[clang] [OpenACC] Make sure our 'init' recipe handles nullptr_t (PR #211008)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 21 08:49:35 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Erich Keane (erichkeane)

<details>
<summary>Changes</summary>

The bug report shows that we missed one scalar type in our initialization code, nullptr_t!  This patch adds the initializer to make sure it works correctly, and adds the test (plus a non-template
    version).

Fixes: #<!-- -->210877

---
Full diff: https://github.com/llvm/llvm-project/pull/211008.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaOpenACC.cpp (+3) 
- (modified) clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp (+21) 


``````````diff
diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 79edb8093c368..7e4c2f508cc11 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -2734,6 +2734,9 @@ Expr *GenerateReductionInitRecipeExpr(ASTContext &Context,
                                                   IK == InitKind::AllOnes ||
                                                   IK == InitKind::Largest),
                                                  Ty, ExprRange.getBegin()));
+    } else if (Ty->isNullPtrType()) {
+      Exprs.push_back(new (Context)
+                          CXXNullPtrLiteralExpr(Ty, ExprRange.getBegin()));
     } else {
       Exprs.push_back(IntegerLiteral::Create(
           Context, getInitIntValue(Context, IK, Ty), Ty, ExprRange.getBegin()));
diff --git a/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp b/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp
index 0ef733b728d09..c55d298c8b775 100644
--- a/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp
+++ b/clang/test/SemaOpenACC/compute-construct-reduction-clause.cpp
@@ -320,3 +320,24 @@ void incomplete_use(Incomplete &i) {
 #pragma acc parallel reduction(+:i)
   while (1);
 }
+
+namespace GH210877 {
+struct S {
+  decltype(nullptr) x;
+  S &operator*=(S &s);
+};
+
+void foo() {
+  S t;
+#pragma acc parallel reduction(* : t)
+  ;
+}
+
+template <typename T> void fooTempl() {
+  T t;
+#pragma acc parallel reduction(* : t)
+  ;
+}
+
+void bar() { fooTempl<S>(); }
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/211008


More information about the cfe-commits mailing list