From: Richard Smith Date: Fri, 4 Nov 2011 01:10:57 +0000 (+0000) Subject: Constant expression evaluation: although we don't know whether a literal will X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=74f4634781cee06e28eb741bda5d0f936fdd1948;p=clang Constant expression evaluation: although we don't know whether a literal will be at the same address as another object, we do know it won't alias a null pointer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143674 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 781ffa6fb4..3e82c4ce8a 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -1970,8 +1970,10 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) { return false; // It's implementation-defined whether distinct literals will have // distinct addresses. In clang, we do not guarantee the addresses are - // distinct. - if (IsLiteralLValue(LHSValue) || IsLiteralLValue(RHSValue)) + // distinct. However, we do know that the address of a literal will be + // non-null. + if ((IsLiteralLValue(LHSValue) || IsLiteralLValue(RHSValue)) && + LHSValue.Base && RHSValue.Base) return false; // We can't tell whether weak symbols will end up pointing to the same // object. diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index c984f5bf84..b188578420 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -99,3 +99,6 @@ char c = ((union u)(123456)).b[0]; // expected-error {{not a compile-time consta extern const int weak_int __attribute__((weak)); const int weak_int = 42; int weak_int_test = weak_int; // expected-error {{not a compile-time constant}} + +int literalVsNull1 = "foo" == 0; +int literalVsNull2 = 0 == "foo";