-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Control analysis-based diagnostics with #pragma #136323
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
Changes from 1 commit
3beecb2
e9f2cd4
17fcd1f
7e116dc
1644401
cf27e93
f561ae3
67c74fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16574,7 +16574,8 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, | |
BD->setCaptures(Context, Captures, BSI->CXXThisCaptureIndex != 0); | ||
|
||
// Pop the block scope now but keep it alive to the end of this function. | ||
AnalysisBasedWarnings::Policy WP = AnalysisWarnings.getDefaultPolicy(); | ||
AnalysisBasedWarnings::Policy WP = | ||
AnalysisWarnings.getPolicyInEffectAt(Body->getEndLoc()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Static analysis points out that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the statement EDIT: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I missed the |
||
PoppedFunctionScopePtr ScopeRAII = PopFunctionScopeInfo(&WP, BD, BlockTy); | ||
|
||
BlockExpr *Result = new (Context) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify -Werror=unreachable-code-aggressive %s | ||
|
||
// Test that analysis-based warnings honor #pragma diagnostic controls. These | ||
// diagnostics are triggered at the end of a function body, so the pragma needs | ||
// to be enabled through to the closing curly brace in order for the diagnostic | ||
// to be emitted. | ||
|
||
struct [[clang::consumable(unconsumed)]] Linear { | ||
[[clang::return_typestate(unconsumed)]] | ||
Linear() {} | ||
[[clang::callable_when(consumed)]] | ||
~Linear() {} | ||
}; | ||
|
||
int a() { | ||
Linear l; | ||
return 0; // No -Wconsumed diagnostic, analysis is not enabled. | ||
return 1; // expected-error {{'return' will never be executed}} | ||
} | ||
|
||
#pragma clang diagnostic push | ||
#pragma clang diagnostic error "-Wconsumed" | ||
int b() { | ||
Linear l; | ||
return 0; // expected-error {{invalid invocation of method '~Linear' on object 'l' while it is in the 'unconsumed' state}} | ||
return 1; // expected-error {{'return' will never be executed}} | ||
} | ||
#pragma clang diagnostic pop | ||
|
||
int c() { | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic error "-Wconsumed" | ||
Linear l; | ||
return 0; // No -Wconsumed diagnostic, analysis is disabled before the closing brace | ||
return 1; // expected-error {{'return' will never be executed}} | ||
#pragma clang diagnostic pop | ||
} | ||
|
||
int d() { | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic error "-Wconsumed" | ||
#pragma clang diagnostic ignored "-Wunreachable-code-aggressive" | ||
Linear l; | ||
return 0; // expected-error {{invalid invocation of method '~Linear' on object 'l' while it is in the 'unconsumed' state}} | ||
return 1; // Diagnostic is ignored | ||
} | ||
#pragma clang diagnostic pop | ||
|
||
int e() { | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic error "-Wconsumed" | ||
#pragma clang diagnostic ignored "-Wunreachable-code-aggressive" | ||
Linear l; | ||
return 0; | ||
return 1; | ||
// Both diagnostics are ignored because analysis is disabled before the | ||
// closing brace. | ||
#pragma clang diagnostic pop | ||
} | ||
|
||
int f() { | ||
Linear l; | ||
return 0; // No -Wconsumed diagnostic, analysis is not enabled at } so it never runs to produce the diagnostic | ||
return 1; // Diagnostic ignores because it was disabled at the } | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wunreachable-code-aggressive" | ||
} | ||
#pragma clang diagnostic pop | ||
|
||
int g() { | ||
Linear l; | ||
return 0; // No -Wconsumed diagnostic, the diagnostic generated at } is not enabled on this line. | ||
Sirraide marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return 1; // expected-error {{'return' will never be executed}} | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic warning "-Wconsumed" | ||
} | ||
#pragma clang diagnostic pop |
Uh oh!
There was an error while loading. Please reload this page.