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

Samuel Antao sfantao at us.ibm.com
Thu Jul 23 20:59:40 PDT 2015


sfantao added a comment.

Thanks for the review!

Please see the inline comment below.

Thanks again,
Samuel


================
Comment at: lib/Sema/Sema.cpp:366
@@ -365,3 +365,3 @@
     if (*exprNullability == NullabilityKind::Nullable) {
       if (auto typeNullability = Ty->getNullability(Context)) {
         if (*typeNullability == NullabilityKind::NonNull) {
----------------
Done!

================
Comment at: lib/Sema/SemaCast.cpp:2106-2113
@@ -2105,3 +2105,10 @@
       return;
     }
 
+  // If we are casting pointers, we need to check whether this refers to an
+  // address cast.
+  if (DestType->isPointerType() && SrcExpr.get()->getType()->isPointerType() &&
+      DestType->getPointeeType().getAddressSpace() !=
+          SrcExpr.get()->getType().getAddressSpace()) {
+    Kind = CK_AddressSpaceConversion;
+    return;
----------------
I agree, the pointee type should also be checked. 

However, if I move the check to `TryReinterpretCast` a static cast will be attempted first and will hit the assertion I've just added to Sema.cpp. Do you suggest to add something to `TryStaticCast` as well? Or should I just add the pointee check?


http://reviews.llvm.org/D7606







More information about the cfe-commits mailing list