https://github.com/tadeuszjt created 
https://github.com/llvm/llvm-project/pull/221502

**Problem**
When an invalid 'gang dim' value is used in `CheckGangDimExpr`, the function 
prints the value into the diagnostic message by calling `getExtValue`. This 
function asserts on values that can't fit into a signed integer. 

**Solution**
`APSInt` has a `<<` operator anyway so just use that.

Fixes #221418

>From ec4947480141607e3573cefaebdbb552a153e0b8 Mon Sep 17 00:00:00 2001
From: Tadeusz Tomoszek <[email protected]>
Date: Sun, 6 Sep 2026 01:13:38 +0200
Subject: [PATCH] [Clang][OpenACC] Fixed getExtValue Call on Invalid Gang Dim

---
 clang/lib/Sema/SemaOpenACCClause.cpp                 | 2 +-
 clang/test/SemaOpenACC/routine-construct-clauses.cpp | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaOpenACCClause.cpp 
b/clang/lib/Sema/SemaOpenACCClause.cpp
index 0409e2456895d..b4686afb9b1dc 100644
--- a/clang/lib/Sema/SemaOpenACCClause.cpp
+++ b/clang/lib/Sema/SemaOpenACCClause.cpp
@@ -1159,7 +1159,7 @@ ExprResult CheckGangDimExpr(SemaOpenACC &S, Expr *E) {
 
   if (!ICE || *ICE <= 0 || ICE > 3) {
     S.Diag(Res.get()->getBeginLoc(), diag::err_acc_gang_dim_value)
-        << ICE.has_value() << ICE.value_or(llvm::APSInt{}).getExtValue();
+        << ICE.has_value() << ICE.value_or(llvm::APSInt::get(0));
     return ExprError();
   }
 
diff --git a/clang/test/SemaOpenACC/routine-construct-clauses.cpp 
b/clang/test/SemaOpenACC/routine-construct-clauses.cpp
index 4c7152861afc1..16f49299e9264 100644
--- a/clang/test/SemaOpenACC/routine-construct-clauses.cpp
+++ b/clang/test/SemaOpenACC/routine-construct-clauses.cpp
@@ -103,6 +103,7 @@ static constexpr int One() { return 1; }
 static constexpr int Two() { return 2; }
 static constexpr int Three() { return 3; }
 static constexpr int Four() { return 4; }
+static constexpr unsigned long HugeUnsigned() { return -42; }
 };
 // 'dim' must be 1, 2, or 3.
 // expected-error@+1{{argument to 'gang' clause dimension must be 1, 2, or 3: 
evaluated to -5}}
@@ -114,6 +115,8 @@ static constexpr int Four() { return 4; }
 #pragma acc routine(Func) gang(dim:HasFuncs::Three())
 // expected-error@+1{{argument to 'gang' clause dimension must be 1, 2, or 3: 
evaluated to 4}}
 #pragma acc routine(Func) gang(dim:HasFuncs::Four())
+// expected-error@+1{{argument to 'gang' clause dimension must be 1, 2, or 3: 
evaluated to 18'446'744'073'709'551'574}}
+#pragma acc routine(Func) gang(dim:HasFuncs::HugeUnsigned())
 
 template<typename T>
 struct DependentT {

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to