================
@@ -202,6 +202,43 @@ class SemaPPCallbacks : public PPCallbacks {
       break;
     }
   }
+  void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace,
+                        diag::Severity Mapping, StringRef Str) override {
+    // If one of the analysis-based diagnostics was enabled while processing
+    // a function, we want to note it in the analysis-based warnings so they
+    // can be run at the end of the function body even if the analysis warnings
+    // are disabled at that point.
+    SmallVector<diag::kind, 256> GroupDiags;
+    diag::Flavor Flavor =
+        Str[1] == 'W' ? diag::Flavor::WarningOrError : diag::Flavor::Remark;
+    StringRef Group = Str.substr(2);
+
+    if (S->PP.getDiagnostics().getDiagnosticIDs()->getDiagnosticsInGroup(
+            Flavor, Group, GroupDiags))
+      return;
+
+    for (diag::kind K : GroupDiags) {
+      // Note: the cases in this switch should be kept in sync with the
+      // diagnostics in AnalysisBasedWarnings::getPolicyInEffectAt().
+      AnalysisBasedWarnings::Policy &Override =
+          S->AnalysisWarnings.getPolicyOverrides();
+      switch (K) {
+      default: break;
----------------
AaronBallman wrote:

> So every new analysis-based warning needs to be added to this list right? 

Correct, but thankfully we don't add those very often.

> How weird are the consequences of forgetting it?

If you add it to AnalysisBasedDiagnostics.cpp and not to Sema.cpp, the analysis 
will work everywhere except for pragma regions like this. If you add it to 
Sema.cpp but not AnalysisBasicDiagnostics.cpp, the only time the analysis will 
work will be within pragma regions. So either is weird, but one seems more 
likely to slip through the cracks than the other.

> It might be a good idea to make a unified list of analysis-based warnings. 
> (Or like, make it a flag in Diagnostic...Kinds.td.) 

Yeah, it would be nice if this could be tablegenned. But there are so few 
analysis-based warnings and there's no good mechanism to know when you forget 
to add the correct marking to the .td file that I can think of so far.

> Probably out of scope for this patch.

Yeah, I'd prefer to punt on that. :-)

https://github.com/llvm/llvm-project/pull/136323
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to