Warn about bitwise shift with negative shift amount (UB in C) - #1989
Conversation
Agent-Logs-Url: https://github.com/goblint/analyzer/sessions/c81d432d-7783-4469-9c48-85d6bb3d1531 Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/goblint/analyzer/sessions/c81d432d-7783-4469-9c48-85d6bb3d1531 Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/goblint/analyzer/sessions/c81d432d-7783-4469-9c48-85d6bb3d1531 Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
|
@copilot: Address Simmo's comment, check why the tests don't pass and fix this. |
…d int Agent-Logs-Url: https://github.com/goblint/analyzer/sessions/1dec7b36-67b9-4835-abab-afb1ff9c852e Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
Done in commit
|
|
@copilot: One of the tests still fails! |
… int top Agent-Logs-Url: https://github.com/goblint/analyzer/sessions/daf39d5f-96e8-4887-9ade-7004d5fcc994 Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
... Fixed in commit |
Agent-Logs-Url: https://github.com/goblint/analyzer/sessions/fd400683-08ae-4a0a-b4ff-458d87ba80f8 Co-authored-by: michael-schwarz <13812333+michael-schwarz@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds explicit diagnostics for undefined behavior when bit-shifting by a negative amount, improving the base analysis’ reporting precision and extending regression coverage.
Changes:
- Refactors shift-negative checking into
check_shift_negand integrates it intoShiftlt/Shiftrthandling insrc/analyses/base.ml. - Emits
safe/warn/errorresults forChecks.Category.InvalidShiftbased on interval bounds of the shift amount. - Adds a dedicated regression test for negative/possibly-negative and provably non-negative shift amounts.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/regression/98-bitwise-operations/09-shift-neg.c | Adds regression coverage for left/right shifts with negative, possibly-negative, and non-negative shift amounts. |
| src/analyses/base.ml | Introduces check_shift_neg and invokes it for both << and >> to diagnose negative shift counts as UB. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CHANGES: * Add new may-happen-in-parallel analyses (goblint/analyzer#1805, goblint/analyzer#1865, goblint/analyzer#1913, goblint/analyzer#1928). * Add Open Verification Dashboard checks output (goblint/analyzer#1838, goblint/analyzer#1929). * Add negative bitwise shift warnings (goblint/analyzer#1637, goblint/analyzer#1989). * Add missing function declaration warnings (goblint/analyzer#1911). * Improve overflow warnings (goblint/analyzer#1894, goblint/analyzer#1895, goblint/analyzer#1896, goblint/analyzer#1905). * Fix spurious overflow checks (goblint/analyzer#1767, goblint/analyzer#1909, goblint/analyzer#1910, goblint/analyzer#1932, goblint/analyzer#2022). * Fix missing overflow and out-of-bounds checks (goblint/analyzer#1935, goblint/analyzer#2017, goblint/analyzer#2029). * Optimize base analysis domain using Patricia trees (goblint/analyzer#2002, goblint/analyzer#2015). * Optimize field offset calculations (goblint/analyzer#1964, goblint/analyzer#1973, goblint/analyzer#1974). * Optimize non-incremental top-down solver (goblint/analyzer#1566, goblint/analyzer#1972). * Add OCaml 5.5 support (goblint/analyzer#2006, goblint/analyzer#2010).
shift_amount_negcheck→check_shift_neg dir ythat directly performs the M.error/M.warn/Checks.* actionsShiftltandShiftrtcases now callcheck_shift_neg "left" yandcheck_shift_neg "right" yrespectively[0,5]instead ofunsigned inttopID.ge/ID.ltinstead ofID.minimal/ID.maximalincheck_shift_negfor potentially more precise results