[cfe-dev] [analyzer] Pruning path diagnostic notes

Artem Dergachev via cfe-dev cfe-dev at lists.llvm.org
Sun Jun 21 01:57:35 PDT 2020


No, there's no API for that; you'll have to patch BugReporter from the 
inside to make this happen.


 > Even disregarding the question of whether the criterion that I 
mentioned for discarding path notes is possible

This problem is not checker-specific and it's indeed a fairly hard 
theoretical problem in general; we have some ideas but we don't have a 
generic solution in mind. Extra notes are annoying and potentially 
confusing but they're technically correct so it's not too bad.

Say, if your code would have been slightly different:

void f() {
   int foo = 2;

   if (!someResult())
     return;

   if (otherResult())
     foo = 3;

   neverCallThisAPIWith3(foo);
}

Then you'd definitely want to keep the note about otherResult() but not 
probably still drop the note about someResult().

Another example:

void f() {
   bool bar = false;
   if (!someResult())
     bar = true;

   int foo = 2;
   if (bar)
     foo = 3;

   neverCallThisAPIWith3(foo);
}

In this case you'd want most likely want to keep the entire path even 
though foo wasn't even declared at the first note.

On 6/21/20 6:13 AM, via cfe-dev wrote:
> Hi list,
>
> Is there any way to get a BugReporterVisitor to delete path diagnostic 
> notes that occur at program points that my plugin doesn't consider 
> interesting?
>
> For example,
>
> void f() {
>   if (!someResult())
>     return;
>   if (!otherResult())
>     return;
>   int foo = 3;
>   neverCallThisAPIWith3(foo);
> }
>
> If I am checking that neverCallThisAPIWith3() is never called with 3, 
> then in this case there are a lot of irrelevant path diagnostic notes 
> due to the early returns. (e.g. we always see "note: Taking false 
> branch" on the if-statements, but if we took the true branch on either 
> of them, then we wouldn't get to the 'foo' part.) Really what I want 
> to show in my diagnostic is notes that concern the value of variable 
> 'foo'. If possible, I'd like to prune the notes that distinguish the 
> path from other paths where 'foo' is never even declared.
>
> Is this possible? I don't see any method in the docs to delete a note 
> from a BugReport, in the first place. (Even disregarding the question 
> of whether the criterion that I mentioned for discarding path notes is 
> possible)
>
> Cheers,
> -- 
> Philip C
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200621/c5370c44/attachment-0001.html>


More information about the cfe-dev mailing list