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

Clang #7

Open
andrewt0301 opened this issue Apr 7, 2023 · 5 comments
Open

Clang #7

andrewt0301 opened this issue Apr 7, 2023 · 5 comments

Comments

@andrewt0301
Copy link
Owner

clang --analyze -Xclang -analyzer-constraints=z3 -Xclang -analyzer-max-loop -Xclang 5 .\main.cpp

@andrewt0301
Copy link
Owner Author

int main() {
int a = 0;
for (int i = 3; i >= 0; i--) {
a += 42 / i;
}
return a;
}

@andrewt0301
Copy link
Owner Author

andrewt0301 commented Apr 9, 2023

andrewt@LAPTOP-5GPL0IVV:~/src/examples$ cat main.cpp

int main() {
  int a = 0;
  for (int i = 3; i >= 0; i--) {
    a += 42 / i;
  }
  return a;
}

andrewt@LAPTOP-5GPL0IVV:~/src/examples$ clang-tidy main.cpp --
1 warning generated.
/home/andrewt/src/examples/main.cpp:5:13: warning: Division by zero [clang-analyzer-core.DivideZero]
    a += 42 / i;
         ~~~^~~
/home/andrewt/src/examples/main.cpp:4:3: note: Loop condition is true.  Entering loop body
  for (int i = 3; i >= 0; i--) {
  ^
/home/andrewt/src/examples/main.cpp:4:3: note: Loop condition is true.  Entering loop body
/home/andrewt/src/examples/main.cpp:4:3: note: Loop condition is true.  Entering loop body
/home/andrewt/src/examples/main.cpp:4:27: note: The value 0 is assigned to 'i'
  for (int i = 3; i >= 0; i--) {
                          ^~~
/home/andrewt/src/examples/main.cpp:4:3: note: Loop condition is true.  Entering loop body
  for (int i = 3; i >= 0; i--) {
  ^
/home/andrewt/src/examples/main.cpp:5:13: note: Division by zero
    a += 42 / i;
         ~~~^~~
andrewt@LAPTOP-5GPL0IVV:~/src/examples$

@andrewt0301
Copy link
Owner Author

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