forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[analyzer] Avoid out-of-order node traversal on void return (llvm#117863
) The motivating example: https://compiler-explorer.com/z/WjsxYfs43 ```C++ #include <stdlib.h> void inf_loop_break_callee() { void* data = malloc(10); while (1) { (void)data; // line 3 break; // -> execution continues on line 3 ?!! } } ``` To correct the flow steps in this example (see the fixed version in the added test case) I changed two things in the engine: - Make `processCallExit` create a new StmtPoint only for return statements. If the last non-jump statement is not a return statement, e.g. `(void)data;`, it is no longer inserted in the exploded graph after the function exit. - Skip the purge program points. In the example above, purge points are still inserted after the `break;` executes. Now, when the bug reporter is looking for the next statement executed after the function execution is finished, it will ignore the purge program points, so it won't confusingly pick the `(void)data;` statement. CPP-5778
- Loading branch information
Showing
6 changed files
with
67 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,26 @@ | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc -analyzer-output text -verify %s | ||
|
||
typedef __typeof(sizeof(int)) size_t; | ||
void *malloc(size_t size); | ||
|
||
void inf_loop_break_callee() { | ||
void* data = malloc(10); // expected-note{{Memory is allocated}} | ||
while (1) { // expected-note{{Loop condition is true}} | ||
(void)data; | ||
break; // No note that we jump to the line above from this break | ||
} // expected-note@-1{{Execution jumps to the end of the function}} | ||
} // expected-warning{{Potential leak of memory pointed to by 'data'}} | ||
// expected-note@-1 {{Potential leak of memory pointed to by 'data'}} | ||
|
||
void inf_loop_break_caller() { | ||
inf_loop_break_callee(); // expected-note{{Calling 'inf_loop_break_callee'}} | ||
} | ||
|
||
void inf_loop_break_top() { | ||
void* data = malloc(10); // expected-note{{Memory is allocated}} | ||
while (1) { // expected-note{{Loop condition is true}} | ||
(void)data; | ||
break; // No note that we jump to the line above from this break | ||
} // expected-note@-1{{Execution jumps to the end of the function}} | ||
} // expected-warning{{Potential leak of memory pointed to by 'data'}} | ||
// expected-note@-1 {{Potential leak of memory pointed to by 'data'}} |