[PATCH] D40242: Do not perform the analysis based warning if all warnings are ignored
Olivier Goffart via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 20 23:48:59 PST 2017
ogoffart updated this revision to Diff 123720.
ogoffart added a comment.
Herald added a subscriber: klimek.
I added a test.
I did not add such test before because i know that calling Reset() on the diagnostics is kind of a hack.
This change does not have any behavioral difference normally, it is just an optimization that skips the computation of the CFG if all warnings are ignored.
https://reviews.llvm.org/D40242
Files:
lib/Sema/AnalysisBasedWarnings.cpp
unittests/Tooling/ToolingTest.cpp
Index: unittests/Tooling/ToolingTest.cpp
===================================================================
--- unittests/Tooling/ToolingTest.cpp
+++ unittests/Tooling/ToolingTest.cpp
@@ -533,5 +533,31 @@
}
#endif
+TEST(runToolOnCode, TestResetDiagnostics) {
+ // This is a tool that resets the diagnostic during the compilation.
+ struct ResetDiagnosticAction : public clang::ASTFrontendAction {
+ std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &Compiler,
+ StringRef) override {
+ struct Consumer : public clang::ASTConsumer {
+ bool HandleTopLevelDecl(clang::DeclGroupRef D) override {
+ auto &Diags = (*D.begin())->getASTContext().getDiagnostics();
+ // Ignore any error
+ Diags.Reset();
+ // Disable warnings because computing the CFG might crash.
+ Diags.setIgnoreAllWarnings(true);
+ return true;
+ }
+ };
+ return llvm::make_unique<Consumer>();
+ }
+ };
+
+ // Should not crash
+ EXPECT_FALSE(
+ runToolOnCode(new ResetDiagnosticAction,
+ "struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };"
+ "void func() { long x; Foo f(x); }"));
+}
+
} // end namespace tooling
} // end namespace clang
Index: lib/Sema/AnalysisBasedWarnings.cpp
===================================================================
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -2080,10 +2080,10 @@
// time.
DiagnosticsEngine &Diags = S.getDiagnostics();
- // Do not do any analysis for declarations in system headers if we are
- // going to just ignore them.
- if (Diags.getSuppressSystemWarnings() &&
- S.SourceMgr.isInSystemHeader(D->getLocation()))
+ // Do not do any analysis if we are going to just ignore them.
+ if (Diags.getIgnoreAllWarnings() ||
+ (Diags.getSuppressSystemWarnings() &&
+ S.SourceMgr.isInSystemHeader(D->getLocation())))
return;
// For code in dependent contexts, we'll do this at instantiation time.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40242.123720.patch
Type: text/x-patch
Size: 2092 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171121/b1be299e/attachment.bin>
More information about the cfe-commits
mailing list