blob: 892e372eff6127828fe7eadb3e8376cf202e167c [file] [log] [blame]
Douglas Gregor3e41d602009-02-13 23:20:09 +00001// RUN: clang -fsyntax-only -verify %s
2void f() {
3 int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring C library function 'malloc' with type}} \
4 // expected-note{{please include the header <stdlib.h> or explicitly provide a declaration for 'malloc'}} \
Douglas Gregorcda9c672009-02-16 17:45:42 +00005 // expected-note{{'malloc' is a builtin with type 'void *}}
Douglas Gregor3e41d602009-02-13 23:20:09 +00006}
7
8void *alloca(__SIZE_TYPE__); // redeclaration okay
9
Douglas Gregorcda9c672009-02-16 17:45:42 +000010int *calloc(__SIZE_TYPE__, __SIZE_TYPE__); // expected-warning{{incompatible redeclaration of library function 'calloc' will be ignored}} \
11 // expected-note{{'calloc' is a builtin with type 'void *}}
Douglas Gregor3e41d602009-02-13 23:20:09 +000012
13
14void g(int malloc) { // okay: these aren't functions
15 int calloc = 1;
16}
17
18void h() {
Douglas Gregorcda9c672009-02-16 17:45:42 +000019 int malloc(int); // expected-warning{{incompatible redeclaration of library function 'malloc' will be ignored}}
20 int strcpy(int); // expected-warning{{incompatible redeclaration of library function 'strcpy' will be ignored}} \
21 // expected-note{{'strcpy' is a builtin with type 'char *(char *, char const *)'}}
Douglas Gregor3e41d602009-02-13 23:20:09 +000022}
Douglas Gregor370ab3f2009-02-14 01:52:53 +000023
24void f2() {
25 fprintf(0, "foo"); // expected-error{{implicit declaration of 'fprintf' requires inclusion of the header <stdio.h>}}
26}
Douglas Gregorcda9c672009-02-16 17:45:42 +000027
28// PR2892
29void __builtin_object_size(); // expected-error{{conflicting types}} \
30// expected-note{{'__builtin_object_size' is a builtin with type}}
31
32int a[10];
33
34int f0() {
35 return __builtin_object_size(&a); // expected-error {{too few arguments to function}}
36}
37
38void * realloc(void *p, int size) { // expected-warning{{incompatible redeclaration of library function 'realloc' will be ignored}} \
39// expected-note{{'realloc' is a builtin with type 'void *(void *, unsigned long)'}} \
40// expected-error{{definition of library function 'realloc' in a hosted implementation}} \
41 // expected-note{{use -ffreestanding to compile as a freestanding implementation}}
42 return p;
43}
44