Debian Codegraph @

clang/test/Analysis/uninit-vals.cpp

raw
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core.builtin -verify -DCHECK_FOR_CRASH %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core -verify -analyzer-output=text %s
3
4 #ifdef CHECK_FOR_CRASH
5 // expected-no-diagnostics
6 #endif
7
8 namespace PerformTrivialCopyForUndefs {
9 struct A {
10 int x;
11 };
12
13 struct B {
14 A a;
15 };
16
17 struct C {
18 B b;
19 };
20
21 void foo() {
22 C c1;
23 C *c2;
24 #ifdef CHECK_FOR_CRASH
25 // If the value of variable is not defined and checkers that check undefined
26 // values are not enabled, performTrivialCopy should be able to handle the
27 // case with undefined values, too.
28 c1.b.a = c2->b.a;
29 #else
30 c1.b.a = c2->b.a; // expected-warning{{1st function call argument is an uninitialized value}}
31 // expected-note@-1{{1st function call argument is an uninitialized value}}
32 #endif
33 }
34 }
35
36 namespace gh_178797 {
37 struct SpecialBuffer {
38 SpecialBuffer() : src(defaultBuffer), dst(defaultBuffer) {}
39 int* src;
40 int* dst;
41 int defaultBuffer[2];
42 };
43 // Not really a swap, but we need an assignment assigning UndefinedVal
44 // within a "swap" function to trigger this behavior.
45 void swap(int& lhs, int& rhs) {
46 lhs = rhs; // no-crash
47 // Not reporting copying uninitialized data because that is explicitly suppressed in the checker.
48 }
49 void entry_point() {
50 SpecialBuffer special;
51 swap(*special.dst, *++special.src);
52 }
53 } // namespace gh_178797