brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · e05f522 Raw
81 lines · c
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix,debug.ExprInspection \2// RUN:    -verify -analyzer-config eagerly-assume=false -std=c99 %s \3// RUN:    -Wno-implicit-function-declaration4 5int printf(const char *restrict,...);6 7void clang_analyzer_eval(int);8void clang_analyzer_dump(int*);9 10// Testing core functionality of the region store.11int compoundLiteralTest(void) {12    int index = 0;13    for (index = 0; index < 2; index++) {14        int thing = (int []){0, 1}[index];15        printf("thing: %i\n", thing);16    }17    return 0;18}19 20int compoundLiteralTest2(void) {21    int index = 0;22    for (index = 0; index < 3; index++) {23        int thing = (int [][3]){{0,0,0}, {1,1,1}, {2,2,2}}[index][index];24        printf("thing: %i\n", thing);25    }26    return 0;27}28 29int concreteOffsetBindingIsInvalidatedBySymbolicOffsetAssignment(int length,30                                                                 int i) {31  int values[length];32  values[i] = 4;33  return values[0]; // no-warning34}35 36struct X{37  int mem;38};39int initStruct(struct X *st);40int structOffsetBindingIsInvalidated(int length, int i){41  struct X l;42  initStruct(&l);43  return l.mem; // no-warning44}45 46void testConstraintOnRegionOffset(int *values, int length, int i){47  if (values[1] == 4) {48    values[i] = 5;49    clang_analyzer_eval(values[1] == 4);// expected-warning {{UNKNOWN}}50  }51}52 53int initArray(int *values);54void testConstraintOnRegionOffsetStack(int *values, int length, int i) {55  if (values[0] == 4) {56    initArray(values);57    clang_analyzer_eval(values[0] == 4);// expected-warning {{UNKNOWN}}58  }59}60 61int buffer[10];62void b(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C23, conflicting with a subsequent definition}}63void missingPrototypeCallsiteMatchingArgsAndParams() {64  // expected-warning@+1 {{passing arguments to 'b' without a prototype is deprecated in all versions of C and is not supported in C23}}65  b(&buffer);66}67void b(int *c) { // expected-note {{conflicting prototype is here}}68  clang_analyzer_dump(c); // expected-warning {{&Element{buffer,0 S64b,int}}}69  *c = 42; // no-crash70}71 72void c(); // expected-warning {{a function declaration without a prototype is deprecated in all versions of C and is treated as a zero-parameter prototype in C23, conflicting with a subsequent definition}}73void missingPrototypeCallsiteMismatchingArgsAndParams() {74  // expected-warning@+1 {{passing arguments to 'c' without a prototype is deprecated in all versions of C and is not supported in C23}}75  c(&buffer, &buffer);76}77void c(int *c) { // expected-note {{conflicting prototype is here}}78  clang_analyzer_dump(c); // expected-warning {{Unknown}}79  *c = 42; // no-crash80}81