@@ -2492,9 +2492,11 @@ class sema::AnalysisBasedWarnings::InterProceduralData {
24922492 CalledOnceInterProceduralData CalledOnceData;
24932493};
24942494
2495- static unsigned isEnabled (DiagnosticsEngine &D, unsigned diag) {
2496- return (unsigned )!D.isIgnored (diag, SourceLocation ());
2497- }
2495+ template <typename ... Ts>
2496+ static bool areAnyEnabled (DiagnosticsEngine &D, SourceLocation Loc,
2497+ Ts... Diags) {
2498+ return (!D.isIgnored (Diags, Loc) || ...);
2499+ };
24982500
24992501sema::AnalysisBasedWarnings::AnalysisBasedWarnings (Sema &s)
25002502 : S(s), IPData(std::make_unique<InterProceduralData>()),
@@ -2503,23 +2505,37 @@ sema::AnalysisBasedWarnings::AnalysisBasedWarnings(Sema &s)
25032505 NumUninitAnalysisVariables(0 ), MaxUninitAnalysisVariablesPerFunction(0 ),
25042506 NumUninitAnalysisBlockVisits(0 ),
25052507 MaxUninitAnalysisBlockVisitsPerFunction(0 ) {
2508+ }
2509+
2510+ // We need this here for unique_ptr with forward declared class.
2511+ sema::AnalysisBasedWarnings::~AnalysisBasedWarnings () = default ;
25062512
2513+ sema::AnalysisBasedWarnings::Policy
2514+ sema::AnalysisBasedWarnings::getPolicyInEffectAt (SourceLocation Loc) {
25072515 using namespace diag ;
25082516 DiagnosticsEngine &D = S.getDiagnostics ();
2517+ Policy P;
25092518
2510- DefaultPolicy.enableCheckUnreachable =
2511- isEnabled (D, warn_unreachable) || isEnabled (D, warn_unreachable_break) ||
2512- isEnabled (D, warn_unreachable_return) ||
2513- isEnabled (D, warn_unreachable_loop_increment);
2519+ // Note: The enabled checks should be kept in sync with the switch in
2520+ // SemaPPCallbacks::PragmaDiagnostic().
2521+ P.enableCheckUnreachable =
2522+ PolicyOverrides.enableCheckUnreachable ||
2523+ areAnyEnabled (D, Loc, warn_unreachable, warn_unreachable_break,
2524+ warn_unreachable_return, warn_unreachable_loop_increment);
25142525
2515- DefaultPolicy.enableThreadSafetyAnalysis = isEnabled (D, warn_double_lock);
2526+ P.enableThreadSafetyAnalysis = PolicyOverrides.enableThreadSafetyAnalysis ||
2527+ areAnyEnabled (D, Loc, warn_double_lock);
25162528
2517- DefaultPolicy.enableConsumedAnalysis =
2518- isEnabled (D, warn_use_in_invalid_state);
2529+ P.enableConsumedAnalysis = PolicyOverrides.enableConsumedAnalysis ||
2530+ areAnyEnabled (D, Loc, warn_use_in_invalid_state);
2531+ return P;
25192532}
25202533
2521- // We need this here for unique_ptr with forward declared class.
2522- sema::AnalysisBasedWarnings::~AnalysisBasedWarnings () = default ;
2534+ void sema::AnalysisBasedWarnings::clearOverrides () {
2535+ PolicyOverrides.enableCheckUnreachable = false ;
2536+ PolicyOverrides.enableConsumedAnalysis = false ;
2537+ PolicyOverrides.enableThreadSafetyAnalysis = false ;
2538+ }
25232539
25242540static void flushDiagnostics (Sema &S, const sema::FunctionScopeInfo *fscope) {
25252541 for (const auto &D : fscope->PossiblyUnreachableDiags )
@@ -2870,6 +2886,9 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
28702886 AC.getCFG ();
28712887 }
28722888
2889+ // Clear any of our policy overrides.
2890+ clearOverrides ();
2891+
28732892 // Collect statistics about the CFG if it was built.
28742893 if (S.CollectStats && AC.isCFGBuilt ()) {
28752894 ++NumFunctionsAnalyzed;
0 commit comments