Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -6527,6 +6527,21 @@ S.Diag(Loc, diag::ext_typecheck_cond_incompatible_pointers) << LHSTy << RHSTy << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + + // If the addresse spacesare different, we do not allow a bitcast. + if (!S.getLangOpts().OpenCL) { + if (LAddrSpace != ResultAddrSpace) { + S.Diag(Loc, diag::err_typecheck_incompatible_address_space) + << LHSTy << incompatTy << Sema::AA_Converting + << LHS.get()->getSourceRange(); + } + if (RAddrSpace != ResultAddrSpace) { + S.Diag(Loc, diag::err_typecheck_incompatible_address_space) + << RHSTy << incompatTy << Sema::AA_Converting + << RHS.get()->getSourceRange(); + } + } + return incompatTy; } Index: test/Sema/address_spaces.c =================================================================== --- test/Sema/address_spaces.c +++ test/Sema/address_spaces.c @@ -72,4 +72,6 @@ // 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 *')}} + // expected-error@-1{{converting '__attribute__((address_space(1))) char *' to type 'void *' changes address space of pointer}} + // expected-error@-2{{converting '__attribute__((address_space(2))) char *' to type 'void *' changes address space of pointer}} } Index: test/Sema/conditional-expr.c =================================================================== --- test/Sema/conditional-expr.c +++ test/Sema/conditional-expr.c @@ -74,9 +74,12 @@ int __attribute__((address_space(2))) *adr2; int __attribute__((address_space(3))) *adr3; test0 ? adr2 : adr3; // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}} + // expected-error@-1{{converting '__attribute__((address_space(2))) int *' to type 'void *' changes address space of pointer}} + // expected-error@-2{{converting '__attribute__((address_space(3))) int *' to type 'void *' changes address space of pointer}} // Make sure address-space mask ends up in the result type (test0 ? (test0 ? adr2 : adr2) : nonconst_int); // expected-warning {{pointer type mismatch}} expected-warning {{expression result unused}} + // expected-error@-1{{converting '__attribute__((address_space(2))) int *' to type 'void *' changes address space of pointer}} } int Postgresql() {