[cfe-commits] r143374 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaCXX/constant-expression-cxx11.cpp

Eli Friedman eli.friedman at gmail.com
Mon Oct 31 15:28:06 PDT 2011


Author: efriedma
Date: Mon Oct 31 17:28:05 2011
New Revision: 143374

URL: http://llvm.org/viewvc/llvm-project?rev=143374&view=rev
Log:
Don't try to fold comparisons between the address of an object and an arbitrary integer constant.  Fixes regression from r143334.


Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=143374&r1=143373&r2=143374&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Oct 31 17:28:05 2011
@@ -1981,6 +1981,12 @@
         // unspecified or undefined behavior.
         if (!E->isEqualityOp())
           return false;
+        // A constant address may compare equal to the address of a symbol.
+        // The one exception is that address of an object cannot compare equal
+        // to the null pointer.
+        if ((!LHSValue.Base && !LHSValue.Offset.isZero()) ||
+            (!RHSValue.Base && !RHSValue.Offset.isZero()))
+          return false;
         // It's implementation-defined whether distinct literals will have
         // distinct addresses. We define it to be unspecified.
         if (IsLiteralLValue(LHSValue) || IsLiteralLValue(RHSValue))

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=143374&r1=143373&r2=143374&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Mon Oct 31 17:28:05 2011
@@ -200,6 +200,9 @@
 constexpr S* sptr = &s;
 constexpr bool dyncast = sptr == dynamic_cast<S*>(sptr);
 
+extern char externalvar[];
+constexpr bool constaddress = (void *)externalvar == (void *)0x4000UL;  // expected-error {{must be initialized by a constant expression}}
+
 using check = int[m1 + (m2<<1) + (m3<<2) + (m4<<3) + (m5<<4) + (m6<<5) +
                   (n1<<6) + (n2<<7) + (n7<<8) + (n8<<9) + (g1<<10) + (g2<<11) +
                (s1<<12) + (s2<<13) + (s3<<14) + (s4<<15) + (s5<<16) + (s6<<17)];





More information about the cfe-commits mailing list