[cfe-commits] r143674 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/const-eval.c
Richard Smith
richard-llvm at metafoo.co.uk
Thu Nov 3 18:10:57 PDT 2011
Author: rsmith
Date: Thu Nov 3 20:10:57 2011
New Revision: 143674
URL: http://llvm.org/viewvc/llvm-project?rev=143674&view=rev
Log:
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.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/const-eval.c
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=143674&r1=143673&r2=143674&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Nov 3 20:10:57 2011
@@ -1970,8 +1970,10 @@
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.
Modified: cfe/trunk/test/Sema/const-eval.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/const-eval.c?rev=143674&r1=143673&r2=143674&view=diff
==============================================================================
--- cfe/trunk/test/Sema/const-eval.c (original)
+++ cfe/trunk/test/Sema/const-eval.c Thu Nov 3 20:10:57 2011
@@ -99,3 +99,6 @@
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";
More information about the cfe-commits
mailing list