Bug 29382 - Bootstrap comparison failure!
Summary: Bootstrap comparison failure!
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on: 34768
Blocks:
  Show dependency treegraph
 
Reported: 2006-10-07 20:03 UTC by Ralf W. Grosse-Kunstleve
Modified: 2008-01-13 18:15 UTC (History)
4 users (show)

See Also:
Host: i386-redhat-linux
Target: i386-redhat-linux
Build: i386-redhat-linux
Known to work:
Known to fail:
Last reconfirmed: 2007-05-29 12:48:39


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf W. Grosse-Kunstleve 2006-10-07 20:03:26 UTC
Platform info:
  Red Hat Enterprise Linux WS release 3 (Taroon)
  Linux legless 2.4.21-4.ELsmp #1 SMP Fri Oct 3 17:52:56 EDT 2003 i686 i686 i386 GNU/Linux
  g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)

gcc SVN snapshot:
  2006-10-07 10:14 PDT

Commands used:
  ../gcc_trunk/configure --prefix=/some/path --enable-languages=c,c++
  make bootstrap

End of make bootstrap output:

Comparing stages 2 and 3
warning: ./cc1-checksum.o differs
warning: ./cc1plus-checksum.o differs
Bootstrap comparison failure!
./cfg.o differs
./cfgloopanal.o differs
./loop-iv.o differs
./predict.o differs
./profile.o differs
./value-prof.o differs
./ipa-inline.o differs
make[2]: *** [compare] Error 1
make[2]: Leaving directory `/net/legless/scratch1/rwgk/gcc_build'
make[1]: *** [stage3-bubble] Error 2
make[1]: Leaving directory `/net/legless/scratch1/rwgk/gcc_build'
make: *** [bootstrap] Error 2


Comments:
  I had the same problem with the SVN snapshot from 2006-09-21 22:03 PDT.
  
  Both SVN snapshots work without a problem under Fedora Core 5 x86_64.
Comment 1 Andrew Pinski 2006-10-07 20:07:54 UTC
This works for me on i686-linux-gnu.  Can you first try compiling 3.4.x and then trying compiling the mainline with that?
Comment 2 Andrew Pinski 2007-03-05 19:43:18 UTC
No feedback in 3 months so closing.
Comment 3 tru 2007-05-21 15:43:31 UTC
[tru@magneto ~]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-58)
[tru@magneto ~]$ rpm -q gcc
gcc-3.2.3-58.i386

is failing too, but a plain gcc-3.4.6 can bootstrap gcc-4.2.0
Comment 4 Jakub Jelinek 2007-05-29 10:40:09 UTC
When using gcc-3.2.3 as bootstrap compiler, i386.c is miscompiled
with -O0 -fkeep-inline-functions (the latter option is what is new
in gcc 4.2 and why 4.1.x bootstrap didn't suffer from this, see
2006-07-04  Eric Botcazou  <ebotcazou@libertysurf.fr>

        PR bootstrap/18058
        * configure.in: Add -fkeep-inline-functions to CFLAGS for stage 1
        if the bootstrap compiler is a GCC version that supports it.
        * configure: Regenerate.
).

typedef struct rtx_def *rtx;
enum machine_mode
{
  VOIDmode = 0,
  DImode = 13
};
extern rtx gen_rtx_CONST_INT (enum machine_mode, long);
extern rtx gen_x86_shld_1 (rtx, rtx, rtx);
static __inline__ rtx
gen_x86_64_shld(rtx a, rtx b, rtx c)
{
  return 0;
}
extern rtx emit_insn (rtx);

void
foo (rtx *high, rtx *low, enum machine_mode mode, int count)
{
  emit_insn ((mode == DImode ? gen_x86_shld_1 : gen_x86_64_shld)
             (high[0], low[0], gen_rtx_CONST_INT (VOIDmode, count)));
}

(extracted from i386.i) is miscompiled (tested latest RHEL3 gcc-3.2.3 as well as current branches/gcc-3_2-branch), it calls gen_x86_64_shld unconditionally.
Removing -fkeep-inline-functions (or adding asm volatile ("") into the inline
function or making gen_x86_64_shld extern instead of static inline cures this).

Now, gcc-3_2-branch is long time closed, so IMNSHO gcc-4.2+ should work around
this bug.
Comment 5 Eric Botcazou 2007-05-29 10:47:15 UTC
> Now, gcc-3_2-branch is long time closed, so IMNSHO gcc-4.2+ should work around
> this bug.

