[cfe-commits] r148020 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/CXX/expr/expr.const/p2-0x.cpp test/CodeGenCXX/const-init.cpp www/cxx_status.html

Richard Smith richard-llvm at metafoo.co.uk
Wed Jan 11 22:08:57 PST 2012


Author: rsmith
Date: Thu Jan 12 00:08:57 2012
New Revision: 148020

URL: http://llvm.org/viewvc/llvm-project?rev=148020&view=rev
Log:
Allow constant-folding of references which were formed in a manner not permitted
in a constant expression, for compatibility with g++.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp
    cfe/trunk/test/CodeGenCXX/const-init.cpp
    cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=148020&r1=148019&r2=148020&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Jan 12 00:08:57 2012
@@ -832,7 +832,8 @@
 
 /// Check that this reference or pointer core constant expression is a valid
 /// value for an address or reference constant expression. Type T should be
-/// either LValue or CCValue.
+/// either LValue or CCValue. Return true if we can fold this expression,
+/// whether or not it's a constant expression.
 template<typename T>
 static bool CheckLValueConstantExpression(EvalInfo &Info, const Expr *E,
                                           const T &LVal, APValue &Value,
@@ -854,19 +855,15 @@
     } else {
       Info.Diag(E->getExprLoc());
     }
+    // Don't allow references to temporaries to escape.
     return false;
   }
 
   bool IsReferenceType = E->isGLValue();
 
   if (Designator.Invalid) {
-    // This is not a core constant expression. A diagnostic will have already
-    // been produced.
-    if (IsReferenceType)
-      return false;
-
-    // Allow this for pointers, so we can fold things like integers cast to
-    // pointers.
+    // This is not a core constant expression. An appropriate diagnostic will
+    // have already been produced.
     Value = APValue(LVal.getLValueBase(), LVal.getLValueOffset(),
                     APValue::NoLValuePath());
     return true;
@@ -884,7 +881,7 @@
   if (!Base) {
     // FIXME: diagnostic
     Info.CCEDiag(E->getExprLoc());
-    return false;
+    return true;
   }
 
   // Does this refer one past the end of some object?
@@ -897,7 +894,6 @@
     else
       Info.Note(Base.dyn_cast<const Expr*>()->getExprLoc(),
                 diag::note_constexpr_temporary_here);
-    return false;
   }
 
   return true;

Modified: cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp?rev=148020&r1=148019&r2=148020&view=diff
==============================================================================
--- cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.const/p2-0x.cpp Thu Jan 12 00:08:57 2012
@@ -134,8 +134,9 @@
   constexpr const int &f(const int *q) {
     return q[0]; // expected-note {{dereferenced pointer past the end of subobject of 's' is not a constant expression}}
   }
+  constexpr int n = (f(p), 0); // expected-error {{constant expression}} expected-note {{in call to 'f(&s.m + 1)'}}
   struct T {
-    int n : f(p); // expected-error {{not an integer constant expression}} expected-note {{in call to 'f(&s.m + 1)'}}
+    int n : f(p); // expected-error {{not an integer constant expression}} expected-note {{read of dereferenced one-past-the-end pointer}}
   };
 
   namespace Ptr {

Modified: cfe/trunk/test/CodeGenCXX/const-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/const-init.cpp?rev=148020&r1=148019&r2=148020&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/const-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/const-init.cpp Thu Jan 12 00:08:57 2012
@@ -69,3 +69,10 @@
 // But make sure we do fold this.
 // CHECK: @_ZZ21FoldableAddrLabelDiffvE1x = internal global i64 sub (i64 ptrtoint (i8* blockaddress(@_Z21FoldableAddrLabelDiffv
 void FoldableAddrLabelDiff() { static long x = (long)&&a-(long)&&b; a:b:return;}
+
+// CHECK: @i = constant i32* bitcast (float* @PR9558 to i32*)
+int &i = reinterpret_cast<int&>(PR9558);
+
+int arr[2];
+// CHECK: @pastEnd = constant i32* bitcast (i8* getelementptr (i8* bitcast ([2 x i32]* @arr to i8*), i64 8) to i32*)
+int &pastEnd = arr[2];

Modified: cfe/trunk/www/cxx_status.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=148020&r1=148019&r2=148020&view=diff
==============================================================================
--- cfe/trunk/www/cxx_status.html (original)
+++ cfe/trunk/www/cxx_status.html Thu Jan 12 00:08:57 2012
@@ -8,7 +8,7 @@
   <link type="text/css" rel="stylesheet" href="content.css">
   <style type="text/css">
     .none { background-color: #FFCCCC }
-    .partial  { background-color: #FFFF99 }
+    .svn  { background-color: #FFFF99 }
     .full { background-color: #CCFF99 }
     th { background-color: #FFDDAA }
   </style>
@@ -156,7 +156,7 @@
       <td>
 	<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2764.pdf">N2764
       </a></td>
-      <td class="none" align="center">No</td>
+      <td class="svn" align="center">SVN</td>
     </tr>
     <tr>
       <td>Generalized attributes</td>
@@ -238,7 +238,7 @@
     <tr>
       <td>Extending <code>sizeof</code></td>
       <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2253.html">N2253</a></td>
-      <td class="none" align="center">No</td>
+      <td class="svn" align="center">SVN</td>
     </tr>
     <tr>
       <td>Inline namespaces</td>





More information about the cfe-commits mailing list