r355499 - [PR40778] Add addr space conversion when binding reference to a temporary.
Anastasia Stulova via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 6 05:02:42 PST 2019
Author: stulova
Date: Wed Mar 6 05:02:41 2019
New Revision: 355499
URL: http://llvm.org/viewvc/llvm-project?rev=355499&view=rev
Log:
[PR40778] Add addr space conversion when binding reference to a temporary.
This change fixes temporary materialization to happen in the right
(default) address space when binding to it a reference of different type.
It adds address space conversion afterwards to match the addr space
of a reference.
Differential Revision: https://reviews.llvm.org/D58634
Added:
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-references.cl
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/Sema/SemaInit.cpp
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=355499&r1=355498&r2=355499&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Mar 6 05:02:41 2019
@@ -317,6 +317,11 @@ public:
qs.removeObjCLifetime();
return qs;
}
+ Qualifiers withoutAddressSpace() const {
+ Qualifiers qs = *this;
+ qs.removeAddressSpace();
+ return qs;
+ }
bool hasObjCLifetime() const { return Mask & LifetimeMask; }
ObjCLifetime getObjCLifetime() const {
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=355499&r1=355498&r2=355499&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Mar 6 05:02:41 2019
@@ -4760,7 +4760,15 @@ static void TryReferenceInitializationCo
// copy-initialization (8.5). The reference is then bound to the
// temporary. [...]
- InitializedEntity TempEntity = InitializedEntity::InitializeTemporary(cv1T1);
+ // Ignore address space of reference type at this point and perform address
+ // space conversion after the reference binding step.
+ QualType cv1T1IgnoreAS =
+ T1Quals.hasAddressSpace()
+ ? S.Context.getQualifiedType(T1, T1Quals.withoutAddressSpace())
+ : cv1T1;
+
+ InitializedEntity TempEntity =
+ InitializedEntity::InitializeTemporary(cv1T1IgnoreAS);
// FIXME: Why do we use an implicit conversion here rather than trying
// copy-initialization?
@@ -4795,8 +4803,9 @@ static void TryReferenceInitializationCo
// than, cv2; otherwise, the program is ill-formed.
unsigned T1CVRQuals = T1Quals.getCVRQualifiers();
unsigned T2CVRQuals = T2Quals.getCVRQualifiers();
- if (RefRelationship == Sema::Ref_Related &&
- (T1CVRQuals | T2CVRQuals) != T1CVRQuals) {
+ if ((RefRelationship == Sema::Ref_Related &&
+ (T1CVRQuals | T2CVRQuals) != T1CVRQuals) ||
+ !T1Quals.isAddressSpaceSupersetOf(T2Quals)) {
Sequence.SetFailed(InitializationSequence::FK_ReferenceInitDropsQualifiers);
return;
}
@@ -4810,7 +4819,11 @@ static void TryReferenceInitializationCo
return;
}
- Sequence.AddReferenceBindingStep(cv1T1, /*bindingTemporary=*/true);
+ Sequence.AddReferenceBindingStep(cv1T1IgnoreAS, /*bindingTemporary=*/true);
+
+ if (T1Quals.hasAddressSpace())
+ Sequence.AddQualificationConversionStep(cv1T1, isLValueRef ? VK_LValue
+ : VK_XValue);
}
/// Attempt character array initialization from a string literal
Added: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-references.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-references.cl?rev=355499&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-references.cl (added)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-references.cl Wed Mar 6 05:02:41 2019
@@ -0,0 +1,14 @@
+//RUN: %clang_cc1 %s -cl-std=c++ -triple spir -emit-llvm -o - | FileCheck %s
+
+int bar(const unsigned int &i);
+// CHECK-LABEL: define spir_func void @_Z3foov()
+void foo() {
+ // The generic addr space reference parameter object will be bound
+ // to a temporary value allocated in private addr space. We need an
+ // addrspacecast before passing the value to the function.
+ // CHECK: [[REF:%.*]] = alloca i32
+ // CHECK: store i32 1, i32* [[REF]]
+ // CHECK: [[REG:%[0-9]+]] = addrspacecast i32* [[REF]] to i32 addrspace(4)*
+ // CHECK: call spir_func i32 @_Z3barRU3AS4Kj(i32 addrspace(4)* nonnull dereferenceable(4) [[REG]])
+ bar(1);
+}
More information about the cfe-commits
mailing list