Agreed, we can simply say that GCC 3.2.x is not "is a GCC version that supports
it".  Would you mind writing the patch?  I don't have GCC 3.2.x handy.  TIA.
Comment 6 Jakub Jelinek 2007-05-29 11:42:57 UTC
Seems there were 2 separate bugs that are causing this miscompilation.
1) common_type (in contemporary gcc's common_pointer_type) will for the type
of the whole conditional expression use pointer to attribute const function
rather than non-const:
int fn1 (void);
int fn2 (void) __attribute__((const));
...
(cond ? fn1 : fn2)
I'd say that's an unfortunate effect from representing __attribute__((const))
as TREE_READONLY on the FUNCTION_TYPE rather than as an attribute.  Say for
cond expr where one ptr target is volatile and the other is not the result
needs to be ptr to volatile and similarly for say
int *ptr1;
const int *ptr2;
cond ? ptr1 : ptr2
where the result should be pointer to const, a conservative choice.  But for
__attribute__((const)) functions the conservative choise is the exact opposite,
if I have (cond ? fn1 : fn2) one of the functions isn't const and therefore
nothing should assume the whole thing is pointer to __attribute__((const)) function.  gcc trunk handles this the same way.

2) because of 1), but also e.g. on
typedef struct rtx_def *rtx;
enum machine_mode
{
  VOIDmode = 0,
  DImode = 13
};
extern rtx gen_rtx_CONST_INT (enum machine_mode, long);
extern rtx gen_x86_shld_1 (rtx, rtx, rtx) __attribute__((const));
extern rtx gen_x86_64_shld (rtx, rtx, rtx) __attribute__((const));
extern rtx emit_insn (rtx);

void
foo (rtx *high, rtx *low, enum machine_mode mode, int count)
{
  emit_insn ((mode == DImode ? gen_x86_shld_1 : gen_x86_64_shld)
             (high[0], low[0], gen_rtx_CONST_INT (VOIDmode, count)));
}
where 1) doesn't apply a properly emitted expanded COND_EXPR into rtl is
passed through emit_libcall_block which changes:
(insn 31 0 32 (set (reg:CCZ 17 flags)
        (compare:CCZ (mem/f:SI (plus:DI (reg/f:DI 54 virtual-stack-vars)
                    (const_int -20 [0xffffffffffffffec])) [0 mode+0 S4 A32])
            (const_int 13 [0xd]))) -1 (nil)
    (nil))

(jump_insn 32 31 34 (set (pc)
        (if_then_else (ne (reg:CCZ 17 flags)
                (const_int 0 [0x0]))
            (label_ref 37)
            (pc))) -1 (nil)
    (nil))

(insn 34 32 35 (set (reg:DI 63)
        (symbol_ref:DI ("gen_x86_shld_1"))) -1 (nil)
    (nil))

(jump_insn 35 34 36 (set (pc)
        (label_ref 40)) -1 (nil)
    (nil))

(barrier 36 35 37)

(code_label 37 36 39 2 "" "" [0 uses])

(insn 39 37 40 (set (reg:DI 63)
        (symbol_ref:DI ("gen_x86_64_shld"))) -1 (nil)
    (nil))

(code_label 40 39 42 3 "" "" [0 uses])

(insn 42 40 44 (set (reg:DI 1 rdx)
        (reg:DI 60)) -1 (nil)
    (nil))

(insn 44 42 46 (set (reg:DI 4 rsi)
        (mem:DI (reg/f:DI 61) [0 S8 A64])) -1 (nil)
    (nil))

(insn 46 44 47 (set (reg:DI 5 rdi)
        (mem:DI (reg/f:DI 62) [0 S8 A64])) -1 (nil)
    (nil))

(call_insn/u 47 46 0 (set (reg:DI 0 rax)
        (call (mem:QI (reg:DI 63) [0 S1 A8])
            (const_int 0 [0x0]))) -1 (nil)
    (nil)
    (expr_list (use (reg:DI 5 rdi))
        (expr_list (use (reg:DI 4 rsi))
            (expr_list (use (reg:DI 1 rdx))
                (nil)))))

into
(insn 34 30 39 (set (reg:DI 63)
        (symbol_ref:DI ("gen_x86_shld_1"))) -1 (nil)
    (nil))

