Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undetected integer overflows in constant-folded expressions #217

Open
lzaoral opened this issue Feb 16, 2022 · 0 comments
Open

Undetected integer overflows in constant-folded expressions #217

lzaoral opened this issue Feb 16, 2022 · 0 comments

Comments

@lzaoral
Copy link
Contributor

lzaoral commented Feb 16, 2022

Code:

#include <limits.h>
int a = (INT_MAX + 1) - 5;

IR:

@a = dso_local global i32 2147483643, align 4

The easiest solution seems to be parsing of the overflow warnings emitted by clang. However, we still need to check that the expression is reachable (clang generates these warnings even if such expression is wrapped in if (0) statement) and to generate a suitable witness.

$ clang -Winteger-overflow -S -emit-llvm const.c -o const.ll
const.c:2:18: warning: overflow in expression; result is -2147483648 with type 'int' [-Winteger-overflow]
int a = (INT_MAX + 1) - 5;
                 ^
const.c:2:23: warning: overflow in expression; result is 2147483643 with type 'int' [-Winteger-overflow]
int a = (INT_MAX + 1) - 5;

2 warnings generated.

Related: https://gitlab.com/sosy-lab/benchmarking/sv-benchmarks/-/issues/1327

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant