xref: /llvm-project/clang/test/Analysis/suppression-attr.cpp (revision 017675fff116c26bef7f0a389c983c909a3141fd)
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
2 
3 namespace [[clang::suppress]]
4 suppressed_namespace {
foo()5   int foo() {
6     int *x = 0;
7     return *x;
8   }
9 
10   int foo_forward();
11 }
12 
foo_forward()13 int suppressed_namespace::foo_forward() {
14     int *x = 0;
15     return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
16 }
17 
18 // Another instance of the same namespace.
19 namespace suppressed_namespace {
bar()20   int bar() {
21     int *x = 0;
22     return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
23   }
24 }
25 
lambda()26 void lambda() {
27   [[clang::suppress]] {
28     auto lam = []() {
29       int *x = 0;
30       return *x;
31     };
32   }
33 }
34 
35 class [[clang::suppress]] SuppressedClass {
foo()36   int foo() {
37     int *x = 0;
38     return *x;
39   }
40 
41   int bar();
42 };
43 
bar()44 int SuppressedClass::bar() {
45   int *x = 0;
46   return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
47 }
48 
49 class SuppressedMethodClass {
foo()50   [[clang::suppress]] int foo() {
51     int *x = 0;
52     return *x;
53   }
54 
55   [[clang::suppress]] int bar1();
56   int bar2();
57 };
58 
bar1()59 int SuppressedMethodClass::bar1() {
60   int *x = 0;
61   return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}
62 }
63 
64 [[clang::suppress]]
bar2()65 int SuppressedMethodClass::bar2() {
66   int *x = 0;
67   return *x; // no-warning
68 }
69