Skip to content

Commit ac27ca9

Browse files
committed
Add test to unittests
1 parent 3f59abb commit ac27ca9

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

clang/unittests/AST/ASTExprTest.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,19 @@ TEST(ASTExpr, InitListIsConstantInitialized) {
108108
(void)FooInit->updateInit(Ctx, 2, Ref);
109109
EXPECT_FALSE(FooInit->isConstantInitializer(Ctx, false));
110110
}
111+
112+
TEST(ASTExpr, CheckForUnsignedOverflowICE) {
113+
auto AST = buildASTFromCode(R"cpp(
114+
unsigned u = 1'000'000'000u * 8u;
115+
)cpp");
116+
ASTContext &Ctx = AST->getASTContext();
117+
const VarDecl *Var = getVariableNode(AST.get(), "u");
118+
119+
const auto ICE = Var->getInit()->getIntegerConstantExpr(Ctx);
120+
EXPECT_TRUE(ICE.has_value());
121+
EXPECT_TRUE(ICE->isUnsigned());
122+
EXPECT_EQ(3'705'032'704u, *ICE);
123+
124+
const auto ICEOverflowCheck = Var->getInit()->getIntegerConstantExpr(Ctx, nullptr, true);
125+
EXPECT_FALSE(ICEOverflowCheck.has_value());
126+
}

0 commit comments

Comments
 (0)