File: region-store.c

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (80 lines) | stat: -rw-r--r-- 2,774 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix,debug.ExprInspection \
// RUN:    -verify -analyzer-config eagerly-assume=false -std=c99 %s \
// RUN:    -Wno-implicit-function-declaration

int printf(const char *restrict,...);

void clang_analyzer_eval(int);
void clang_analyzer_dump(int*);

// Testing core functionality of the region store.
int compoundLiteralTest(void) {
    int index = 0;
    for (index = 0; index < 2; index++) {
        int thing = (int []){0, 1}[index];
        printf("thing: %i\n", thing);
    }
    return 0;
}

int compoundLiteralTest2(void) {
    int index = 0;
    for (index = 0; index < 3; index++) {
        int thing = (int [][3]){{0,0,0}, {1,1,1}, {2,2,2}}[index][index];
        printf("thing: %i\n", thing);
    }
    return 0;
}

int concreteOffsetBindingIsInvalidatedBySymbolicOffsetAssignment(int length,
                                                                 int i) {
  int values[length];
  values[i] = 4;
  return values[0]; // no-warning
}

struct X{
  int mem;
};
int initStruct(struct X *st);
int structOffsetBindingIsInvalidated(int length, int i){
  struct X l;
  initStruct(&l);
  return l.mem; // no-warning
}

void testConstraintOnRegionOffset(int *values, int length, int i){
  if (values[1] == 4) {
    values[i] = 5;
    clang_analyzer_eval(values[1] == 4);// expected-warning {{UNKNOWN}}
  }
}

int initArray(int *values);
void testConstraintOnRegionOffsetStack(int *values, int length, int i) {
  if (values[0] == 4) {
    initArray(values);
    clang_analyzer_eval(values[0] == 4);// expected-warning {{UNKNOWN}}
  }
}

int buffer[10];
void 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}}
void missingPrototypeCallsiteMatchingArgsAndParams() {
  // expected-warning@+1 {{passing arguments to 'b' without a prototype is deprecated in all versions of C and is not supported in C23}}
  b(&buffer);
}
void b(int *c) { // expected-note {{conflicting prototype is here}}
  clang_analyzer_dump(c); // expected-warning {{&Element{buffer,0 S64b,int}}}
  *c = 42; // no-crash
}

void 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}}
void missingPrototypeCallsiteMismatchingArgsAndParams() {
  // expected-warning@+1 {{passing arguments to 'c' without a prototype is deprecated in all versions of C and is not supported in C23}}
  c(&buffer, &buffer);
}
void c(int *c) { // expected-note {{conflicting prototype is here}}
  clang_analyzer_dump(c); // expected-warning {{Unknown}}
  *c = 42; // no-crash
}