[cfe-dev] [Analyzer - UnreachableCodeChecker] Why analyzer suppress the warnings coming from macro?
Artem Dergachev via cfe-dev
cfe-dev at lists.llvm.org
Mon Sep 4 06:42:14 PDT 2017
I strongly believe that your heuristic would be very hard to implement.
Also the analyzer's symbolic execution engine would be totally
unhelpful. Recall that there is no AST constructed for macro bodies, and
they don't even need to be valid code - until they're expanded. For
example, in the body of your MACRO(), "cond" within "if ()" doesn't have
any meaningful type assigned to it, or declared anywhere.
So you may have to compile incorrect parts of the program, probably
merge them back into the old AST one way or another, and prove that
after any such recompile, the code that would be produced by a certain
portion of the macro body would be dead. I believe such facility would
be extremely hard to construct, and not worth the effort if all we want
is to find a few weird macros.
On 9/4/17 6:29 AM, Wong Henry via cfe-dev wrote:
> Hi all,
> I have some questions about UnreachableCodeChecker. It seems that
> UnreachableCodeChecker suppresses some dead code warnings coming from
> macros.
> Given the below code sippet:
> -------------------------------------------------
> 1 #include <stdio.h>
> 2 #define MACRO(cond) \
> 3 if (cond) { printf("dead code\n"); } <---- dead code
> 4
> 5 void foo()
> 6 {
> 7 MACRO(0)
> 8 }
> -------------------------------------------------
> It is reasonable to suppress the dead code warning in the above code
> sample. But it is unreasonable to suppress some other dead code warnings.
> For example:
> -------------------------------------------------
> 1 #include <stdio.h>
> 2 #define MACRO(cond) \
> 3 if (0) { printf("dead code\n"); } <---- dead code
> 4
> 5 void foo()
> 6 {
> 7 MACRO(0)
> 8 }
> -------------------------------------------------
> No matter what 'cond' is, the 'printf' is always unreachable. So I
> have the following two questions:
> (1) What caused UnreachableCodeChecker to be designed like that?
> (2) If I want to make some improvements, what kind of work should I
> do, for example, only suppress dead code warnings that depend on macro
> arguments and suppresses common patterns in macros like 'do {...}
> while (0)'.
>
> Cheers,
> Henry Wong
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list