1 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
2 // RUN: %clang_analyze_cc1 -triple x86_64-pc-windows-msvc19.11.0 -fms-extensions -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
4 #include "Inputs/system-header-simulator-cxx.h"
7 // Intentionally not using an "auto" return type here, as such must also have a definition.
8 template <typename T
, typename U
> constexpr int&& forward_like(U
&& x
) noexcept
;
9 template <typename T
> const T
& move_if_noexcept(T
& x
) noexcept
;
12 template <typename T
> void clang_analyzer_dump_ref(T
&&);
13 template <typename T
> void clang_analyzer_dump_ptr(T
*);
14 void clang_analyzer_eval(bool);
15 void clang_analyzer_warnIfReached();
17 void testAddressof(int x
) {
18 clang_analyzer_eval(&x
== __builtin_addressof(x
)); // expected-warning{{TRUE}}
21 void testStdBuiltinLikeFunctions(int x
) {
22 clang_analyzer_dump_ptr(std::addressof(x
)); // expected-warning{{&x}}
23 clang_analyzer_dump_ptr(std::__addressof(x
)); // expected-warning{{&x}}
24 clang_analyzer_dump_ref(std::as_const(x
)); // expected-warning{{&x}}
25 clang_analyzer_dump_ref(std::forward
<int &>(x
)); // expected-warning{{&x}}
26 clang_analyzer_dump_ref(std::forward_like
<int &>(x
)); // expected-warning{{&x}}
27 clang_analyzer_dump_ref(std::move(x
)); // expected-warning{{&x}}
28 clang_analyzer_dump_ref(std::move_if_noexcept(x
)); // expected-warning{{&x}}
37 clang_analyzer_eval(__builtin_object_size(&object
.y
, 0) == sizeof(object
) - sizeof(int)); // expected-warning{{TRUE}}
39 // Clang can't actually evaluate these builtin "calls", but importantly they don't actually evaluate the argument expression either.
42 clang_analyzer_eval(__builtin_object_size(&buf
[i
++], 0) == sizeof(buf
)); // expected-warning{{FALSE}}
43 clang_analyzer_eval(__builtin_object_size(&buf
[++i
], 0) == sizeof(buf
) - 1); // expected-warning{{FALSE}}
45 clang_analyzer_eval(i
== 0); // expected-warning{{TRUE}}
48 void test_assume_aligned_1(char *p
) {
51 q
= (char*) __builtin_assume_aligned(p
, 16);
52 clang_analyzer_eval(p
== q
); // expected-warning{{TRUE}}
55 void test_assume_aligned_2(char *p
) {
58 q
= (char*) __builtin_assume_aligned(p
, 16, 8);
59 clang_analyzer_eval(p
== q
); // expected-warning{{TRUE}}
62 void test_assume_aligned_3(char *p
) {
65 q
= __builtin_assume_aligned(p
, 16, 8);
66 clang_analyzer_eval(p
== q
); // expected-warning{{TRUE}}
69 void test_assume_aligned_4(char *p
) {
72 q
= (char*) __builtin_assume_aligned(p
+ 1, 16);
73 clang_analyzer_eval(p
== q
); // expected-warning{{FALSE}}
77 __builtin_assume(i
< 10);
78 clang_analyzer_eval(i
< 15); // expected-warning {{TRUE}}
83 __builtin_assume(i
< 5);
84 clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
85 // We give up the analysis on this path.
93 clang_analyzer_eval(i
< 15); // expected-warning {{TRUE}}
99 clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
100 // We give up the analysis on this path.
106 void test_constant_p(void *ptr
) {
110 clang_analyzer_eval(__builtin_constant_p(42) == 1); // expected-warning {{TRUE}}
111 clang_analyzer_eval(__builtin_constant_p(i
) == 0); // expected-warning {{TRUE}}
112 clang_analyzer_eval(__builtin_constant_p(j
) == 1); // expected-warning {{TRUE}}
113 clang_analyzer_eval(__builtin_constant_p(k
) == 1); // expected-warning {{TRUE}}
114 clang_analyzer_eval(__builtin_constant_p(i
+ 42) == 0); // expected-warning {{TRUE}}
115 clang_analyzer_eval(__builtin_constant_p(j
+ 42) == 1); // expected-warning {{TRUE}}
116 clang_analyzer_eval(__builtin_constant_p(k
+ 42) == 1); // expected-warning {{TRUE}}
117 clang_analyzer_eval(__builtin_constant_p(" ") == 1); // expected-warning {{TRUE}}
118 clang_analyzer_eval(__builtin_constant_p(test_constant_p
) == 0); // expected-warning {{TRUE}}
119 clang_analyzer_eval(__builtin_constant_p(k
- 3) == 0); // expected-warning {{FALSE}}
120 clang_analyzer_eval(__builtin_constant_p(k
- 3) == 1); // expected-warning {{TRUE}}
121 clang_analyzer_eval(__builtin_constant_p(ptr
== 0)); // expected-warning {{FALSE}}