brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · 2a934be Raw
117 lines · cpp
1// RUN: %clang_analyze_cc1 \2// RUN:   -analyzer-checker=core,debug.ExprInspection %s -verify3 4// These test cases demonstrate lack of Static Analyzer features.5// The FIXME: tags indicate where we expect different output.6 7// Handle constructors for default arguments.8// Default arguments in C++ are recomputed at every call,9// and are therefore local, and not static, variables.10void clang_analyzer_eval(bool);11void clang_analyzer_warnIfReached();12 13struct init_with_list {14  int a;15  init_with_list() : a(1) {}16};17 18struct init_in_body {19  int a;20  init_in_body() { a = 1; }21};22 23struct init_default_member {24  int a = 1;25};26 27struct basic_struct {28  int a;29};30 31// Top-level analyzed functions.32void top_f(init_with_list l = init_with_list()) {33  // We expect that the analyzer doesn't assume anything about the parameter.34  clang_analyzer_eval(l.a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}35}36 37void top_g(init_in_body l = init_in_body()) {38  // We expect that the analyzer doesn't assume anything about the parameter.39  clang_analyzer_eval(l.a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}40}41 42void top_h(init_default_member l = init_default_member()) {43  // We expect that the analyzer doesn't assume anything about the parameter.44  clang_analyzer_eval(l.a == 1); // expected-warning {{TRUE}} expected-warning {{FALSE}}45}46 47// Not-top-level analyzed functions.48int called_f(init_with_list l = init_with_list()) {49  // We expect that the analyzer assumes the default value50  // when called from test2().51  return l.a;52}53 54int called_g(init_in_body l = init_in_body()) {55  // We expect that the analyzer assumes the default value56  // when called from test3().57  return l.a;58}59 60int called_h(init_default_member l = init_default_member()) {61  // We expect that the analyzer assumes the default value62  // when called from test4().63  return l.a;64}65 66int called_i(const init_with_list &l = init_with_list()){67  // We expect that the analyzer assumes the default value68  // when called from test5().69  return l.a;70}71 72int called_j(init_with_list &&l = init_with_list()){73  // We expect that the analyzer assumes the default value74  // when called from test6().75  return l.a;76}77 78int plain_parameter_passing(basic_struct l) {79  return l.a;80}81 82void test1() {83  basic_struct b;84  b.a = 1;85  clang_analyzer_eval(plain_parameter_passing(b) == 1); //expected-warning {{TRUE}}86}87 88void test2() {89  // We expect that the analyzer assumes the default value.90  // FIXME: Should be TRUE.91  clang_analyzer_eval(called_f() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}92}93 94void test3() {95  // We expect that the analyzer assumes the default value.96  // FIXME: Should be TRUE.97  clang_analyzer_eval(called_g() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}98}99 100void test4() {101  // We expect that the analyzer assumes the default value.102  // FIXME: Should be TRUE.103  clang_analyzer_eval(called_h() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}104}105 106void test5() {107  //We expect that the analyzer assumes the default value.108  // FIXME: Should be TRUE.109  clang_analyzer_eval(called_i() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}110}111 112void test6() {113  // We expect that the analyzer assumes the default value.114  // FIXME: Should be TRUE.115  clang_analyzer_eval(called_j() == 1); //expected-warning {{TRUE}} expected-warning {{FALSE}}116}117