This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR c++/23180 (4.1 regression)
- From: Josh Conner <jconner at apple dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 8 Sep 2005 15:12:47 -0700
- Subject: [PATCH] Fix PR c++/23180 (4.1 regression)
In this PR, g++ is segfaulting on structure initializers containing a
value like this:
((long) (&((struct type *) 42)->field[0])) - 42
(i.e., an attempt to mimic the offsetof functionality).
This is occurring because the tree that is passed to output_constant:
<addr_expr 0x24b47c0
type <pointer_type 0x2422120
type <integer_type 0x24141e0 char public unsigned QI
size <integer_cst 0x2409340 constant invariant 8>
unit size <integer_cst 0x2409360 constant invariant 1>
align 8 symtab 0 alias set -1 precision 8 min
<integer_cst 0x2409420 0> max <integer_cst 0x2409440 255>
pointer_to_this <pointer_type 0x2422120>>
unsigned SI
size <integer_cst 0x24095e0 constant invariant 32>
unit size <integer_cst 0x24092a0 constant invariant 4>
align 32 symtab 0 alias set -1>
constant invariant
arg 0 <array_ref 0x240e390 type <integer_type 0x24141e0 char>
arg 0 <component_ref 0x240e300 type <array_type 0x24b1de0>
arg 0 <indirect_ref 0x24b46a0 type <record_type
0x24b1d20 Track>
arg 0 <integer_cst 0x2491900 constant invariant
42>> arg 1 <field_decl 0x24b1e40 soundName>>
arg 1 <integer_cst 0x24b4680 constant invariant -42>>>
Is being evaluated through the function expand_simple_binop to
generate the code for calculating "42-42". However,
expand_simple_binop isn't appropriate for calculating values outside
of a function, as in this case. The attached patch addresses this
issue by detecting this condition in expand_expr_addr_expr_1, and
computing the (42-42) expression in place.
Note that this behavior doesn't appear with the C front-end, only C+
+. So, if there's some reason that output_constant shouldn't ever
see a tree of this form, please let me know and I'll take a look at
the front-end instead.
Tested on i686-pc-linux-gnu and arm-none-elf with no regressions. OK
for mainline?
- Josh
2005-09-08 Josh Conner <jconner@apple.com>
PR c++/23180
* expr.c (expand_expr_addr_expr_1): Don't invoke
expand_simple_binop if addr and offset are both constants.
Attachment:
pr23180.patch
Description: Binary data