brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · 29a96c0 Raw
78 lines · cpp
1// RUN: %clang_analyze_cc1 -std=c++11 -verify %s \2// RUN:   -triple=x86_64-unknown-linux-gnu \3// RUN:   -analyzer-checker=core,security.ArrayBound,debug.ExprInspection4 5void clang_analyzer_eval(bool);6void clang_analyzer_value(int);7void clang_analyzer_dump(int);8 9// From: https://github.com/llvm/llvm-project/issues/10076210extern int arrOf10[10];11void using_builtin(int x) {12  __builtin_assume(x > 101); // CallExpr13  arrOf10[x] = 404; // expected-warning {{Out of bound access to memory}}14}15 16void using_assume_attr(int ax) {17  [[assume(ax > 100)]]; // NullStmt with an "assume" attribute.18  arrOf10[ax] = 405; // expected-warning {{Out of bound access to memory}}19}20 21void using_many_assume_attr(int yx) {22  [[assume(yx > 104), assume(yx > 200), assume(yx < 300)]]; // NullStmt with an attribute23  arrOf10[yx] = 406; // expected-warning{{Out of bound access to memory}}24}25 26int using_assume_attr_has_no_sideeffects(int y) {27  int orig_y = y;28  clang_analyzer_value(y);      // expected-warning {{32s:{ [-2147483648, 2147483647] }}}29  clang_analyzer_value(orig_y); // expected-warning {{32s:{ [-2147483648, 2147483647] }}}30  clang_analyzer_dump(y);       // expected-warning-re {{{{^}}reg_${{[0-9]+}}<int y> [debug.ExprInspection]{{$}}}}31  clang_analyzer_dump(orig_y);  // expected-warning-re {{{{^}}reg_${{[0-9]+}}<int y> [debug.ExprInspection]{{$}}}}32 33  // We should not apply sideeffects of the argument of [[assume(...)]].34  // "y" should not get incremented;35  [[assume(++y == 43)]]; // expected-warning {{assumption is ignored because it contains (potential) side-effects}}36 37  clang_analyzer_dump(y);       // expected-warning-re {{{{^}}reg_${{[0-9]+}}<int y> [debug.ExprInspection]{{$}}}}38  clang_analyzer_dump(orig_y);  // expected-warning-re {{{{^}}reg_${{[0-9]+}}<int y> [debug.ExprInspection]{{$}}}}39  clang_analyzer_value(y);      // expected-warning {{32s:{ [-2147483648, 2147483647] }}}40  clang_analyzer_value(orig_y); // expected-warning {{32s:{ [-2147483648, 2147483647] }}}41  clang_analyzer_eval(y == orig_y); // expected-warning {{TRUE}} Good.42 43  return y;44}45 46int using_builtin_assume_has_no_sideeffects(int y) {47  int orig_y = y;48  clang_analyzer_value(y);      // expected-warning {{32s:{ [-2147483648, 2147483647] }}}49  clang_analyzer_value(orig_y); // expected-warning {{32s:{ [-2147483648, 2147483647] }}}50  clang_analyzer_dump(y);       // expected-warning-re {{{{^}}reg_${{[0-9]+}}<int y> [debug.ExprInspection]{{$}}}}51  clang_analyzer_dump(orig_y);  // expected-warning-re {{{{^}}reg_${{[0-9]+}}<int y> [debug.ExprInspection]{{$}}}}52 53  // We should not apply sideeffects of the argument of __builtin_assume(...)54  // "u" should not get incremented;55  __builtin_assume(++y == 43); // expected-warning {{assumption is ignored because it contains (potential) side-effects}}56 57  clang_analyzer_dump(y);       // expected-warning-re {{{{^}}reg_${{[0-9]+}}<int y> [debug.ExprInspection]{{$}}}}58  clang_analyzer_dump(orig_y);  // expected-warning-re {{{{^}}reg_${{[0-9]+}}<int y> [debug.ExprInspection]{{$}}}}59  clang_analyzer_value(y);      // expected-warning {{32s:{ [-2147483648, 2147483647] }}}60  clang_analyzer_value(orig_y); // expected-warning {{32s:{ [-2147483648, 2147483647] }}}61  clang_analyzer_eval(y == orig_y); // expected-warning {{TRUE}} Good.62 63  return y;64}65 66template <int ...args>67bool issue151529() {68  // no-crash69  [[assume((true))]]; 70  // no-crash71  [[assume(((args >= 0) && ...))]];  // expected-warning {{pack fold expression is a C++17 extension}}72  return ((args >= 0) && ...); // expected-warning {{pack fold expression is a C++17 extension}}73}74 75void instantiate_issue151529() {76  issue151529<0>();77}78