-
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 all commits
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 |
---|---|---|
|
@@ -16597,7 +16597,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,83 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify -Werror=unreachable-code-aggressive %s | ||
|
||
// Test that analysis-based warnings honor #pragma diagnostic controls. | ||
|
||
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; // 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 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; // 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 f() { | ||
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 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 | ||
|
||
int h() { | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic error "-Wconsumed" | ||
#pragma clang diagnostic ignored "-Wunreachable-code-aggressive" | ||
#pragma clang diagnostic pop | ||
|
||
Linear l; | ||
return 0; // No -Wconsumed diagnostic, the diagnostic generated at } is not enabled on this line. | ||
return 1; // expected-error {{'return' will never be executed}} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests show this working but.... where on earth are these set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overrides are set in
SemaPPCallback::PragmaDiagnostic()
, the others come fromAnalysisBasedWarnings::getPolicyInEffectAt()