https://github.com/elizabethandrews updated 
https://github.com/llvm/llvm-project/pull/221233

>From 103bb3b1723037239b3f9d32c2c2cd4b9e9fb947 Mon Sep 17 00:00:00 2001
From: Elizabeth Andrews <[email protected]>
Date: Thu, 3 Sep 2026 13:13:52 -0700
Subject: [PATCH 1/2] [clang] Fix address spaces on prvalue

Address spaces should not be attached to pr values.
---
 clang/lib/AST/Type.cpp                       |  4 ++++
 clang/lib/Sema/SemaInit.cpp                  |  2 +-
 clang/test/SemaCXX/address-space-prvalue.cpp | 25 ++++++++++++++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/address-space-prvalue.cpp

diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index df296eb4e28e5..e57f3de75ac8a 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3728,6 +3728,10 @@ QualType QualType::getNonLValueExprType(const ASTContext 
&Context) const {
       (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType()))
     return getUnqualifiedType();
 
+  // A prvalue should not have an address space.
+  if (hasAddressSpace())
+    return Context.removeAddrSpaceQualType(*this);
+
   return *this;
 }
 
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 48ce51863c2c0..e6477a8c6bd26 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7683,7 +7683,7 @@ PerformConstructorInitialization(Sema &S,
     CurInit = S.CheckForImmediateInvocation(
         CXXTemporaryObjectExpr::Create(
             S.Context, CalleeDecl,
-            Entity.getType().getNonLValueExprType(S.Context), TSInfo,
+            Entity.getType().getNonReferenceType(), TSInfo,
             ConstructorArgs, ParenOrBraceRange, HadMultipleCandidates,
             IsListInitialization, IsStdInitListInitialization,
             ConstructorInitRequiresZeroInit),
diff --git a/clang/test/SemaCXX/address-space-prvalue.cpp 
b/clang/test/SemaCXX/address-space-prvalue.cpp
new file mode 100644
index 0000000000000..c0cbb20c10f2d
--- /dev/null
+++ b/clang/test/SemaCXX/address-space-prvalue.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
+
+struct X { int a; };
+
+using GlobalX = X __attribute__((address_space(1)));
+
+GlobalX prvalue();
+GlobalX &lvalue();
+GlobalX &&xvalue();
+
+void test() {
+  // A prvalue should not have an address space even if the function's
+  // return type is address-space qualified.
+  // CHECK: VarDecl {{.*}} v 'X'
+  // CHECK: CallExpr {{.*}} 'X'{{$}}
+  auto v = prvalue();
+
+  // CHECK: VarDecl {{.*}} l '__attribute__((address_space(1))) X &'
+  // CHECK: CallExpr {{.*}}:'__attribute__((address_space(1))) X' lvalue
+  auto &l = lvalue();
+
+  // CHECK: VarDecl {{.*}} r '__attribute__((address_space(1))) X &&'
+  // CHECK: CallExpr {{.*}}:'__attribute__((address_space(1))) X' xvalue
+  auto &&r = xvalue();
+}

>From b476f7f9feb036fa5e67eb0d7a03625fd6f01379 Mon Sep 17 00:00:00 2001
From: Elizabeth Andrews <[email protected]>
Date: Fri, 4 Sep 2026 07:31:22 -0700
Subject: [PATCH 2/2] clang-format changes

---
 clang/lib/Sema/SemaInit.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index e6477a8c6bd26..44071e150b781 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7682,9 +7682,8 @@ PerformConstructorInitialization(Sema &S,
 
     CurInit = S.CheckForImmediateInvocation(
         CXXTemporaryObjectExpr::Create(
-            S.Context, CalleeDecl,
-            Entity.getType().getNonReferenceType(), TSInfo,
-            ConstructorArgs, ParenOrBraceRange, HadMultipleCandidates,
+            S.Context, CalleeDecl, Entity.getType().getNonReferenceType(),
+            TSInfo, ConstructorArgs, ParenOrBraceRange, HadMultipleCandidates,
             IsListInitialization, IsStdInitListInitialization,
             ConstructorInitRequiresZeroInit),
         CalleeDecl);

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

Reply via email to