[PATCH] Fix adress cast for C++ in SEMA

Samuel Antao sfantao at us.ibm.com
Thu Feb 12 21:58:14 PST 2015


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/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7606.19872.patch
Type: text/x-patch
Size: 576 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150213/4222c486/attachment.bin>


More information about the cfe-commits mailing list