Summary: | [12/13 Regression] Spurious stringop-overflow warning with <atomic> since r12-4725-g88b504b7a8c5affb | ||
---|---|---|---|
Product: | gcc | Reporter: | Ed Catmur <ed> |
Component: | tree-optimization | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED INVALID | ||
Severity: | normal | CC: | marxin, msebor |
Priority: | P3 | Keywords: | diagnostic |
Version: | 12.1.0 | ||
Target Milestone: | 12.2 | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2022-05-13 00:00:00 | |
Bug Depends on: | |||
Bug Blocks: | 88443 |
Description
Ed Catmur
2022-05-12 16:58:07 UTC
Flags: -O1 -Wstringop-overflow=1 https://godbolt.org/z/8r8roz7Pa Affected code: https://github.com/abseil/abseil-cpp/issues/1175 The proposed patch to abseil-cpp corresponds to adding an assumption that `b` is true above. Started with r12-4725-g88b504b7a8c5affb. The warning is caused by the if statement: if p is null, accessing the p->a member is undefined. It triggers because the GCC optimizer splits the code into two branches: one with a nonnull p and another with a null p. The second one triggers the warning. If p can be null then moving the increment to the body of the if statement avoids the undefined behavior (and the warning). If p cannot be null then making the if statement unconditional also avoids the warning. |