public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/32480]  New: gcc 4.1.2 labels in removed dead code weirdness
@ 2007-06-24 10:37 scrippie at xs4all dot nl
  2007-06-24 11:02 ` [Bug c/32480] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: scrippie at xs4all dot nl @ 2007-06-24 10:37 UTC (permalink / raw)
  To: gcc-bugs

Hi,

I'm not sure this qualifies as a bug or not, but there might be some room for
improvement here.

Given the following piece of code, compiled with gcc 4.1.2 without
optimization:

int main(int argc, char **argv)
{
main_start:
        printf("%x %x %x %d\n", &&main_start, &&blah_start, &&blah_end,
&&blah_end - &&blah_start);

        goto blah_end;
blah_start:
        __asm__ __volatile__ ("int $0x80");
blah_end:
        return 1;
}

I get the results: 80483b5 80483b5 80483ed 56

First of all gcc obviously determines the inline assembler is dead code and
removes it. This doesn't seem really bad in most cases, although the inline
assembler has been marked volatile. Should gcc remove unreachable volatile
inline assembler like this? If so, is there any (non-hackish) way to instruct
the compiler to keep off? Wasn't volatile meant for this in the first place?

Second, after dead code removal the label 'blah_start' is at the same address
as the label 'main_start', which seems very counter-intuitive.
There will probably be a good reason for this (I can imagine after dead code
removal you're left with an empty basic block, which can be reordered in any
way you want), but wouldn't it be more clear if this will give the same results
as one would get when removing the inline assembler by hand? I.e. where the
address of blah_start will be equal to the address of blah_end, which is what
one would expect in the first place? Or does some part of some standard outline
this leads to undefined behaviour?

I hope someone has a bit of time to spare to shed some light on this issue.

With kind regards,
 -- Ronald Huizer


-- 
           Summary: gcc 4.1.2 labels in removed dead code weirdness
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: scrippie at xs4all dot nl
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/32480] gcc 4.1.2 labels in removed dead code weirdness
  2007-06-24 10:37 [Bug c/32480] New: gcc 4.1.2 labels in removed dead code weirdness scrippie at xs4all dot nl
@ 2007-06-24 11:02 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-06-24 11:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-06-24 11:02 -------
No, the behavior of GCC is the documented behavior.

http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Labels-as-Values.html
Basically if you don't use the labels as values for computed jumps the label
can be moved anywhere.
If a basic block is unreachable, we can remove it.  This is what is happening
and not removal of asm and then moving the basic block.

Since you cannot use labels as values for anything other than jumps, this is
invalid.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-06-24 11:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-24 10:37 [Bug c/32480] New: gcc 4.1.2 labels in removed dead code weirdness scrippie at xs4all dot nl
2007-06-24 11:02 ` [Bug c/32480] " pinskia at gcc dot gnu dot org

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).