From fb4afc2fc659faff43a6df4c1d0e07df9c90479d Mon Sep 17 00:00:00 2001 From: DeLesley Hutchins Date: Wed, 5 Dec 2012 00:06:15 +0000 Subject: [PATCH] Thread safety analysis: Add a new "beta" warning flag: -Wthread-safety-beta. As the analysis improves, it will continue to add new warnings that are potentially disruptive to existing users. From now on, such warnings will first be introduced under the "beta" flag. Such warnings are not turned on by default; their purpose is to allow users to test their code against future planned changes, before those changes are actually made. After a suitable migration period, beta warnings will be folded into the standard -Wthread-safety. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169338 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Analysis/Analyses/ThreadSafety.h | 7 +++++++ include/clang/Basic/DiagnosticGroups.td | 1 + include/clang/Basic/DiagnosticSemaKinds.td | 4 ++++ lib/Sema/AnalysisBasedWarnings.cpp | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/include/clang/Analysis/Analyses/ThreadSafety.h b/include/clang/Analysis/Analyses/ThreadSafety.h index ef6b821e39..f7f12d4820 100644 --- a/include/clang/Analysis/Analyses/ThreadSafety.h +++ b/include/clang/Analysis/Analyses/ThreadSafety.h @@ -68,6 +68,7 @@ enum LockErrorKind { class ThreadSafetyHandler { public: typedef llvm::StringRef Name; + ThreadSafetyHandler() : IssueBetaWarnings(false) { } virtual ~ThreadSafetyHandler(); /// Warn about lock expressions which fail to resolve to lockable objects. @@ -143,6 +144,12 @@ public: /// \param Loc -- The location of the function call. virtual void handleFunExcludesLock(Name FunName, Name LockName, SourceLocation Loc) {} + + bool issueBetaWarnings() { return IssueBetaWarnings; } + void setIssueBetaWarnings(bool b) { IssueBetaWarnings = b; } + +private: + bool IssueBetaWarnings; }; /// \brief Check a function's CFG for thread-safety violations. diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index cae627ed23..edfaa102e2 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -406,6 +406,7 @@ def ThreadSafety : DiagGroup<"thread-safety", [ThreadSafetyAttributes, ThreadSafetyAnalysis, ThreadSafetyPrecise]>; +def ThreadSafetyBeta : DiagGroup<"thread-safety-beta">; // Note that putting warnings in -Wall will not disable them by default. If a // warning should be active _only_ when -Wall is passed in, mark it as diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 18874b603f..99936ff861 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1939,6 +1939,10 @@ def warn_fun_requires_lock_precise : Warning< InGroup, DefaultIgnore; def note_found_mutex_near_match : Note<"found near match '%0'">; +// Dummy warning that will trigger "beta" warnings from the analysis if enabled. +def warn_thread_safety_beta : Warning< + "Thread safety beta warning.">, InGroup, DefaultIgnore; + def warn_impcast_vector_scalar : Warning< "implicit conversion turns vector to scalar: %0 to %1">, InGroup>, DefaultIgnore; diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 4a13ffa8e3..20f0fd8eef 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -1544,6 +1544,10 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, SourceLocation FL = AC.getDecl()->getLocation(); SourceLocation FEL = AC.getDecl()->getLocEnd(); thread_safety::ThreadSafetyReporter Reporter(S, FL, FEL); + if (Diags.getDiagnosticLevel(diag::warn_thread_safety_beta,D->getLocStart()) + != DiagnosticsEngine::Ignored) + Reporter.setIssueBetaWarnings(true); + thread_safety::runThreadSafetyAnalysis(AC, Reporter); Reporter.emitDiagnostics(); } -- 2.40.0