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

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 21 07:22:33 PDT 2026


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

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

>From e902dea799e9e0145d241c9a45d4036b3910b70f Mon Sep 17 00:00:00 2001
From: erichkeane <ekeane at nvidia.com>
Date: Tue, 21 Jul 2026 07:21:12 -0700
Subject: [PATCH] [OpenACC] Make sure our 'init' recipe handles nullptr_t

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
---
 clang/lib/Sema/SemaOpenACC.cpp                |  3 +++
 .../compute-construct-reduction-clause.cpp    | 21 +++++++++++++++++++
 2 files changed, 24 insertions(+)

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>(); }
+}



More information about the cfe-commits mailing list