public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug bootstrap/29382] Bootstrap comparison failure!
Date: Tue, 29 May 2007 11:43:00 -0000	[thread overview]
Message-ID: <20070529114258.23235.qmail@sourceware.org> (raw)
In-Reply-To: <bug-29382-3137@http.gcc.gnu.org/bugzilla/>



------- Comment #6 from jakub at gcc dot gnu dot org  2007-05-29 11:42 -------
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.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29382


  parent reply	other threads:[~2007-05-29 11:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-07 20:03 [Bug bootstrap/29382] New: " rwgk at yahoo dot com
2006-10-07 20:08 ` [Bug bootstrap/29382] " pinskia at gcc dot gnu dot org
2007-03-05 19:43 ` pinskia at gcc dot gnu dot org
2007-05-21 14:43 ` tru at pasteur dot fr
2007-05-29 10:40 ` jakub at gcc dot gnu dot org
2007-05-29 10:47 ` ebotcazou at gcc dot gnu dot org
2007-05-29 11:43 ` jakub at gcc dot gnu dot org [this message]
2007-05-29 12:48 ` jakub at gcc dot gnu dot org
2007-05-30 13:33 ` jakub at gcc dot gnu dot org
2007-05-30 13:48 ` jakub at gcc dot gnu dot org
2007-05-30 14:03 ` jakub at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070529114258.23235.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).