[llvm-commits] CVS: llvm-gcc/gcc/c-typeck.c
Chris Lattner
lattner at cs.uiuc.edu
Sun Jan 2 20:17:33 PST 2005
Changes in directory llvm-gcc/gcc:
c-typeck.c updated: 1.3 -> 1.4
---
Log message:
Fix PR487: http://llvm.cs.uiuc.edu/PR487 and testcase Regression/CFrontend/2005-01-02-ConstantInits.c
---
Diffs of the changes: (+14 -8)
Index: llvm-gcc/gcc/c-typeck.c
diff -u llvm-gcc/gcc/c-typeck.c:1.3 llvm-gcc/gcc/c-typeck.c:1.4
--- llvm-gcc/gcc/c-typeck.c:1.3 Thu Feb 5 10:05:44 2004
+++ llvm-gcc/gcc/c-typeck.c Sun Jan 2 22:17:21 2005
@@ -46,6 +46,9 @@
#include "target.h"
#include "llvm-out.h"
+struct initializer_stack;
+extern struct initializer_stack *initializer_stack;
+
/* Nonzero if we've already printed a "missing braces around initializer"
message within this initializer. */
static int missing_braces_mentioned;
@@ -2408,10 +2411,14 @@
}
/* For &x[y], return x+y */
- if (TREE_CODE (arg) == ARRAY_REF && !EMIT_LLVM)
+ if (TREE_CODE (arg) == ARRAY_REF)
{
if (!c_mark_addressable (TREE_OPERAND (arg, 0)))
return error_mark_node;
+ /* DON'T fold this, unless its a constant expression which might
+ * initialize a global.
+ */
+ if (!EMIT_LLVM || initializer_stack)
return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
TREE_OPERAND (arg, 1), 1);
}
@@ -2462,17 +2469,16 @@
return error_mark_node;
}
- addr = fold (build (PLUS_EXPR, argtype,
- convert (argtype, addr),
- convert (argtype, byte_position (field))));
- if (EMIT_LLVM) {
+ if (EMIT_LLVM && !initializer_stack) {
/* For LLVM, don't fold pointer arithmetic unless doing so
* produces a constant!
*/
- tree addr2 = build1 (code, argtype, arg);
- if (!TREE_CONSTANT(addr) || TREE_CONSTANT(addr2))
- addr = addr2;
+ addr = build1 (code, argtype, arg);
}
+ else
+ addr = fold (build (PLUS_EXPR, argtype,
+ convert (argtype, addr),
+ convert (argtype, byte_position (field))));
}
else
addr = build1 (code, argtype, arg);
More information about the llvm-commits
mailing list