Joern Rennecke wrote:
Andrew Haley wrote:
> > So it seems I have to abandom the system compiler for doing
bootstraps.
Can you make a simple testcase for this?
Andrew.
Attached.
This fails at -O0..-O2 for gcc 3.2.2 and gcc 3.2.3 on
i686-pc-linux-gnu. For gcc 3.4.3,
it still fails at -O1.
4.2.0 appears to be OK, although it might be this bug only hidden by
the tree optimizers
optimizing the test case into something that doesn't trigger the bug.
I've identified this code in 3.4.0 c-typeck.c:common_type as the culprit:
case POINTER_TYPE:
/* For two pointers, do this recursively on the target type,
and combine the qualifiers of the two types' targets. */
/* This code was turned off; I don't know why.
But ANSI C specifies doing this with the qualifiers.
So I turned it on again. */
{
tree pointed_to_1 = TREE_TYPE (t1);
tree pointed_to_2 = TREE_TYPE (t2);
tree target = common_type (TYPE_MAIN_VARIANT (pointed_to_1),
TYPE_MAIN_VARIANT (pointed_to_2));
t1 = build_pointer_type (c_build_qualified_type
(target,
TYPE_QUALS (pointed_to_1) |
TYPE_QUALS (pointed_to_2)));
return build_type_attribute_variant (t1, attributes);
}
(gdb) s
325 TYPE_QUALS (pointed_to_2)));
(gdb)
c_build_qualified_type (type=0xb5988804, type_quals=1)
at ../../srcw/gcc/c-common.c:2793
2793 if (type == error_mark_node)
(gdb) call debug_tree(type)
<function_type 0xb5988804
type <integer_type 0xb599c4a4 int SI
size <integer_cst 0xb599a208 constant 32>
unit size <integer_cst 0xb599a294 constant 4>
align 32 symtab 0 alias set -1 precision 32 min <integer_cst
0xb599a26c -2147483648> max <integer_cst 0xb599a280 2147483647>
pointer_to_this <pointer_type 0xb59a3ca8>>
DI
size <integer_cst 0xb599a5a0 type <integer_type 0xb59a3654
bit_size_type> constant 64>
unit size <integer_cst 0xb599a794 type <integer_type 0xb59a35e8
unsigned int> constant 8>
align 64 symtab 0 alias set -1
arg-types <tree_list 0xb598485c value <integer_type 0xb599c4a4 int>
chain <tree_list 0xb598467c value <void_type 0xb59a3870 void>>>
pointer_to_this <pointer_type 0xb58f6360>>
One of the function pointers is TREE_READONLY, and we make the result
TREE_READONLY.
This is wrong, since TREE_READONLY for functions means that they have no
side effects.
There is similar code in mainline, but it is not reached with the testcase.