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
) {
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
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
45 void deadCode(List orig
) {
47 clang_analyzer_dump(c
.value
);
48 // expected-warning-re@-1 {{reg_${{[0-9]+}}<int orig.value>}}
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.
57 clang_analyzer_warnIfReached(); // no-warning: Dead code.
61 List
* n2
= new List(*n
); // ctor
64 clang_analyzer_warnIfReached(); // unreachable
71 List
* n2
= new List(); // ctor
72 *n2
= *n
; // assignment
75 clang_analyzer_warnIfReached(); // unreachable
86 void nestedLazyCompoundVal(List
* n
) {
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