Issue 61522
Summary UBsan produces incorrect report on a null-pointer-dereference
Labels new issue
Assignees
Reporter shao-hua-li
    For the following code, Clang's UBsan cannot produce an incorrect report on the null-pointer-dereference. GCC'UBsan can produce the correct report.

Compiler explorer: https://godbolt.org/z/949vYEaMb

```shell
% cat a.c
struct a {
  char d
} ;
struct a b;
struct a *c;
struct a e() {
 int f[3];
  f[2]=0;
  c = 0;
  f[2]=0;
  *c = b;
  return b;
}
void main() {
    e(); 
}
%
% clang -fsanitize=undefined -O0 a.c && ./a.out
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 
...
% clang -fsanitize=undefined -O2 a.c && ./a.out
/a.c:8:3: runtime error: subtraction of unsigned offset from 0x7ffcd03c3e2c overflowed to 0x7ffcd03c3e34
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /a.c:8:3 in 
/a.c:10:3: runtime error: subtraction of unsigned offset from 0x7ffcd03c3e2c overflowed to 0x7ffcd03c3e34
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /a.c:10:3 in 
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==1==ERROR: UndefinedBehaviorSanitizer
...
%
% gcc -fsanitize=undefined -O2 a.c && ./a.out
/a.c:11:6: runtime error: store to null pointer of type 'struct a'
%
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to