(insn 39 34 31 (set (reg:DI 63)
        (symbol_ref:DI ("gen_x86_64_shld"))) -1 (nil)
    (nil))

(insn 31 39 32 (set (reg:CCZ 17 flags)
        (compare:CCZ (mem/f:SI (plus:DI (reg/f:DI 54 virtual-stack-vars)
                    (const_int -20 [0xffffffffffffffec])) [0 mode+0 S4 A32])
            (const_int 13 [0xd]))) -1 (nil)
    (nil))

(jump_insn 32 31 35 (set (pc)
        (if_then_else (ne (reg:CCZ 17 flags)
                (const_int 0 [0x0]))
            (label_ref 37)
            (pc))) -1 (nil)
    (nil))

(jump_insn 35 32 36 (set (pc)
        (label_ref 40)) -1 (nil)
    (nil))

(insn 34 30 39 (set (reg:DI 63)
        (symbol_ref:DI ("gen_x86_shld_1"))) -1 (nil)
    (nil))

(insn 39 34 31 (set (reg:DI 63)
        (symbol_ref:DI ("gen_x86_64_shld"))) -1 (nil)
    (nil))

(insn 31 39 32 (set (reg:CCZ 17 flags)
        (compare:CCZ (mem/f:SI (plus:DI (reg/f:DI 54 virtual-stack-vars)
                    (const_int -20 [0xffffffffffffffec])) [0 mode+0 S4 A32])
            (const_int 13 [0xd]))) -1 (nil)
    (nil))

(jump_insn 32 31 35 (set (pc)
        (if_then_else (ne (reg:CCZ 17 flags)
                (const_int 0 [0x0]))
            (label_ref 37)
            (pc))) -1 (nil)
    (nil))

(jump_insn 35 32 36 (set (pc)
        (label_ref 40)) -1 (nil)
    (nil))

(barrier 36 35 37)

(code_label 37 36 40 2 "" "" [0 uses])

(code_label 40 37 42 3 "" "" [0 uses])

(insn 42 40 44 (set (reg:DI 1 rdx)
        (reg:DI 60)) -1 (nil)
    (nil))

(insn 44 42 46 (set (reg:DI 4 rsi)
        (mem:DI (reg/f:DI 61) [0 S8 A64])) -1 (nil)
    (nil))

(insn 46 44 47 (set (reg:DI 5 rdi)
        (mem:DI (reg/f:DI 62) [0 S8 A64])) -1 (nil)
    (nil))

(call_insn/u 47 46 49 (set (reg:DI 0 rax)
        (call (mem:QI (reg:DI 63) [0 S1 A8])
            (const_int 0 [0x0]))) -1 (nil)
    (expr_list:REG_EH_REGION (const_int -1 [0xffffffffffffffff])
        (nil))
    (expr_list (use (reg:DI 5 rdi))
        (expr_list (use (reg:DI 4 rsi))
            (expr_list (use (reg:DI 1 rdx))
                (nil)))))

Haven't checked yet what exactly fixed this on 3.4 (or already 3.3) branch.
Comment 7 Jakub Jelinek 2007-05-29 12:48:38 UTC
2) is apparently PR11557, fixed in GCC 3.3.1+.

So, I'd say as workaround we should not use -fkeep-inline-functions for
GCC < 3.3.1.  Testing a patch for that.
Comment 8 Jakub Jelinek 2007-05-30 13:32:50 UTC
Subject: Bug 29382

Author: jakub
Date: Wed May 30 13:32:34 2007
New Revision: 125182

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=125182
Log:
	PR bootstrap/29382
	* configure.in: Don't use -fkeep-inline-functions for GCC < 3.3.1.
	* configure: Rebuilt.

Modified:
    trunk/ChangeLog
    trunk/configure
    trunk/configure.ac

Comment 9 Jakub Jelinek 2007-05-30 13:48:19 UTC
Subject: Bug 29382

Author: jakub
Date: Wed May 30 13:48:07 2007
New Revision: 125184

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=125184
Log:
	PR bootstrap/29382
	* configure.in: Don't use -fkeep-inline-functions for GCC < 3.3.1.
	* configure: Rebuilt.

Modified:
    branches/gcc-4_2-branch/ChangeLog
    branches/gcc-4_2-branch/configure
    branches/gcc-4_2-branch/configure.in

Comment 10 Jakub Jelinek 2007-05-30 14:03:08 UTC
Worked around in 4.2.1+ and on the trunk.