1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core -analyzer-store=region -verify %s
2 //
3 // Just exercise the analyzer on code that has at one point caused issues
4 // (i.e., no assertions or crashes).
5 
6 
f1(const char * x,char * y)7 static void f1(const char *x, char *y) {
8   while (*x != 0) {
9     *y++ = *x++;
10   }
11 }
12 
13 // This following case checks that we properly handle typedefs when getting
14 // the RvalueType of an ElementRegion.
15 typedef struct F12_struct {} F12_typedef;
16 typedef void* void_typedef;
17 void_typedef f2_helper();
f2(void * buf)18 static void f2(void *buf) {
19   F12_typedef* x;
20   x = f2_helper();
21   memcpy((&x[1]), (buf), 1); // expected-warning{{implicitly declaring library function 'memcpy' with type 'void *(void *, const void *}} \
22   // expected-note{{include the header <string.h> or explicitly provide a declaration for 'memcpy'}}
23 }
24 
25 // AllocaRegion is untyped. Void pointer isn't of much help either. Before
26 // realizing that the value is undefined, we need to somehow figure out
27 // what type of value do we expect.
f3(void * dest)28 void f3(void *dest) {
29   void *src = __builtin_alloca(5);
30   memcpy(dest, src, 1); // expected-warning{{2nd function call argument is a pointer to uninitialized value}}
31 }
32