Following program miscompiles with -O1 on (32 bit) Darwin. Works with -O0.
It appears that RTL generation for
printf (&"cmp.func is %p (expected %p)\n"[0],
comparator_matrixD.2001[0][(intD.2) (D.2150 == 2)],
compare_e_stringD.2019);
is incorrect, but I haven't dug deeply yet. I will be fixing this unless
somebody recognizes it as a dup
#include <stdio.h>
#define test(a) ((a) ? 1 : 0)
typedef int (*arg_cmp_func)();
class Item_func
{
public:
enum Functype { UNKNOWN_FUNC, EQ_FUNC, EQUAL_FUNC };
virtual enum Functype functype() const { return UNKNOWN_FUNC; }
};
class Item_bool_func2 : public Item_func
{
public:
virtual enum Functype functype() const { return EQUAL_FUNC; }
};
class Arg_comparator
{
public:
Item_bool_func2 *owner;
arg_cmp_func func;
static arg_cmp_func comparator_matrix[4][2];
int Arg_comparator::set_compare_func(Item_bool_func2 *item, int type)
{
owner = item;
/****************** problematic line is here ************************/
func = comparator_matrix[type][test(owner->functype() ==
Item_func::EQUAL_FUNC)];
return 0;
}
};
int compare_string() { return 0; }
int compare_e_string() { return 0; }
int compare_real() { return 0; }
int compare_e_real() { return 0; }
int compare_int_signed() { return 0; }
int compare_e_int() { return 0; }
int compare_row() { return 0; }
int compare_e_row() { return 0; }
arg_cmp_func Arg_comparator::comparator_matrix[4][2] =
{{&compare_string, &compare_e_string},
{&compare_real, &compare_e_real},
{&compare_int_signed, &compare_e_int},
{&compare_row, &compare_e_row}};
int main()
{
Arg_comparator cmp;
Item_bool_func2 equal_func;
cmp.set_compare_func(&equal_func, 0);
printf("cmp.func is %p (expected %p)\n", cmp.func, &compare_e_string);
}
--
Summary: miscompilation of correct code
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: dalej at apple dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: same
GCC host triplet: powerpc-apple-darwin8.0.0.b3
GCC target triplet: same
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19650