• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core,debug.ExprInspection -analyzer-store=region -verify %s
2 
3 void clang_analyzer_eval(int);
4 void clang_analyzer_warnIfReached();
5 
f(void)6 void f(void) {
7   void (*p)(void);
8   p = f;
9   p = &f;
10   p();
11   (*p)();
12 }
13 
14 void g(void (*fp)(void));
15 
f2()16 void f2() {
17   g(f);
18 }
19 
f3(void (* f)(void),void (* g)(void))20 void f3(void (*f)(void), void (*g)(void)) {
21   clang_analyzer_eval(!f); // expected-warning{{UNKNOWN}}
22   f();
23   clang_analyzer_eval(!f); // expected-warning{{FALSE}}
24 
25   clang_analyzer_eval(!g); // expected-warning{{UNKNOWN}}
26   (*g)();
27   clang_analyzer_eval(!g); // expected-warning{{FALSE}}
28 }
29 
nullFunctionPointerConstant()30 void nullFunctionPointerConstant() {
31   void (*f)(void) = 0;
32   f(); // expected-warning{{Called function pointer is null}}
33   clang_analyzer_warnIfReached(); // no-warning
34 }
35 
nullFunctionPointerConstraint(void (* f)(void))36 void nullFunctionPointerConstraint(void (*f)(void)) {
37   if (f)
38     return;
39   f(); // expected-warning{{Called function pointer is null}}
40   clang_analyzer_warnIfReached(); // no-warning
41 }
42