[clang] [Clang] Fix a crash introduced in PR#88666 (PR #89567)
Shilei Tian via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 21 20:41:56 PDT 2024
https://github.com/shiltian created https://github.com/llvm/llvm-project/pull/89567
The unroll value can be a template variable such that we need to check it before
we verify if it is constant value.
>From 8f14bcc2ea3d4badb63b953dc23b27b49b0a6521 Mon Sep 17 00:00:00 2001
From: Shilei Tian <i at tianshilei.me>
Date: Sun, 21 Apr 2024 23:41:35 -0400
Subject: [PATCH] [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.
---
clang/lib/Sema/SemaStmtAttr.cpp | 2 +-
clang/test/Sema/unroll-template-value-crash.cpp | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
create mode 100644 clang/test/Sema/unroll-template-value-crash.cpp
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);
+}
More information about the cfe-commits
mailing list