[PATCH] D107553: [C++4OpenCL] Initialize temporaries in the private address space
Ole Strohm via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 5 04:08:04 PDT 2021
olestrohm created this revision.
olestrohm added reviewers: Anastasia, rjmccall.
olestrohm added a project: clang.
Herald added subscribers: ldrumm, yaxunl.
olestrohm requested review of this revision.
Herald added a subscriber: cfe-commits.
This patch fixes initializing temporaries, which are currently initialized without an address space, meaning that no constructor can ever be applicable.
This is also working towards putting temporaries in the private address space.
Fixes the second issue in PR43296.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107553
Files:
clang/include/clang/Sema/Initialization.h
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
clang/test/SemaOpenCLCXX/temporaries.clcpp
Index: clang/test/SemaOpenCLCXX/temporaries.clcpp
===================================================================
--- /dev/null
+++ clang/test/SemaOpenCLCXX/temporaries.clcpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -pedantic -ast-dump | FileCheck %s
+
+struct X {
+ X() __private = default;
+};
+
+// CHECK: VarDecl {{.*}} gx
+// CHECK: CXXTemporaryObjectExpr {{.*}} '__private X'
+__global X gx = X();
+
+void k() {
+ // CHECK: VarDecl {{.*}} x1
+ // CHECK: CXXTemporaryObjectExpr {{.*}} '__private X'
+ X x1 = X();
+
+ // CHECK: VarDecl {{.*}} x2
+ // CHECK: CXXConstructExpr {{.*}} 'const __private X'
+ const X x2;
+}
Index: clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
===================================================================
--- clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
@@ -32,6 +32,8 @@
__local X lx;
__private X x;
+ __private X tx = X();
+
__private Y py;
__constant Y cy1; // expected-error{{variable in constant address space must be initialized}}
__constant Y cy2(1); // expected-error{{no matching constructor for initialization of '__constant Y'}}
Index: clang/lib/Sema/SemaExprCXX.cpp
===================================================================
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1454,7 +1454,8 @@
"List initialization must have initializer list as expression.");
SourceRange FullRange = SourceRange(TyBeginLoc, RParenOrBraceLoc);
- InitializedEntity Entity = InitializedEntity::InitializeTemporary(TInfo);
+ InitializedEntity Entity =
+ InitializedEntity::InitializeTemporary(Context, TInfo);
InitializationKind Kind =
Exprs.size()
? ListInitialization
@@ -5293,7 +5294,8 @@
S, Sema::ExpressionEvaluationContext::Unevaluated);
Sema::SFINAETrap SFINAE(S, /*AccessCheckingSFINAE=*/true);
Sema::ContextRAII TUContext(S, S.Context.getTranslationUnitDecl());
- InitializedEntity To(InitializedEntity::InitializeTemporary(Args[0]));
+ InitializedEntity To(
+ InitializedEntity::InitializeTemporary(S.Context, Args[0]));
InitializationKind InitKind(InitializationKind::CreateDirect(KWLoc, KWLoc,
RParenLoc));
InitializationSequence Init(S, To, InitKind, ArgExprs);
Index: clang/include/clang/Sema/Initialization.h
===================================================================
--- clang/include/clang/Sema/Initialization.h
+++ clang/include/clang/Sema/Initialization.h
@@ -335,8 +335,13 @@
}
/// Create the initialization entity for a temporary.
- static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo) {
- return InitializeTemporary(TypeInfo, TypeInfo->getType());
+ static InitializedEntity InitializeTemporary(ASTContext &Context,
+ TypeSourceInfo *TypeInfo) {
+ QualType Type = TypeInfo->getType();
+ if (Context.getLangOpts().OpenCL && !Type.hasAddressSpace())
+ Type = Context.getAddrSpaceQualType(Type, LangAS::opencl_private);
+
+ return InitializeTemporary(TypeInfo, Type);
}
/// Create the initialization entity for a temporary.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107553.364407.patch
Type: text/x-patch
Size: 3268 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210805/04aa57f0/attachment.bin>
More information about the cfe-commits
mailing list