llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: elizabethandrews <details> <summary>Changes</summary> Address spaces should not be attached to pr values. Assisted by Claude for test writing. --- Full diff: https://github.com/llvm/llvm-project/pull/221233.diff 3 Files Affected: - (modified) clang/lib/AST/Type.cpp (+4) - (modified) clang/lib/Sema/SemaInit.cpp (+1-1) - (added) clang/test/SemaCXX/address-space-prvalue.cpp (+25) ``````````diff 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(); +} `````````` </details> https://github.com/llvm/llvm-project/pull/221233 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
