]> granicus.if.org Git - clang/commitdiff
Constant expression evaluation: although we don't know whether a literal will
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 4 Nov 2011 01:10:57 +0000 (01:10 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 4 Nov 2011 01:10:57 +0000 (01:10 +0000)
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

lib/AST/ExprConstant.cpp
test/Sema/const-eval.c

index 781ffa6fb4de20ea533f51d47ec5f52cd52d2d40..3e82c4ce8ad278fc3bb35d8acbe20c13ea8f7082 100644 (file)
@@ -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.
index c984f5bf840e755335628ce885ce2f54e6dcc9c6..b188578420ad5cd9491d16805c09ec617524cc8a 100644 (file)
@@ -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";