llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Shilei Tian (shiltian) <details> <summary>Changes</summary> The unroll value can be a template variable such that we need to check it before we verify if it is constant value. --- Full diff: https://github.com/llvm/llvm-project/pull/89567.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaStmtAttr.cpp (+1-1) - (added) clang/test/Sema/unroll-template-value-crash.cpp (+7) ``````````diff 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..bb200fc3667c8f --- /dev/null +++ b/clang/test/Sema/unroll-template-value-crash.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -x c++ -emit-llvm -S -verify %s +// expected-no-diagnostics + +template <int Unroll> void foo() { + #pragma unroll Unroll + for (int i = 0; i < Unroll; ++i); +} `````````` </details> https://github.com/llvm/llvm-project/pull/89567 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits