blob: d7ec16953a09c470ee3b99e3cf24ee139ffb61ba [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor3e41d602009-02-13 23:20:09 +00002void f() {
Jean-Daniel Dupas5faf5d32012-01-27 23:21:02 +00003 int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring library function 'malloc' with type}} \
Douglas Gregor3e41d602009-02-13 23:20:09 +00004 // 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 Gregor374e1562009-03-23 17:47:24 +000010int *calloc(__SIZE_TYPE__, __SIZE_TYPE__); // expected-warning{{incompatible redeclaration of library function 'calloc'}} \
Douglas Gregorcda9c672009-02-16 17:45:42 +000011 // 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 Gregor374e1562009-03-23 17:47:24 +000019 int malloc(int); // expected-warning{{incompatible redeclaration of library function 'malloc'}}
20 int strcpy(int); // expected-warning{{incompatible redeclaration of library function 'strcpy'}} \
Chris Lattner58f9e132010-09-05 00:04:01 +000021 // expected-note{{'strcpy' is a builtin with type 'char *(char *, const char *)'}}
Douglas Gregor3e41d602009-02-13 23:20:09 +000022}
Douglas Gregor370ab3f2009-02-14 01:52:53 +000023
24void f2() {
Douglas Gregor6b9109e2011-01-03 09:37:44 +000025 fprintf(0, "foo"); // expected-warning{{declaration of built-in function 'fprintf' requires inclusion of the header <stdio.h>}} \
Chris Lattnere0303582010-01-09 20:43:19 +000026 expected-warning {{implicit declaration of function 'fprintf' is invalid in C99}}
Douglas Gregor370ab3f2009-02-14 01:52:53 +000027}
Douglas Gregorcda9c672009-02-16 17:45:42 +000028
29// PR2892
30void __builtin_object_size(); // expected-error{{conflicting types}} \
31// expected-note{{'__builtin_object_size' is a builtin with type}}
32
33int a[10];
34
35int f0() {
36 return __builtin_object_size(&a); // expected-error {{too few arguments to function}}
37}
38
Douglas Gregor374e1562009-03-23 17:47:24 +000039void * realloc(void *p, int size) { // expected-warning{{incompatible redeclaration of library function 'realloc'}} \
Eli Friedmanedbb94c2009-02-18 00:52:29 +000040// expected-note{{'realloc' is a builtin with type 'void *(void *,}}
Douglas Gregorcda9c672009-02-16 17:45:42 +000041 return p;
42}
Douglas Gregor374e1562009-03-23 17:47:24 +000043
44// PR3855
45void snprintf(); // expected-warning{{incompatible redeclaration of library function 'snprintf'}} \
Eli Friedmanff59a8a2009-03-24 01:11:18 +000046 // expected-note{{'snprintf' is a builtin}}
Douglas Gregor374e1562009-03-23 17:47:24 +000047
48int
49main(int argc, char *argv[])
50{
51 snprintf();
52}
53
54void snprintf() { }
Douglas Gregor6b9109e2011-01-03 09:37:44 +000055
56// PR8316
57void longjmp(); // expected-warning{{declaration of built-in function 'longjmp' requires inclusion of the header <setjmp.h>}}
Douglas Gregor5f164af2012-05-08 18:29:52 +000058
59extern float fmaxf(float, float);