1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li // RUN: not %clang_cc1 -fsyntax-only -ast-dump %s | FileCheck %s
3*67e74705SXin Li
f()4*67e74705SXin Li void f() {
5*67e74705SXin Li int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring library function 'malloc' with type}} \
6*67e74705SXin Li // expected-note{{include the header <stdlib.h> or explicitly provide a declaration for 'malloc'}} \
7*67e74705SXin Li // expected-note{{'malloc' is a builtin with type 'void *}}
8*67e74705SXin Li }
9*67e74705SXin Li
10*67e74705SXin Li void *alloca(__SIZE_TYPE__); // redeclaration okay
11*67e74705SXin Li
12*67e74705SXin Li int *calloc(__SIZE_TYPE__, __SIZE_TYPE__); // expected-warning{{incompatible redeclaration of library function 'calloc'}} \
13*67e74705SXin Li // expected-note{{'calloc' is a builtin with type 'void *}}
14*67e74705SXin Li
15*67e74705SXin Li
g(int malloc)16*67e74705SXin Li void g(int malloc) { // okay: these aren't functions
17*67e74705SXin Li int calloc = 1;
18*67e74705SXin Li }
19*67e74705SXin Li
h()20*67e74705SXin Li void h() {
21*67e74705SXin Li int malloc(int); // expected-warning{{incompatible redeclaration of library function 'malloc'}}
22*67e74705SXin Li int strcpy(int); // expected-warning{{incompatible redeclaration of library function 'strcpy'}} \
23*67e74705SXin Li // expected-note{{'strcpy' is a builtin with type 'char *(char *, const char *)'}}
24*67e74705SXin Li }
25*67e74705SXin Li
f2()26*67e74705SXin Li void f2() {
27*67e74705SXin Li fprintf(0, "foo"); // expected-warning{{declaration of built-in function 'fprintf' requires inclusion of the header <stdio.h>}} \
28*67e74705SXin Li expected-warning {{implicit declaration of function 'fprintf' is invalid in C99}}
29*67e74705SXin Li }
30*67e74705SXin Li
31*67e74705SXin Li // PR2892
32*67e74705SXin Li void __builtin_object_size(); // expected-error{{conflicting types}} \
33*67e74705SXin Li // expected-note{{'__builtin_object_size' is a builtin with type}}
34*67e74705SXin Li
35*67e74705SXin Li int a[10];
36*67e74705SXin Li
f0()37*67e74705SXin Li int f0() {
38*67e74705SXin Li return __builtin_object_size(&a); // expected-error {{too few arguments to function}}
39*67e74705SXin Li }
40*67e74705SXin Li
realloc(void * p,int size)41*67e74705SXin Li void * realloc(void *p, int size) { // expected-warning{{incompatible redeclaration of library function 'realloc'}} \
42*67e74705SXin Li // expected-note{{'realloc' is a builtin with type 'void *(void *,}}
43*67e74705SXin Li return p;
44*67e74705SXin Li }
45*67e74705SXin Li
46*67e74705SXin Li // PR3855
47*67e74705SXin Li void snprintf(); // expected-warning{{incompatible redeclaration of library function 'snprintf'}} \
48*67e74705SXin Li // expected-note{{'snprintf' is a builtin}}
49*67e74705SXin Li
50*67e74705SXin Li int
main(int argc,char * argv[])51*67e74705SXin Li main(int argc, char *argv[])
52*67e74705SXin Li {
53*67e74705SXin Li snprintf();
54*67e74705SXin Li }
55*67e74705SXin Li
snprintf()56*67e74705SXin Li void snprintf() { }
57*67e74705SXin Li
58*67e74705SXin Li // PR8316
59*67e74705SXin Li void longjmp(); // expected-warning{{declaration of built-in function 'longjmp' requires inclusion of the header <setjmp.h>}}
60*67e74705SXin Li
61*67e74705SXin Li extern float fmaxf(float, float);
62*67e74705SXin Li
63*67e74705SXin Li struct __jmp_buf_tag {};
64*67e74705SXin Li void sigsetjmp(struct __jmp_buf_tag[1], int); // expected-warning{{declaration of built-in function 'sigsetjmp' requires inclusion of the header <setjmp.h>}}
65*67e74705SXin Li
66*67e74705SXin Li // CHECK: FunctionDecl {{.*}} <line:[[@LINE-2]]:1, col:44> col:6 sigsetjmp '
67*67e74705SXin Li // CHECK-NOT: FunctionDecl
68*67e74705SXin Li // CHECK: ReturnsTwiceAttr {{.*}} <{{.*}}> Implicit
69