brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 59b417e Raw
53 lines · c
1// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s2 3extern char *something();4 5void test1() {6  int *p;7  p = (int *)22; // expected-note{{Pointer value of (int *)22 stored to 'p'}}8  *p = 2; // expected-warning{{Dereference of a fixed address (loaded from variable 'p')}} \9          // expected-note{{Dereference of a fixed address (loaded from variable 'p')}}10}11 12void test2_1(int *p) {13  *p = 1; // expected-warning{{Dereference of a fixed address (loaded from variable 'p')}} \14          // expected-note{{Dereference of a fixed address (loaded from variable 'p')}}15}16 17void test2() {18  int *p = (int *)11; // expected-note{{'p' initialized to (int *)11}}19  test2_1(p); // expected-note{{Passing pointer value (int *)11 via 1st parameter 'p'}} \20              // expected-note{{Calling 'test2_1'}}21}22 23struct test3_s {24  int a;25};26 27 28void test3() {29  struct test3_s *x;30  unsigned long long val = 1111111; // expected-note{{'val' initialized to 1111111}}31  x = (struct test3_s *)val; // expected-note{{Pointer value of (struct test3_s *)1111111 stored to 'x'}}32  x->a = 3; // expected-warning{{Access to field 'a' results in a dereference of a fixed address (loaded from variable 'x')}} \33            // expected-note{{Access to field 'a' results in a dereference of a fixed address (loaded from variable 'x')}}34}35 36char *test4_1() {37  char *ret;38  ret = something(); // expected-note{{Value assigned to 'ret'}}39  if (ret == (char *)-1) // expected-note{{Assuming the condition is true}} \40                         // expected-note{{Taking true branch}}41    return ret; // expected-note{{Returning pointer (loaded from 'ret')}}42  return 0;43}44 45void test4() {46  char *x;47  x = test4_1(); // expected-note{{Calling 'test4_1'}} \48                 // expected-note{{Returning from 'test4_1'}} \49                 // expected-note{{Pointer value of (char *)-1 stored to 'x'}}50  *x = 3; // expected-warning{{Dereference of a fixed address (loaded from variable 'x')}} \51          // expected-note{{Dereference of a fixed address (loaded from variable 'x')}}52}53