The cast of a pointer to a different address space makes clang implement an 
implicit cast during SEMA that was not getting the right CastKind information. 
This caused the code emission to fail later on. This patch adds an extra check 
before the creation of the cast and fixes the kind if the types are pointers 
and the address spaces differ.

This is a fix for http://llvm.org/bugs/show_bug.cgi?id=20135.

http://reviews.llvm.org/D7606

Files:
  lib/Sema/Sema.cpp

Index: lib/Sema/Sema.cpp
===================================================================
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -347,6 +347,13 @@
     }
   }
 
+  // If we are casting pointers, we need to make sure we deal with address
+  // spaces properly
+  if (Kind == CK_NoOp && ExprTy->isPointerType() && TypeTy->isPointerType() &&
+      ExprTy->getPointeeType().getAddressSpace() !=
+          TypeTy->getPointeeType().getAddressSpace())
+    Kind = CK_AddressSpaceConversion;
+
   return ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK);
 }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/Sema/Sema.cpp
===================================================================
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -347,6 +347,13 @@
     }
   }
 
+  // If we are casting pointers, we need to make sure we deal with address
+  // spaces properly
+  if (Kind == CK_NoOp && ExprTy->isPointerType() && TypeTy->isPointerType() &&
+      ExprTy->getPointeeType().getAddressSpace() !=
+          TypeTy->getPointeeType().getAddressSpace())
+    Kind = CK_AddressSpaceConversion;
+
   return ImplicitCastExpr::Create(Context, Ty, Kind, E, BasePath, VK);
 }
 
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to