[riot-notifications] [RIOT-OS/RIOT] makefiles: Add -fwrapv to CFLAGS (#10748)

Marian Buschsieweke notifications at github.com
Thu Jan 10 20:12:27 CET 2019

@kaspar030: I agree that addressing the problem (fixing the code that relies on undefined behavior) instead of putting duct tape around the problem (making code relying on undefined behavior work as intended instead of fixing the bug) would be much better. And making the compiler warn about those bugs would be the perfect tool for that.

The problem is when I use this buggy code:

#include <stdio.h>
#include <limits.h>

int main(void)
    int a = INT_MAX;
    if (a + 1 < a) { /* <-- Undefined behavior here */
        puts("a + 1 < a!");

    printf("a + 1 = %d, a = %d\n", a + 1, a);
    return 0;

The "expected" (expected != correct here) output would be:
a + 1 < a!
a + 1 = -2147483648, a = 2147483647

But when I compile and run I get with GCC 8.2.0:

$ gcc -Wstrict-overflow -Wall -Wextra -std=c99 -pedantic -o test test.c && ./test
a + 1 = -2147483648, a = 2147483647

`clang` does compile and even produces the expected output in this case, but does not give a warning either. (But beware: `clang` does also optimize checks out, e.g. the assert in http://ptrace.fefe.de/int.c)

So `-Wstrict-overflow` does not detect this issue :-(

You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190110/9030f219/attachment-0001.html>

More information about the notifications mailing list