avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Inconsisten behaviour of switch statement


From: Paulo Marques
Subject: RE: [avr-gcc-list] Inconsisten behaviour of switch statement
Date: Tue, 27 Mar 2007 03:23:02 +0100
User-agent: Internet Messaging Program (IMP) H3 (4.1.2)

Quoting Eric Weddington <address@hidden>:

<snip>

But he shouldn't _have_ to do that.  Bug in gcc?

Hmm.. point. Maybe a "missed optimization" type of bug. You could fill out a
GCC bug report. Feel free to put me on the CC list of the bug report so I
can track it.

This is not a "missed optimization". I hadn't time to test this yet, but if gcc compiles switch statements with volatile vars like that, it can give actual wrong results because the value of the variable may change *while* the if/else tree is being executed.

Imagine that your global var is switching between 0 and 4 and you have a switch statement that has cases 0, 1, 2, 3, 4, "default".

Lets assume the first test in the tree is (var > 2) and var=4 at this point, the code branches to a point where it tests for (var < 4) but before the test is executed the var changes (on an interrupt, or something) to 0. Now the test will give true, making the code execute the option for case 3. But the global variable never had that value at all!

I would need some time to build an actual test case to show this. Unfortunately, time is something that I don't have abundantly right now :(

--
Paulo Marques


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]