[PATCH] D19662: [OpenCL] Fix bug in mergeTypes which causes equivalent types treated as different.

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 28 08:01:41 PDT 2016


yaxunl created this revision.
yaxunl added a reviewer: Anastasia.
yaxunl added subscribers: cfe-commits, tstellarAMD.

When comparing unqualified types, canonical types should be used, otherwise equivalent types may be treated as different type.

For example,

typedef int int_t;
generic int* a;
global int_t* b;

`0 ? a : b` should have type generic int*. However due to this bug, int_t and int are treated as different types, which causes the type of `0 ? a : b` to have type generic void*.

This patch fixes it. 

http://reviews.llvm.org/D19662

Files:
  lib/AST/ASTContext.cpp
  test/CodeGenOpenCL/address-spaces-conversions.cl

Index: test/CodeGenOpenCL/address-spaces-conversions.cl
===================================================================
--- test/CodeGenOpenCL/address-spaces-conversions.cl
+++ test/CodeGenOpenCL/address-spaces-conversions.cl
@@ -49,7 +49,7 @@
   generic int *var_gen2;
   generic float *var_gen_f;
   generic void *var_gen_v;
-
+  
   var_gen = var_gen ? var_gen : var_gen2; // operands of the same addr spaces and the same type
   // CHECK: icmp
   // CHECK-NOT: addrspacecast
@@ -63,7 +63,16 @@
   // CHECK: %{{.+}} = addrspacecast i32 addrspace(1)* %{{.+}} to i32 addrspace(4)*
   // CHECK: phi
   // CHECK: store
-  
+
+  typedef int int_t;
+  global int_t *var_glob_typedef;
+  var_gen = var_gen ? var_gen : var_glob_typedef; // operands of overlapping addr spaces and equivalent types
+  // CHECK: icmp
+  // CHECK-NOT: bitcast
+  // CHECK: %{{.+}} = addrspacecast i32 addrspace(1)* %{{.+}} to i32 addrspace(4)*
+  // CHECK: phi
+  // CHECK: store
+ 
   var_gen_v = var_gen ? var_gen : var_gen_f; // operands of the same addr space and different types
   // CHECK: icmp
   // CHECK: %{{.+}} = bitcast i32 addrspace(4)* %{{.+}} to i8 addrspace(4)*
Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -7618,7 +7618,7 @@
   Qualifiers RQuals = RHSCan.getLocalQualifiers();
   if (LQuals != RQuals) {
     if (getLangOpts().OpenCL) {
-      if (LHS.getUnqualifiedType() != RHS.getUnqualifiedType() ||
+      if (LHSCan.getUnqualifiedType() != RHSCan.getUnqualifiedType() ||
           LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers())
         return QualType();
       if (LQuals.isAddressSpaceSupersetOf(RQuals))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19662.55417.patch
Type: text/x-patch
Size: 1731 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160428/195a6fe8/attachment.bin>


More information about the cfe-commits mailing list