[clang] 0accda7 - [Clang] Fix a crash introduced in PR#88666 (#89567)

via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 22 06:08:31 PDT 2024


Author: Shilei Tian
Date: 2024-04-22T09:08:27-04:00
New Revision: 0accda7f17a1f85b4270edf4f0976c55de4e958c

URL: https://github.com/llvm/llvm-project/commit/0accda7f17a1f85b4270edf4f0976c55de4e958c
DIFF: https://github.com/llvm/llvm-project/commit/0accda7f17a1f85b4270edf4f0976c55de4e958c.diff

LOG: [Clang] Fix a crash introduced in PR#88666 (#89567)

Added: 
    clang/test/Sema/unroll-template-value-crash.cpp

Modified: 
    clang/lib/Sema/SemaStmtAttr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 7cd494b42250d4..9d44c22c8ddcc3 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -109,7 +109,7 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
     SetHints(LoopHintAttr::Unroll, LoopHintAttr::Disable);
   } else if (PragmaName == "unroll") {
     // #pragma unroll N
-    if (ValueExpr) {
+    if (ValueExpr && !ValueExpr->isValueDependent()) {
       llvm::APSInt ValueAPS;
       ExprResult R = S.VerifyIntegerConstantExpression(ValueExpr, &ValueAPS);
       assert(!R.isInvalid() && "unroll count value must be a valid value, it's "

diff  --git a/clang/test/Sema/unroll-template-value-crash.cpp b/clang/test/Sema/unroll-template-value-crash.cpp
new file mode 100644
index 00000000000000..d8953c4845c265
--- /dev/null
+++ b/clang/test/Sema/unroll-template-value-crash.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -x c++ -verify %s
+// expected-no-diagnostics
+
+template <int Unroll> void foo() {
+  #pragma unroll Unroll
+  for (int i = 0; i < Unroll; ++i);
+
+  #pragma GCC unroll Unroll
+  for (int i = 0; i < Unroll; ++i);
+}


        


More information about the cfe-commits mailing list