[cfe-dev] [StaticAnalyzer]: Cant get my checker to output
Anna Zaks
ganna at apple.com
Wed Sep 28 22:55:13 PDT 2011
Hi Arjun,
The reason why the callback is not called is that IfStmt is not a CFGElement - it's a CFGTerminator (it expresses only control flow). See the CFG block dump below. We only call checkPostStmt/checkPreStmt for statements that correspond to CFG elements.
If you want to visit the conditions within the if statements (or other branches), use checkBranchCondition() instead.
Cheers,
Anna.
[ B3 ]
1: foo
2: [B3.1]
3: [B3.2]()
4: int a = foo();
5: foo
6: [B3.5]
7: [B3.6]()
8: int b = foo();
9: a
10: &[B3.9]
11: "%d"
12: [B3.11]
13: [B3.12]
14: scanf
15: [B3.14]
16: [B3.15]([B3.13], [B3.10])
17: a
18: [B3.17]
19: b
20: [B3.19]
21: [B3.18] + [B3.20]
22: a
23: [B3.22] = [B3.21]
24: a
25: [B3.24]
26: 2
27: [B3.25] == [B3.26]
T: if [B3.27]
Predecessors (1): B4
Successors (2): B2 B1
On Sep 28, 2011, at 9:03 PM, Arjun Singri wrote:
> My checker was able to output (the debug messages show up) when I changed the IfStmt to BinaryOperator. So my checker has been registered correctly. It is not able to deal with IfStmt for some reason.
>
> Here is the code I am trying to analyze:
>
> #include<stdio.h>
>
> int foo() { return 2; }
>
> int main(void)
> {
> int a = foo();
> int b = foo();
>
> scanf("%d", &a);
>
> a = a + b;
> if (a == 2)
> {
> a = 4;
> }
>
> printf("%d", a);
>
> return 0;
> }
>
>
>
>
> On Wed, Sep 28, 2011 at 7:54 PM, Jim Goodnow II <Jim at thegoodnows.net> wrote:
> Hi Arjun,
>
> Do you have a short example of the code that you are analyzing. It is
> possible that the static analyzer has determined that the if statement
> is in a path that never gets executed. It should still be in the AST
> though. You can use -ast-dump to look at the AST directly.
>
> - jim
>
> On 9/28/2011 7:40 PM, John McCall wrote:
> > On Sep 28, 2011, at 7:34 PM, funceval wrote:
> >> Not even constant folding and constant propagation?
> > Correct. A few places in the AST, like array dimensions, do compute and store the value of a constant expression, but only in unevaluated contexts, and the original source information is never thrown away.
> >
> > John.
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> >
> >
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110928/fc740094/attachment.html>
More information about the cfe-dev
mailing list