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

2024-04-22 Thread Shilei Tian via cfe-commits

https://github.com/shiltian closed 
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


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

2024-04-22 Thread via cfe-commits

https://github.com/yronglin approved this pull request.


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


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

2024-04-21 Thread via cfe-commits

https://github.com/yronglin edited 
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


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

2024-04-21 Thread Shilei Tian via cfe-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/89567

>From 041574d22c2debb5299926b58aed529919905902 Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Mon, 22 Apr 2024 01:09:47 -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 | 10 ++
 2 files changed, 11 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 , Stmt *St, const 
ParsedAttr ,
 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, );
   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 00..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  void foo() {
+  #pragma unroll Unroll
+  for (int i = 0; i < Unroll; ++i);
+
+  #pragma GCC unroll Unroll
+  for (int i = 0; i < Unroll; ++i);
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-04-21 Thread via cfe-commits


@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -x c++ -verify %s
+// expected-no-diagnostics
+
+template  void foo() {
+  #pragma unroll Unroll
+  for (int i = 0; i < Unroll; ++i);
+}

yronglin wrote:

I'd like to add a test for '#pragma GCC unroll N', WDYT?

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


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

2024-04-21 Thread via cfe-commits

https://github.com/yronglin approved this pull request.

Thakns for your fix, LGTM!

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


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

2024-04-21 Thread Shilei Tian via cfe-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/89567

>From 3503f2bfd28af5be8e87835c47207d770659db3c Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Mon, 22 Apr 2024 00:06:31 -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 , Stmt *St, const 
ParsedAttr ,
 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, );
   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 00..4aea46ca727a8d
--- /dev/null
+++ b/clang/test/Sema/unroll-template-value-crash.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -x c++ -verify %s
+// expected-no-diagnostics
+
+template  void foo() {
+  #pragma unroll Unroll
+  for (int i = 0; i < Unroll; ++i);
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-04-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Shilei Tian (shiltian)


Changes

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 , Stmt *St, const 
ParsedAttr ,
 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, );
   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 00..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  void foo() {
+  #pragma unroll Unroll
+  for (int i = 0; i < Unroll; ++i);
+}

``




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


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

2024-04-21 Thread Shilei Tian via cfe-commits

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 
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 , Stmt *St, const 
ParsedAttr ,
 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, );
   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 00..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  void foo() {
+  #pragma unroll Unroll
+  for (int i = 0; i < Unroll; ++i);
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits