Issue 235503
Summary UBSan reports member access within null pointer in unevaluated ?: operand
Labels new issue
Assignees
Reporter etan-status
    Platform: arm64 macOS

Compilers (Homebrew):
```
Homebrew clang version 17.0.6
Target: arm64-apple-darwin27.0.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm@17/bin
```
```
Homebrew clang version 22.1.8
Target: arm64-apple-darwin27.0.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm@22/22.1.8/bin
Configuration file: /opt/homebrew/Cellar/llvm@22/22.1.8/etc/clang/arm64-apple-darwin27.cfg
```
```
Homebrew clang version 23.1.4
Target: arm64-apple-darwin27.0.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/llvm/23.1.4/bin
Configuration file: /opt/homebrew/Cellar/llvm/23.1.4/etc/clang/arm64-apple-darwin27.cfg
```

bug.c:
```c
struct S { long len; char data[]; };

const char *f(int a) { return a ? ((struct S *)0)->data : 0; }

const char *g(void) { return ((struct S *)0) ? ((struct S *)0)->data : 0; }

int main(void) { return f(0) != 0 || g() != 0; }
```

Command:
```sh
clang -fsanitize=null bug.c -o bug && ./bug
```

Output (23.1.4; 17.0.6 and 22.1.8 print the same reports, with -O0 and -O2):
```
bug.c:3:52: runtime error: member access within null pointer of type 'struct S'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior bug.c:3:52
bug.c:5:65: runtime error: member access within null pointer of type 'struct S'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior bug.c:5:65
```

Expected output: none.

Related: #51612 (its example no longer reproduces on 23.1.4)

Note: Apple clang does not have this problem.
Apple clang version 21.0.0 (clang-2100.3.34.2)
Target: arm64-apple-darwin27.0.0

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to