Off-topic: Why no compiler warning for this?
Peter Dufault
dufault at hda.com
Wed Oct 15 12:23:04 UTC 2014
BTW: This macro is more broken than I thought. eTPUB channels are 64 through 95.
I suppose the reason there is no warning for the left shift that "obviously might overflow" is the same reason you don't get warnings about all multiplies - gcc isn't going to warn on all multiplies that might overflow.
On Oct 15, 2014, at 04:14 , Peter Dufault <dufault at hda.com> wrote:
> This is really a gcc question, but with Joel working to wipe out warnings and not wanting to start a thread on another list I'm asking here. I stumbled on this sequence (obviously simplified) in my code. The "XXX" indicates a restriction I intended to remove but didn't, and it would have broken new code I've been writing. I noticed it before hitting the issue.
>
> The ETPU_CHANNEL_BIT macro is appropriate for the MPC5554 eTPUA with channels 0 through 31. The macro is going to left-shift out of the unit32_t for the channels 32 through 63 in eTPUB (not sure why I bothered with the modulus, it's going to be totally broken for larger channel numbers). Code:
>
> #include <inttypes.h>
>
> /* XXX Need a way to specify which eTPU the channel is in.
> * They happen to both be in A.
> */
> #define ETPU_CHANNEL_BIT(CHAN) (1 << ((CHAN) % 64))
>
> extern void foo(int chan);
> extern void bar(uint32_t bit);
>
> void foo(int chan) {
> uint32_t bit = ETPU_CHANNEL_BIT(chan);
> bar(bit);
> }
>
> Here is the optimization level and the compiler warnings I had in effect. I even added -Wstrict-overflow=5 and -O4 hoping to get a warning without luck.
>
> -O2
> -Wall
> -Wcast-qual
> -Werror
> -Wmissing-prototypes
> -Wpointer-arith
>
> Anyone else surprised? Am I missing something obvious? Any suggested additional warnings?
>
> Peter
> -----------------
> Peter Dufault
> HD Associates, Inc. Software and System Engineering
>
> _______________________________________________
> users mailing list
> users at rtems.org
> http://lists.rtems.org/mailman/listinfo/users
Peter
-----------------
Peter Dufault
HD Associates, Inc. Software and System Engineering
More information about the users
mailing list