]> granicus.if.org Git - clang/commitdiff
[OpenCL][Sema] Minor refactoring and constraint checking
authorMarco Antognini <marco.antognini@arm.com>
Wed, 17 Jul 2019 08:52:09 +0000 (08:52 +0000)
committerMarco Antognini <marco.antognini@arm.com>
Wed, 17 Jul 2019 08:52:09 +0000 (08:52 +0000)
Summary:
Simplify code a bit and add assertion to address post-landing comments
from D64083.

Subscribers: yaxunl, Anastasia, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64804

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366306 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp

index df8638a0136239b6942596d74908113762d1c10a..cdca2e8cac6b7bc9bc690184c98e40ffb4866bed 100644 (file)
@@ -4216,17 +4216,12 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
     break;
 
   case ICK_Block_Pointer_Conversion: {
-    QualType LHSType = Context.getCanonicalType(ToType).getUnqualifiedType();
-    QualType RHSType = Context.getCanonicalType(FromType).getUnqualifiedType();
-
-    // Assumptions based on Sema::IsBlockPointerConversion.
-    assert(isa<BlockPointerType>(LHSType) && "BlockPointerType expected");
-    assert(isa<BlockPointerType>(RHSType) && "BlockPointerType expected");
-
     LangAS AddrSpaceL =
-        LHSType->getAs<BlockPointerType>()->getPointeeType().getAddressSpace();
+        ToType->castAs<BlockPointerType>()->getPointeeType().getAddressSpace();
     LangAS AddrSpaceR =
-        RHSType->getAs<BlockPointerType>()->getPointeeType().getAddressSpace();
+        FromType->castAs<BlockPointerType>()->getPointeeType().getAddressSpace();
+    assert(Qualifiers::isAddressSpaceSupersetOf(AddrSpaceL, AddrSpaceR) &&
+           "Invalid cast");
     CastKind Kind =
         AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast;
     From = ImpCastExprToType(From, ToType.getUnqualifiedType(), Kind,