Debian Codegraph @

clang/test/Analysis/call-and-message.c

raw
1 // RUN: %clang_analyze_cc1 %s -verify \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=true \
4 // RUN: -analyzer-config core.CallAndMessage:ArgInitializedness=false \
5 // RUN: -analyzer-output=plist -o %t.plist
6 // RUN: cat %t.plist | FileCheck %s
7
8 // RUN: %clang_analyze_cc1 %s -verify=no-pointee \
9 // RUN: -analyzer-checker=core \
10 // RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=false \
11 // RUN: -analyzer-config core.CallAndMessage:ArgInitializedness=false
12
13 // RUN: %clang_analyze_cc1 %s -verify=arg-init \
14 // RUN: -analyzer-checker=core \
15 // RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=false \
16 // RUN: -analyzer-config core.CallAndMessage:ArgInitializedness=true
17
18 // no-pointee-no-diagnostics
19
20 void doStuff_pointerToConstInt(const int *u){};
21 void pointee_uninit(void) {
22 int i;
23 int *p = &i;
24 doStuff_pointerToConstInt(p); // expected-warning{{1st function call argument is a pointer to uninitialized value [core.CallAndMessage]}}
25 }
26
27 typedef struct S {
28 int a;
29 short b;
30 } S;
31
32 void doStuff_pointerToConstStruct(const S *s){};
33 void pointee_uninit_struct(void) {
34 S s;
35 S *p = &s;
36 doStuff_pointerToConstStruct(p); // expected-warning{{1st function call argument points to an uninitialized value (e.g., field: 'a') [core.CallAndMessage]}}
37 }
38 void pointee_uninit_struct_1(void) {
39 S s;
40 s.a = 2;
41 doStuff_pointerToConstStruct(&s); // expected-warning{{1st function call argument points to an uninitialized value (e.g., field: 'b') [core.CallAndMessage]}}
42 }
43 void pointee_uninit_struct_2(void) {
44 S s = {};
45 doStuff_pointerToConstStruct(&s);
46 }
47 void pointee_uninit_struct_3(S *s) {
48 doStuff_pointerToConstStruct(s);
49 }
50 void pointee_uninit_struct_4(void) {
51 S s = {1, 2};
52 doStuff_pointerToConstStruct(&s);
53 }
54
55 // TODO: If this hash ever changes, turn
56 // core.CallAndMessage:ArgPointeeInitializedness from a checker option into a
57 // checker, as described in the CallAndMessage comments!
58 // CHECK: <key>issue_hash_content_of_line_in_context</key>
59 // CHECK-SAME: <string>97a74322d64dca40aa57303842c745a1</string>
60
61 typedef struct {
62 int i :2;
63 int :30; // unnamed bit-field
64 } B;
65
66 extern void consume_B(B);
67
68 void bitfield_B_init(void) {
69 B b1;
70 b1.i = 1; // b1 is initialized
71 consume_B(b1);
72 }
73
74 void bitfield_B_uninit(void) {
75 B b2;
76 consume_B(b2); // arg-init-warning{{Passed-by-value struct argument contains uninitialized data (e.g., field: 'i') [core.CallAndMessage]}}
77 }