[RISCV] Add shrinkwrap test cases showing gaps in current impl
[llvm-project.git] / clang / test / Analysis / trivial-copy-struct.cpp
blobb2da777541aba91b41d69d64034cff90e68ba616
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
3 template <typename T> void clang_analyzer_dump(T);
4 template <typename T> void clang_analyzer_value(T);
5 void clang_analyzer_warnIfReached();
7 struct Node { int* ptr; };
9 void copy_on_stack(Node* n1) {
10 Node tmp = *n1;
11 Node* n2 = &tmp;
12 clang_analyzer_dump(n1); // expected-warning-re {{&SymRegion{reg_${{[0-9]+}}<Node * n1>}}}
13 clang_analyzer_dump(n2); // expected-warning {{&tmp}}
15 clang_analyzer_dump(n1->ptr); // expected-warning-re {{&SymRegion{reg_${{[0-9]+}}<int * Element{SymRegion{reg_${{[0-9]+}}<Node * n1>},0 S64b,struct Node}.ptr>}}}
16 clang_analyzer_dump(n2->ptr); // expected-warning-re {{&SymRegion{reg_${{[0-9]+}}<int * Element{SymRegion{reg_${{[0-9]+}}<Node * n1>},0 S64b,struct Node}.ptr>}}}
18 if (n1->ptr != n2->ptr)
19 clang_analyzer_warnIfReached(); // unreachable
20 (void)(n1->ptr);
21 (void)(n2->ptr);
24 void copy_on_heap(Node* n1) {
25 Node* n2 = new Node(*n1);
27 clang_analyzer_dump(n1); // expected-warning-re {{&SymRegion{reg_${{[0-9]+}}<Node * n1>}}}
28 clang_analyzer_dump(n2); // expected-warning-re {{&HeapSymRegion{conj_${{[0-9]+}}{Node *, LC{{[0-9]+}}, S{{[0-9]+}}, #{{[0-9]+}}}}}}
30 clang_analyzer_dump(n1->ptr); // expected-warning-re {{&SymRegion{reg_${{[0-9]+}}<int * Element{SymRegion{reg_${{[0-9]+}}<Node * n1>},0 S64b,struct Node}.ptr>}}}
31 clang_analyzer_dump(n2->ptr); // expected-warning-re {{&SymRegion{reg_${{[0-9]+}}<int * Element{SymRegion{reg_${{[0-9]+}}<Node * n1>},0 S64b,struct Node}.ptr>}}}
33 if (n1->ptr != n2->ptr)
34 clang_analyzer_warnIfReached(); // unreachable
35 (void)(n1->ptr);
36 (void)(n2->ptr);
39 struct List {
40 List* next;
41 int value;
42 int padding;
45 void deadCode(List orig) {
46 List c = orig;
47 clang_analyzer_dump(c.value);
48 // expected-warning-re@-1 {{reg_${{[0-9]+}}<int orig.value>}}
49 if (c.value == 42)
50 return;
51 clang_analyzer_value(c.value);
52 // expected-warning@-1 {{32s:{ [-2147483648, 41], [43, 2147483647] }}}
53 // Before symbol was garbage collected too early, and we lost the constraints.
54 if (c.value != 42)
55 return;
57 clang_analyzer_warnIfReached(); // no-warning: Dead code.
60 void ptr1(List* n) {
61 List* n2 = new List(*n); // ctor
62 if (!n->next) {
63 if (n2->next) {
64 clang_analyzer_warnIfReached(); // unreachable
67 delete n2;
70 void ptr2(List* n) {
71 List* n2 = new List(); // ctor
72 *n2 = *n; // assignment
73 if (!n->next) {
74 if (n2->next) {
75 clang_analyzer_warnIfReached(); // unreachable
78 delete n2;
81 struct Wrapper {
82 List head;
83 int count;
86 void nestedLazyCompoundVal(List* n) {
87 Wrapper* w = 0;
89 Wrapper lw;
90 lw.head = *n;
91 w = new Wrapper(lw);
93 if (!n->next) {
94 if (w->head.next) {
95 // Unreachable, w->head is a copy of *n, therefore
96 // w->head.next and n->next are equal
97 clang_analyzer_warnIfReached(); // no-warning: unreachable
100 delete w;