misc-ps.m revision 265a305997c63a28d87ddd370958db083f98bc1a
1// RUN: clang -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=basic --verify -fblocks %s &&
2// RUN: clang -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=range --verify -fblocks %s &&
3// RUN: clang -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=basic --verify -fblocks %s &&
4// RUN: clang -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=range --verify -fblocks %s
5
6
7// Reduced test case from crash in <rdar://problem/6253157>
8@class NSObject;
9@interface A @end
10@implementation A
11- (void)foo:(void (^)(NSObject *x))block {
12  if (!((block != ((void *)0)))) {}
13}
14@end
15
16// Reduced test case from crash in PR 2796;
17//  http://llvm.org/bugs/show_bug.cgi?id=2796
18
19unsigned foo(unsigned x) { return __alignof__((x)) + sizeof(x); }
20
21// Improvement to path-sensitivity involving compound assignments.
22//  Addresses false positive in <rdar://problem/6268365>
23//
24
25unsigned r6268365Aux();
26
27void r6268365() {
28  unsigned x = 0;
29  x &= r6268365Aux();
30  unsigned j = 0;
31    
32  if (x == 0) ++j;
33  if (x == 0) x = x / j; // no-warning
34}
35
36void divzeroassume(unsigned x, unsigned j) {  
37  x /= j;  
38  if (j == 0) x /= 0;     // no-warning
39  if (j == 0) x /= j;     // no-warning
40  if (j == 0) x = x / 0;  // no-warning
41}
42
43void divzeroassumeB(unsigned x, unsigned j) {  
44  x = x / j;  
45  if (j == 0) x /= 0;     // no-warning
46  if (j == 0) x /= j;     // no-warning
47  if (j == 0) x = x / 0;  // no-warning
48}
49
50// InitListExpr processing
51
52typedef float __m128 __attribute__((__vector_size__(16), __may_alias__));
53__m128 return128() {
54  // This compound literal has a Vector type.  We currently just
55  // return UnknownVal.
56  return __extension__(__m128) { 0.0f, 0.0f, 0.0f, 0.0f };
57}
58
59typedef long long __v2di __attribute__ ((__vector_size__ (16)));
60typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
61__m128i vec128i(long long __q1, long long __q0) {
62  // This compound literal returns true for both isVectorType() and 
63  // isIntegerType().
64  return __extension__ (__m128i)(__v2di){ __q0, __q1 };
65}
66
67// Zero-sized VLAs.
68void check_zero_sized_VLA(int x) {
69  if (x)
70    return;
71
72  int vla[x]; // expected-warning{{VLAs with no elements have undefined behavior}}
73}
74
75void check_uninit_sized_VLA() {
76  int x;
77  int vla[x]; // expected-warning{{The expression used to specify the number of elements in the VLA 'vla' evaluates to an undefined or garbage value.}}
78}
79
80// sizeof(void)
81// - Tests a regression reported in PR 3211: http://llvm.org/bugs/show_bug.cgi?id=3211
82void handle_sizeof_void(unsigned flag) {
83  int* p = 0;
84
85  if (flag) {
86    if (sizeof(void) == 1)
87      return;
88    // Infeasible.
89    *p = 1; // no-warning
90  }
91  
92  void* q;
93  
94  if (!flag) {
95    if (sizeof(*q) == 1)
96      return;
97    // Infeasibe.
98    *p = 1; // no-warning
99  }
100    
101  // Infeasible.
102  *p = 1; // no-warning
103}
104
105// PR 3422
106void pr3422_helper(char *p);
107void pr3422() {
108  char buf[100];
109  char *q = &buf[10];
110  pr3422_helper(&q[1]);
111}
112
113// PR 3543 (handle empty statement expressions)
114int pr_3543(void) {
115  ({});
116}
117
118// <rdar://problem/6611677>
119// This test case test the use of a vector type within an array subscript
120// expression.
121typedef long long __a64vector __attribute__((__vector_size__(8)));
122typedef long long __a128vector __attribute__((__vector_size__(16)));
123static inline __a64vector __attribute__((__always_inline__, __nodebug__))  
124my_test_mm_movepi64_pi64(__a128vector a) {
125  return (__a64vector)a[0];
126}
127
128
129