public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39232]  New: apparent bizarre miscompilation on AVR
@ 2009-02-18 16:40 regehr at cs dot utah dot edu
  2009-02-18 16:41 ` [Bug c/39232] " regehr at cs dot utah dot edu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: regehr at cs dot utah dot edu @ 2009-02-18 16:40 UTC (permalink / raw)
  To: gcc-bugs

This is seen on the version of avr-gcc 4.3.3 that gets built by the script that
comes with FemtoOS 0.88.

I'm compiling like this:

  avr-gcc -mmcu=atmega128 -O0 small_preprocessed.c -o small.elf

And observing the result of a run like this:

  java -server avrora.Main -platform=mica2 -simulation=sensor-network
-monitors=break -colors=false -seconds=15 small.elf

Of course you need Avrora installed to do this.

The program computes a checksum over its globals before terminating, this is
found in the Avrora output as: 

  r30:r31 = 0x5DAD

It can be seen that the checksum computed at -O0 is different from higher
optimization levels, which give 0xDBFA.  My belief is that the -O0 result is
wrong, and here's why: deleting almost any line of code from the program causes
it to have the same checksum at all optimization levels.  To see this, delete
for example the line "int16_t l_46 = 1;" in func_43().  This line obviously has
no effect on the computation.  This changes the checksum to 0xDBFA, which is in
agreement with higher optimization levels.

The test code is obviously nonsense.  However, I cannot give a smaller testcase
since deleting code makes the problem go away.

My belief is that this problem in not the result of a stack overflow: my stack
analysis tool estimates that maximum RAM usage (including stack) is 2496 bytes,
leaving plenty of free space on the mega128.

My believe is that this problem is no due to undefined behavior in the C code.


-- 
           Summary: apparent bizarre miscompilation on AVR
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: regehr at cs dot utah dot edu
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: avr


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


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

* [Bug c/39232] apparent bizarre miscompilation on AVR
  2009-02-18 16:40 [Bug c/39232] New: apparent bizarre miscompilation on AVR regehr at cs dot utah dot edu
@ 2009-02-18 16:41 ` regehr at cs dot utah dot edu
  2009-02-20  3:33 ` [Bug target/39232] " regehr at cs dot utah dot edu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: regehr at cs dot utah dot edu @ 2009-02-18 16:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from regehr at cs dot utah dot edu  2009-02-18 16:41 -------
Created an attachment (id=17326)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17326&action=view)
failure-inducing C program


-- 


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


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

* [Bug target/39232] apparent bizarre miscompilation on AVR
  2009-02-18 16:40 [Bug c/39232] New: apparent bizarre miscompilation on AVR regehr at cs dot utah dot edu
  2009-02-18 16:41 ` [Bug c/39232] " regehr at cs dot utah dot edu
@ 2009-02-20  3:33 ` regehr at cs dot utah dot edu
  2009-02-20  3:44 ` regehr at cs dot utah dot edu
  2009-03-04 22:22 ` regehr at cs dot utah dot edu
  3 siblings, 0 replies; 5+ messages in thread
From: regehr at cs dot utah dot edu @ 2009-02-20  3:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from regehr at cs dot utah dot edu  2009-02-20 03:32 -------
Created an attachment (id=17334)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17334&action=view)
failure-inducing C program


-- 


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


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

* [Bug target/39232] apparent bizarre miscompilation on AVR
  2009-02-18 16:40 [Bug c/39232] New: apparent bizarre miscompilation on AVR regehr at cs dot utah dot edu
  2009-02-18 16:41 ` [Bug c/39232] " regehr at cs dot utah dot edu
  2009-02-20  3:33 ` [Bug target/39232] " regehr at cs dot utah dot edu
@ 2009-02-20  3:44 ` regehr at cs dot utah dot edu
  2009-03-04 22:22 ` regehr at cs dot utah dot edu
  3 siblings, 0 replies; 5+ messages in thread
From: regehr at cs dot utah dot edu @ 2009-02-20  3:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from regehr at cs dot utah dot edu  2009-02-20 03:44 -------
Created an attachment (id=17335)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17335&action=view)
diff between broken and working assembly

This is a diff between the attachment compiled at -O0 and the same program but
with the declaration and initialization of l_46 commented out.  The first
problem (I claim) produces incorrect output, the second correct.  So this diff
has to show the problem.  

The change is to turn func_43() to this:

int32_t func_43 (int64_t p_44)
{
  int16_t l_45 = 1;
  //int16_t l_46 = 1;
  return l_45;
}


-- 


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


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

* [Bug target/39232] apparent bizarre miscompilation on AVR
  2009-02-18 16:40 [Bug c/39232] New: apparent bizarre miscompilation on AVR regehr at cs dot utah dot edu
                   ` (2 preceding siblings ...)
  2009-02-20  3:44 ` regehr at cs dot utah dot edu
@ 2009-03-04 22:22 ` regehr at cs dot utah dot edu
  3 siblings, 0 replies; 5+ messages in thread
From: regehr at cs dot utah dot edu @ 2009-03-04 22:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from regehr at cs dot utah dot edu  2009-03-04 22:22 -------
We narrowed this down to a nasty Avrora bug.

In the future we'll try to reproduce in AVR Studio before reporting.


-- 

regehr at cs dot utah dot edu changed:

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


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


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

end of thread, other threads:[~2009-03-04 22:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-18 16:40 [Bug c/39232] New: apparent bizarre miscompilation on AVR regehr at cs dot utah dot edu
2009-02-18 16:41 ` [Bug c/39232] " regehr at cs dot utah dot edu
2009-02-20  3:33 ` [Bug target/39232] " regehr at cs dot utah dot edu
2009-02-20  3:44 ` regehr at cs dot utah dot edu
2009-03-04 22:22 ` regehr at cs dot utah dot edu

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