[llvm-commits] CVS: llvm-gcc/gcc/cp/parser.c typeck.c

Chris Lattner lattner at cs.uiuc.edu
Mon Jan 3 14:29:29 PST 2005



Changes in directory llvm-gcc/gcc/cp:

parser.c updated: 1.2 -> 1.3
typeck.c updated: 1.3 -> 1.4
---
Log message:

Do not form array expressions if we are parsing an initializer.  GCC cannot
handle array expressions as constants, which results in these causing runtime
initialization of initializers instead of compile time initialization in
some cases.  This fixes C++Frontend/2005-01-03-StaticInitializers.cpp



---
Diffs of the changes:  (+12 -12)

Index: llvm-gcc/gcc/cp/parser.c
diff -u llvm-gcc/gcc/cp/parser.c:1.2 llvm-gcc/gcc/cp/parser.c:1.3
--- llvm-gcc/gcc/cp/parser.c:1.2	Sat Nov 27 19:23:05 2004
+++ llvm-gcc/gcc/cp/parser.c	Mon Jan  3 16:29:14 2005
@@ -10878,7 +10878,7 @@
    set to FALSE if there is no initializer present.  If there is an
    initializer, and it is not a constant-expression, *NON_CONSTANT_P
    is set to true; otherwise it is set to false.  */
-
+extern int parsing_initializer;
 static tree
 cp_parser_initializer (cp_parser* parser, bool* is_parenthesized_init,
 		       bool* non_constant_p)
@@ -10895,6 +10895,8 @@
   /* Assume that the initializer is constant.  */
   *non_constant_p = false;
 
+  ++parsing_initializer;
+
   if (token->type == CPP_EQ)
     {
       /* Consume the `='.  */
@@ -10912,6 +10914,7 @@
       init = error_mark_node;
     }
 
+  --parsing_initializer;
   return init;
 }
 


Index: llvm-gcc/gcc/cp/typeck.c
diff -u llvm-gcc/gcc/cp/typeck.c:1.3 llvm-gcc/gcc/cp/typeck.c:1.4
--- llvm-gcc/gcc/cp/typeck.c:1.3	Thu Feb  5 10:05:47 2004
+++ llvm-gcc/gcc/cp/typeck.c	Mon Jan  3 16:29:15 2005
@@ -20,6 +20,7 @@
 the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
+extern int parsing_initializer;
 
 /* This file is part of the C++ front end.
    It contains routines to build C++ expressions given their operands,
@@ -2223,7 +2224,7 @@
      * instead, generate an array ref, even though the first argument is a
      * pointer, not an array!
      */
-    if (EMIT_LLVM)
+    if (EMIT_LLVM && !parsing_initializer)
       return build (ARRAY_REF, TREE_TYPE(TREE_TYPE(ar)), ar, ind);
 
     return build_indirect_ref (cp_build_binary_op (PLUS_EXPR, ar, ind),
@@ -3907,7 +3908,7 @@
 	}
 
       /* For &x[y], return x+y */
-      if (TREE_CODE (arg) == ARRAY_REF && !EMIT_LLVM)
+      if (TREE_CODE (arg) == ARRAY_REF && (!EMIT_LLVM || parsing_initializer))
 	{
 	  if (!cxx_mark_addressable (TREE_OPERAND (arg, 0)))
 	    return error_mark_node;
@@ -4037,7 +4038,6 @@
 	  }
 	else
 	  {
-            tree addrLLVMTmp;
 	    /* Unfortunately we cxannot just build an address
 	       expression here, because we would not handle
 	       address-constant-expressions or offsetof correctly.  */
@@ -4049,17 +4049,14 @@
 	    
 	    rval = build_base_path (PLUS_EXPR, rval, binfo, 1);
 	    rval = build_nop (argtype, rval);
+            if (!EMIT_LLVM || parsing_initializer)
 	    addr = fold (build (PLUS_EXPR, argtype, rval,
 				cp_convert (argtype, byte_position (field))));
-
-            addrLLVMTmp = fold(build1(ADDR_EXPR, argtype, arg));
-            if (EMIT_LLVM &&
-                (TREE_CONSTANT(addrLLVMTmp) || !TREE_CONSTANT(addr))) {
-              /* For LLVM, don't fold pointer arithmetic unless doing so
-               * produces a constant!
+            else
+              /* For LLVM, don't fold pointer arithmetic unless parsing a
+               * static initializer.
                */
-              addr = addrLLVMTmp;
-            }
+              addr = fold(build1(ADDR_EXPR, argtype, arg));
 	  }
 
 	if (TREE_CODE (argtype) == POINTER_TYPE






More information about the llvm-commits mailing list