[PATCH] D68781: [OpenCL] Fix address space for const method call from nonconst

Sven van Haastregt via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 1 10:28:46 PDT 2019


svenvh updated this revision to Diff 227476.
svenvh retitled this revision from "[OpenCL] Fix addr space conversion check in obj arg initialization" to "[OpenCL] Fix address space for const method call from nonconst".
svenvh set the repository for this revision to rC Clang.
svenvh added a comment.
Herald added subscribers: cfe-commits, ebevhan.
Herald added a project: clang.

Fix formatting, reduce use of auto, and add a test.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68781/new/

https://reviews.llvm.org/D68781

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl


Index: clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl
===================================================================
--- clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl
+++ clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl
@@ -203,3 +203,14 @@
 // 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();
+  }
+};
Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -5370,7 +5370,10 @@
 
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68781.227476.patch
Type: text/x-patch
Size: 1401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191101/6eb4a203/attachment.bin>


More information about the cfe-commits mailing list