[clang] 82888b7 - [OpenCL] Fix address space for const method call from nonconst (PR43145)
Sven van Haastregt via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 4 05:12:45 PST 2019
Author: Sven van Haastregt
Date: 2019-11-04T13:12:17Z
New Revision: 82888b78d47ed132aee4993e00669ce7cbd963e0
URL: https://github.com/llvm/llvm-project/commit/82888b78d47ed132aee4993e00669ce7cbd963e0
DIFF: https://github.com/llvm/llvm-project/commit/82888b78d47ed132aee4993e00669ce7cbd963e0.diff
LOG: [OpenCL] Fix address space for const method call from nonconst (PR43145)
Patch by Anastasia Stulova and Sven van Haastregt.
Differential Revision: https://reviews.llvm.org/D68781
Added:
Modified:
clang/lib/Sema/SemaOverload.cpp
clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 2987007f4f23..bf520f66e3ae 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -5370,7 +5370,10 @@ Sema::PerformObjectArgumentInitialization(Expr *From,
if (!Context.hasSameType(From->getType(), DestType)) {
CastKind CK;
- if (FromRecordType.getAddressSpace() != DestType.getAddressSpace())
+ QualType PteeTy = DestType->getPointeeType();
+ LangAS DestAS =
+ PteeTy.isNull() ? DestType.getAddressSpace() : PteeTy.getAddressSpace();
+ if (FromRecordType.getAddressSpace() != DestAS)
CK = CK_AddressSpaceConversion;
else
CK = CK_NoOp;
diff --git a/clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl b/clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl
index 8a282ac21d4b..d4be9b2c946e 100644
--- a/clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl
+++ b/clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl
@@ -203,3 +203,14 @@ TEST(__private)
// IMPL: [[C2GENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[C2GEN]] to i8 addrspace(4)*
// IMPL: [[C1GENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[C1GEN]] to i8 addrspace(4)*
// IMPL: call void @llvm.memcpy.p4i8.p4i8.i32(i8 addrspace(4)* {{.*}}[[C2GENVOID]], i8 addrspace(4)* {{.*}}[[C1GENVOID]]
+
+// Test that calling a const method from a non-const method does not crash Clang.
+class ConstAndNonConstMethod {
+public:
+ void DoConst() const {
+ }
+
+ void DoNonConst() {
+ DoConst();
+ }
+};
More information about the cfe-commits
mailing list