Skip to content

Commit 8f14bcc

Browse files
committed
[Clang] Fix a crash introduced in PR#88666
The unroll value can be a template variable such that we need to check it before we verify if it is constant value.
1 parent 48324f0 commit 8f14bcc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/Sema/SemaStmtAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
109109
SetHints(LoopHintAttr::Unroll, LoopHintAttr::Disable);
110110
} else if (PragmaName == "unroll") {
111111
// #pragma unroll N
112-
if (ValueExpr) {
112+
if (ValueExpr && !ValueExpr->isValueDependent()) {
113113
llvm::APSInt ValueAPS;
114114
ExprResult R = S.VerifyIntegerConstantExpression(ValueExpr, &ValueAPS);
115115
assert(!R.isInvalid() && "unroll count value must be a valid value, it's "
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %clang_cc1 -x c++ -emit-llvm -S -verify %s
2+
// expected-no-diagnostics
3+
4+
template <int Unroll> void foo() {
5+
#pragma unroll Unroll
6+
for (int i = 0; i < Unroll; ++i);
7+
}

0 commit comments

Comments
 (0)