-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[analyzer] Retry UNDEF Z3 queries 2 times by default #120239
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
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f7041f5
[analyzer] Retry UNDEF Z3 queries at most "crosscheck-with-z3-retries…
steakhal 7dc6f31
Use zero-based raw for-loop for counting the Z3 attempts
steakhal 06c4184
Make the analysis option a Positive value
steakhal 930b2a8
Fix off-by-one error in loop condition
steakhal 9a9c112
Uplift test to match the new name of the flag; test added semantics
steakhal 23a1654
Update stale comment
steakhal a65ac8b
Relax the AnalyzerOptions.def include check
steakhal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Check the default config. | ||
| // RUN: %clang_analyze_cc1 -analyzer-checker=debug.ConfigDumper 2>&1 \ | ||
| // RUN: | FileCheck %s --match-full-lines | ||
| // CHECK: crosscheck-with-z3-max-attempts-per-query = 3 | ||
|
|
||
| // RUN: rm -rf %t && mkdir %t | ||
| // RUN: %host_cxx -shared -fPIC \ | ||
| // RUN: %S/z3/Inputs/MockZ3_solver_check.cpp \ | ||
| // RUN: -o %t/MockZ3_solver_check.so | ||
|
|
||
| // DEFINE: %{mocked_clang} = \ | ||
| // DEFINE: LD_PRELOAD="%t/MockZ3_solver_check.so" \ | ||
| // DEFINE: %clang_cc1 %s -analyze -setup-static-analyzer \ | ||
| // DEFINE: -analyzer-config crosscheck-with-z3=true \ | ||
| // DEFINE: -analyzer-checker=core | ||
|
|
||
| // DEFINE: %{retry} = -analyzer-config crosscheck-with-z3-max-attempts-per-query | ||
|
|
||
| // RUN: Z3_SOLVER_RESULTS="UNDEF" %{mocked_clang} %{retry}=0 -verify=refuted | ||
| // RUN: Z3_SOLVER_RESULTS="UNSAT" %{mocked_clang} %{retry}=0 -verify=refuted | ||
| // RUN: Z3_SOLVER_RESULTS="SAT" %{mocked_clang} %{retry}=0 -verify=accepted | ||
|
|
||
| // RUN: Z3_SOLVER_RESULTS="UNDEF,UNDEF" %{mocked_clang} %{retry}=1 -verify=refuted | ||
| // RUN: Z3_SOLVER_RESULTS="UNDEF,UNSAT" %{mocked_clang} %{retry}=1 -verify=refuted | ||
| // RUN: Z3_SOLVER_RESULTS="UNDEF,SAT" %{mocked_clang} %{retry}=1 -verify=accepted | ||
|
|
||
| // RUN: Z3_SOLVER_RESULTS="UNDEF,UNDEF,UNDEF" %{mocked_clang} %{retry}=2 -verify=refuted | ||
| // RUN: Z3_SOLVER_RESULTS="UNDEF,UNDEF,UNSAT" %{mocked_clang} %{retry}=2 -verify=refuted | ||
| // RUN: Z3_SOLVER_RESULTS="UNDEF,UNDEF,SAT" %{mocked_clang} %{retry}=2 -verify=accepted | ||
|
|
||
|
|
||
| // REQUIRES: z3, asserts, shell, system-linux | ||
|
|
||
| // refuted-no-diagnostics | ||
|
|
||
| int div_by_zero_test(int b) { | ||
| if (b) {} | ||
| return 100 / b; // accepted-warning {{Division by zero}} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #include <cassert> | ||
| #include <dlfcn.h> | ||
| #include <cstdio> | ||
| #include <cstdlib> | ||
| #include <cstring> | ||
|
|
||
| #include <z3.h> | ||
|
|
||
| static char *Z3ResultsBegin; | ||
| static char *Z3ResultsCursor; | ||
|
|
||
| static __attribute__((constructor)) void init() { | ||
| const char *Env = getenv("Z3_SOLVER_RESULTS"); | ||
| if (!Env) { | ||
| fprintf(stderr, "Z3_SOLVER_RESULTS envvar must be defined; abort\n"); | ||
| abort(); | ||
| } | ||
| Z3ResultsBegin = strdup(Env); | ||
| Z3ResultsCursor = Z3ResultsBegin; | ||
| if (!Z3ResultsBegin) { | ||
| fprintf(stderr, "strdup failed; abort\n"); | ||
| abort(); | ||
| } | ||
| } | ||
|
|
||
| static __attribute__((destructor)) void finit() { | ||
| if (strlen(Z3ResultsCursor) > 0) { | ||
| fprintf(stderr, "Z3_SOLVER_RESULTS should have been completely consumed " | ||
| "by the end of the test; abort\n"); | ||
| abort(); | ||
| } | ||
| free(Z3ResultsBegin); | ||
| } | ||
|
|
||
| static bool consume_token(char **pointer_to_cursor, const char *token) { | ||
| assert(pointer_to_cursor); | ||
| int len = strlen(token); | ||
| if (*pointer_to_cursor && strncmp(*pointer_to_cursor, token, len) == 0) { | ||
| *pointer_to_cursor += len; | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| Z3_lbool Z3_API Z3_solver_check(Z3_context c, Z3_solver s) { | ||
| consume_token(&Z3ResultsCursor, ","); | ||
|
|
||
| if (consume_token(&Z3ResultsCursor, "UNDEF")) { | ||
| printf("Z3_solver_check returns UNDEF\n"); | ||
| return Z3_L_UNDEF; | ||
| } | ||
| if (consume_token(&Z3ResultsCursor, "SAT")) { | ||
| printf("Z3_solver_check returns SAT\n"); | ||
| return Z3_L_TRUE; | ||
| } | ||
| if (consume_token(&Z3ResultsCursor, "UNSAT")) { | ||
| printf("Z3_solver_check returns UNSAT\n"); | ||
| return Z3_L_FALSE; | ||
| } | ||
| fprintf(stderr, "Z3_SOLVER_RESULTS was exhausted; abort\n"); | ||
| abort(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.