Issue 134577
Summary The flag -fno-strict-overflow has not effect with clang
Labels clang:driver, clang:frontend
Assignees
Reporter yonghong-song
    The 'fno-strict-overflow' intends to not print out signed-integer-overflow.
gcc honors this but clang not. Based on clang documentation https://clang.llvm.org/docs/DiagnosticsReference.html#wstrict-overflow
-fstrict-overflow (and -fno-strict-overflow) does not have impact all.

The following are some examples:
```
$ cat t.c
#include <stdio.h>
extern int a, b;
int main() {
  int c = a + b;
  fprintf(stderr, "c = %d\n", c);
  return 0;
}
$ cat t1.c
int a = 0x7fffFFFF;
int b = 0x7fffFFFF;
$ gcc --version
gcc (GCC) [11.5.0](https://github.com/intern/bunny/?q=obi%2011.5.0) 20240719 (Red Hat 11.5.0-2)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ clang --version
clang version 21.0.0git (https://github.com/llvm/llvm-project.git b9207aef09387342837069d2c0857e6d331a516c)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/yhs/work/llvm-project/llvm/build.20/Release/bin
$ gcc -O2 -fsanitize=signed-integer-overflow -fno-strict-overflow t.c t1.c && ./a.out
c = -2
$ gcc -O2 -fsanitize=signed-integer-overflow t.c t1.c && ./a.out
t.c:4:7: runtime error: signed integer overflow: 2147483647 + 2147483647 cannot be represented in type 'int'
c = -2
$ clang -O2 -fsanitize=signed-integer-overflow -fno-strict-overflow t.c t1.c && ./a.out
t.c:4:13: runtime error: signed integer overflow: 2147483647 + 2147483647 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior t.c:4:13 
c = -2
$ clang -O2 -fsanitize=signed-integer-overflow t.c t1.c && ./a.out
t.c:4:13: runtime error: signed integer overflow: 2147483647 + 2147483647 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior t.c:4:13 
c = -2
$
```

So in summary, for '-fno-strict-overflow' (which is supposed to surpress overflow error), gcc works properly and clang ignores that flag and will emit error regardless.

In linux/Makefile, we have
```
# disable invalid "can't wrap" optimizations for signed / pointers
KBUILD_CFLAGS   += -fno-strict-overflow
```

so the kernel expects to silence signed overflow when ubsan is enabled.
But it only works for gcc build kernel, but not for clang build kernel.

Are there any discussions about implementing `-fno-strict-overflow` properly?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to