Index: lib/AST/ExprConstant.cpp =================================================================== --- lib/AST/ExprConstant.cpp +++ lib/AST/ExprConstant.cpp @@ -4995,7 +4995,11 @@ Result.Designator.setInvalid(); return true; } else { - // Cast is of an lvalue, no need to change value. + // Cast is of an lvalue, no need to change value, unless they have + // different address spaces. + if (Info.Ctx.getTargetAddressSpace(getType(Value.getLValueBase())) != + Info.Ctx.getTargetAddressSpace(E->getType()->getPointeeType())) + return false; Result.setFrom(Info.Ctx, Value); return true; } Index: test/Sema/const-eval.c =================================================================== --- test/Sema/const-eval.c +++ test/Sema/const-eval.c @@ -137,3 +137,6 @@ void PR24622(); struct PR24622 {} pr24622; EVAL_EXPR(52, &pr24622 == (void *)&PR24622); // expected-error {{must have a constant size}} + +int __attribute__((address_space(1))) addrspace1; +int *addrspace0_ptr = (int *)(long)&addrspace1; // expected-error {{not a compile-time constant}}