brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 9ba56d9 Raw
92 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s2 3void clang_analyzer_warnIfReached();4 5struct Clazz {6  template <typename T>7  static void templated_memfn();8};9 10// This must come before the 'templated_memfn' is defined!11static void instantiate() {12  Clazz::templated_memfn<int>();13}14 15template <typename T>16void Clazz::templated_memfn() {17  // When we report a bug in a function, we traverse the lexical decl context18  // of it while looking for suppression attributes to record what source19  // ranges should the suppression apply to.20  // In the past, that traversal didn't follow template instantiations, only21  // primary templates.22  [[clang::suppress]] clang_analyzer_warnIfReached(); // no-warning23 24}25 26namespace [[clang::suppress]]27suppressed_namespace {28  int foo() {29    int *x = 0;30    return *x;31  }32 33  int foo_forward();34}35 36int suppressed_namespace::foo_forward() {37    int *x = 0;38    return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}39}40 41// Another instance of the same namespace.42namespace suppressed_namespace {43  int bar() {44    int *x = 0;45    return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}46  }47}48 49void lambda() {50  [[clang::suppress]] {51    auto lam = []() {52      int *x = 0;53      return *x;54    };55  }56}57 58class [[clang::suppress]] SuppressedClass {59  int foo() {60    int *x = 0;61    return *x;62  }63 64  int bar();65};66 67int SuppressedClass::bar() {68  int *x = 0;69  return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}70}71 72class SuppressedMethodClass {73  [[clang::suppress]] int foo() {74    int *x = 0;75    return *x;76  }77 78  [[clang::suppress]] int bar1();79  int bar2();80};81 82int SuppressedMethodClass::bar1() {83  int *x = 0;84  return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}}85}86 87[[clang::suppress]]88int SuppressedMethodClass::bar2() {89  int *x = 0;90  return *x; // no-warning91}92