From: Anastasia Stulova Date: Wed, 30 Sep 2015 13:49:55 +0000 (+0000) Subject: [OpenCL] Add missing OpenCL LangOpts in address space compatibility checks X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0884c5dd85066589c5bac6233b78a89f5ca6c006;p=clang [OpenCL] Add missing OpenCL LangOpts in address space compatibility checks and test checking broken (due to CL specific diagnostics) C functionality M test/Sema/address_spaces.c M lib/Sema/SemaExpr.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248902 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c2b3f29332..8e4624304e 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -7754,7 +7754,7 @@ static bool checkArithmeticBinOpPointerOperands(Sema &S, SourceLocation Loc, if (isRHSPointer) RHSPointeeTy = RHSExpr->getType()->getPointeeType(); // if both are pointers check if operation is valid wrt address spaces - if (isLHSPointer && isRHSPointer) { + if (S.getLangOpts().OpenCL && isLHSPointer && isRHSPointer) { const PointerType *lhsPtr = LHSExpr->getType()->getAs(); const PointerType *rhsPtr = RHSExpr->getType()->getAs(); if (!lhsPtr->isAddressSpaceOverlapping(*rhsPtr)) { @@ -8783,12 +8783,14 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS, diagnoseDistinctPointerComparison(*this, Loc, LHS, RHS, /*isError*/false); } if (LCanPointeeTy != RCanPointeeTy) { - const PointerType *lhsPtr = LHSType->getAs(); - if (!lhsPtr->isAddressSpaceOverlapping(*RHSType->getAs())) { - Diag(Loc, - diag::err_typecheck_op_on_nonoverlapping_address_space_pointers) - << LHSType << RHSType << 0 /* comparison */ - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + if (getLangOpts().OpenCL) { + const PointerType *LHSPtr = LHSType->getAs(); + if (!LHSPtr->isAddressSpaceOverlapping(*RHSType->getAs())) { + Diag(Loc, + diag::err_typecheck_op_on_nonoverlapping_address_space_pointers) + << LHSType << RHSType << 0 /* comparison */ + << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + } } unsigned AddrSpaceL = LCanPointeeTy.getAddressSpace(); unsigned AddrSpaceR = RCanPointeeTy.getAddressSpace(); diff --git a/test/Sema/address_spaces.c b/test/Sema/address_spaces.c index 4756af9d95..1922c8ae4f 100644 --- a/test/Sema/address_spaces.c +++ b/test/Sema/address_spaces.c @@ -67,3 +67,8 @@ void access_as_field() typedef int PR4997 __attribute__((address_space(Foobar))); // expected-error {{use of undeclared identifier 'Foobar'}} __attribute__((address_space("12"))) int *i; // expected-error {{'address_space' attribute requires an integer constant}} + +// Clang extension doesn't forbid operations on pointers to different address spaces. +char* cmp(_AS1 char *x, _AS2 char *y) { + return x < y ? x : y; // expected-warning {{pointer type mismatch ('__attribute__((address_space(1))) char *' and '__attribute__((address_space(2))) char *')}} +} \ No newline at end of file