[clang] [clang] Fix address spaces on prvalue (PR #221233)
Tom Honermann via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 5 22:17:51 PDT 2026
================
@@ -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();
+}
----------------
tahonermann wrote:
Other expressions to validate (some of these were inspired from `clang/test/SemaCXX/cv-unqual-rvalues.cpp`):
- C-style cast, functional cast, `const_cast`, `static_cast`, `reinterpret_cast`.
- Temporary materialization, e.g., `GlobalX{0}`.
- Prvalue arrays; see https://godbolt.org/z/avcG4h3TM.
- Use of an rvalue reference.
- Non-type template parameters.
- `__builtin_va_arg(..., int __attribute__((address_space(1)))`; see https://godbolt.org/z/Tzh1Yb9aa.
https://github.com/llvm/llvm-project/pull/221233
More information about the cfe-commits
mailing list