public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/52353] New: -ftrapv -fnon-call-exceptions does not work
Date: Thu, 23 Feb 2012 13:05:00 -0000	[thread overview]
Message-ID: <bug-52353-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             Bug #: 52353
           Summary: -ftrapv -fnon-call-exceptions does not work
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: rguenth@gcc.gnu.org


The testcase from PR47086

void
foo ()
{
  int n = 0;
  while (1)
    {
      int i[n % 1];
      n++;
    }
}

reveals that while on the tree level n++ has an outgoing EH edge, RTL
expansion leaves us with

;; n_5 = n_1 + 1;

(insn 12 11 13 (set (reg:DI 67)
        (sign_extend:DI (reg/v:SI 61 [ n ])))
/space/rguenther/src/svn/trunk/gcc/testsuite/gcc.dg/pr47086.c:11 -1
     (nil))

(insn 13 12 14 (set (reg:DI 4 si)
        (const_int 1 [0x1]))
/space/rguenther/src/svn/trunk/gcc/testsuite/gcc.dg/pr47086.c:11 -1
     (nil))

(insn 14 13 15 (set (reg:DI 5 di)
        (reg:DI 67))
/space/rguenther/src/svn/trunk/gcc/testsuite/gcc.dg/pr47086.c:11 -1
     (nil))

(call_insn/u 15 14 16 (set (reg:DI 0 ax)
        (call (mem:QI (symbol_ref:DI ("__addvdi3") [flags 0x41]) [0 S1 A8])
            (const_int 0 [0])))
/space/rguenther/src/svn/trunk/gcc/testsuite/gcc.dg/pr47086.c:11 -1
     (expr_list:REG_EH_REGION (const_int -2147483648 [0xffffffff80000000])
        (nil))
    (expr_list:REG_DEP_TRUE (use (reg:DI 4 si))
        (expr_list:REG_DEP_TRUE (use (reg:DI 5 di))
            (nil))))

(insn 16 15 17 (set (reg:DI 68)
        (reg:DI 0 ax))
/space/rguenther/src/svn/trunk/gcc/testsuite/gcc.dg/pr47086.c:11 -1
     (expr_list:REG_EQUAL (plus:DI (reg:DI 67)
            (const_int 1 [0x1]))
        (nil)))

(insn 17 16 0 (set (reg/v:SI 63 [ n ])
        (subreg:SI (reg:DI 68) 0))
/space/rguenther/src/svn/trunk/gcc/testsuite/gcc.dg/pr47086.c:11 -1
     (nil))

note that the call is marked CONST.  The EH edge is simply thrown away:

;; Basic block 4 , prev 3, next 5, loop_depth 1, count 0, freq 10000, maybe
hot, flags: new reachable rtl modified.
;; Predecessors:  3 [100.0%]  (fallthru) 5 [100.0%]  (dfs_back)
...
(call_insn/u 15 14 16 4 (set (reg:DI 0 ax)
        (call (mem:QI (symbol_ref:DI ("__addvdi3") [flags 0x41]) [0 S1 A8])
            (const_int 0 [0])))
/space/rguenther/src/svn/trunk/gcc/testsuite/gcc.dg/pr47086.c:11 -1
     (expr_list:REG_EH_REGION (const_int -2147483648 [0xffffffff80000000])
        (nil))
    (expr_list:REG_DEP_TRUE (use (reg:DI 4 si))
        (expr_list:REG_DEP_TRUE (use (reg:DI 5 di))
            (nil))))

(insn 16 15 17 4 (set (reg:DI 68)
        (reg:DI 0 ax))
/space/rguenther/src/svn/trunk/gcc/testsuite/gcc.dg/pr47086.c:11 -1
     (expr_list:REG_EQUAL (plus:DI (reg:DI 67)
            (const_int 1 [0x1]))
        (nil)))

(insn 17 16 18 4 (set (reg/v:SI 63 [ n ])
        (subreg:SI (reg:DI 68) 0))
/space/rguenther/src/svn/trunk/gcc/testsuite/gcc.dg/pr47086.c:11 -1
     (nil))

;; Successors:  5 [100.0%]  (fallthru)


So we seem to leave around the libcall because of the EH side-effect
but do not consider that call as possibly throwing (as it is marked
nothrow on RTL) in find_many_sub_basic_blocks
(at least) and DCE it later, too (sounds similar to PR19020).

Currently generated assembly for gcc.dg/pr47086.c on x86_64 is

foo:
.LFB0:
        .cfi_startproc
        .cfi_personality 0x3,__gcc_personality_v0
        pushq   %rbx
        .cfi_def_cfa_offset 16
        .cfi_offset 3, -16
        movl    $0, %ebx
.L2:
        addl    $1, %ebx
        jmp     .L2


I'm running into this issue when removing unreachable blocks during
expansion, then the landing pad unwind info expansion ICEs because the landing
pad was removed.

We mark the call as not throwing via emit_libcall_block because we pass
it (plus (reg) 1) as EQUIV, which may not trap.


             reply	other threads:[~2012-02-23 13:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-23 13:05 rguenth at gcc dot gnu.org [this message]
2012-02-23 13:21 ` [Bug middle-end/52353] " rguenth at gcc dot gnu.org
2012-03-05 13:09 ` rguenth at gcc dot gnu.org
2012-03-05 13:10 ` rguenth at gcc dot gnu.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=bug-52353-4@http.gcc.gnu.org/bugzilla/ \
    --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).