| Summary: | UBSAN triggers false-positive warning [-Werror=uninitialized] | ||
|---|---|---|---|
| Product: | gcc | Reporter: | Dmitry Babokin <babokin> |
| Component: | sanitizer | Assignee: | Not yet assigned to anyone <unassigned> |
| Status: | NEW --- | ||
| Severity: | normal | CC: | dodji, jakub, kcc, msebor |
| Priority: | P3 | Keywords: | diagnostic |
| Version: | 8.0 | ||
| Target Milestone: | --- | ||
| See Also: | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107138 | ||
| Host: | Target: | ||
| Build: | Known to work: | ||
| Known to fail: | 10.2.0, 11.0, 8.3.0, 9.3.0 | Last reconfirmed: | 2021-04-06 00:00:00 |
| Bug Depends on: | |||
| Bug Blocks: | 24639, 103035, 99945 | ||
|
Description
Dmitry Babokin
2017-12-12 01:50:36 UTC
The interaction between sanitizers and middle-end emitted warnings is difficult at best. Can you avoid -Werror when sanitizing? (In reply to Richard Biener from comment #1) > The interaction between sanitizers and middle-end emitted warnings is > difficult at best. Can you avoid -Werror when sanitizing? I can, if it's absolutely needed. But it's convenient. I use it in creduce as a criteria that reduction haven't introduced undefined behavior. UBSAN doesn't catch uninitialized variables, so I have to add this switch. An alternative is to have two separate runs. Reconfirmed with GCC 11. The warning sees the IL below and triggers for the call to .UBSAN_NULL() after the CFG pass has removed the initialization of p.1. A simple way to avoid it is to suppress warnings for calls to the sanitizer internal functions. Interestingly, this bug is only reproducible with C++, not when the same code is compiled as C. $ gcc -O0 -S -Wall -fsanitize=undefined -fdump-tree-cfg-details=/dev/stdout -xc++ pr83382.c pr83382.c: In function ‘void f()’: pr83382.c:6:5: warning: value computed is not used [-Wunused-value] 6 | i >> ((!0 || c) && (0 ? j : *p)); | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; Function f (_Z1fv, funcdef_no=0, decl_uid=2788, cgraph_uid=1, symbol_order=5) Scope blocks: { Scope block #0 } Removing basic block 3 ;; basic block 3, loop depth 0 ;; pred: p.1 = p; <<< initialization removed .UBSAN_NULL (p.1, 2B, 4); _1 = MEM[(const int &)p.1]; _2 = _1 != 0; _3 = (int) _2; _4 = (unsigned long) _3; _5 = (unsigned long) i.0; __builtin___ubsan_handle_shift_out_of_bounds (&*.Lubsan_data0, _5, _4); ;; succ: 4 ;; 1 loops found ;; ;; Loop 0 ;; header 0, latch 1 ;; depth 0, outer -1 ;; nodes: 0 1 2 3 ;; 2 succs { 3 } ;; 3 succs { 1 } void f () { int * p.1; <<< not initialized int i.0; <bb 2> : i.0 = i; <bb 3> : .UBSAN_NULL (p.1, 2B, 4); <<< -Wuninitialized _6 = MEM[(const int &)p.1]; _7 = _6 != 0; _8 = (int) _7; return; } pr83382.c:6:25: warning: ‘p.1’ is used uninitialized [-Wuninitialized] 6 | i >> ((!0 || c) && (0 ? j : *p)); | ~~~^~~~~~~~~ pr83382.c:6:25: note: ‘p.1’ was declared here 6 | i >> ((!0 || c) && (0 ? j : *p)); | ~~~^~~~~~~~~ |