1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s 2651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: not %clang_cc1 -fsyntax-only -ast-dump %s | FileCheck %s 3651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 43e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregorvoid f() { 55faf5d31fa634e1fdb576c4d9708cd4efa5ea310Jean-Daniel Dupas int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring library function 'malloc' with type}} \ 63e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor // expected-note{{please include the header <stdlib.h> or explicitly provide a declaration for 'malloc'}} \ 7cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor // expected-note{{'malloc' is a builtin with type 'void *}} 83e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor} 93e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor 103e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregorvoid *alloca(__SIZE_TYPE__); // redeclaration okay 113e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor 12374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregorint *calloc(__SIZE_TYPE__, __SIZE_TYPE__); // expected-warning{{incompatible redeclaration of library function 'calloc'}} \ 13cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor // expected-note{{'calloc' is a builtin with type 'void *}} 143e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor 153e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor 163e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregorvoid g(int malloc) { // okay: these aren't functions 173e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor int calloc = 1; 183e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor} 193e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor 203e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregorvoid h() { 21374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregor int malloc(int); // expected-warning{{incompatible redeclaration of library function 'malloc'}} 22374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregor int strcpy(int); // expected-warning{{incompatible redeclaration of library function 'strcpy'}} \ 2358f9e13e87e57236fee4b914eea9be6f92a1c345Chris Lattner // expected-note{{'strcpy' is a builtin with type 'char *(char *, const char *)'}} 243e41d60eb627dc227c770f1c1c87d06909cf05fdDouglas Gregor} 25370ab3f1373841d70582feac9e35c3c6b3489f63Douglas Gregor 26370ab3f1373841d70582feac9e35c3c6b3489f63Douglas Gregorvoid f2() { 276b9109e9d5446f213b12d2a6b76495bffb06b794Douglas Gregor fprintf(0, "foo"); // expected-warning{{declaration of built-in function 'fprintf' requires inclusion of the header <stdio.h>}} \ 28e030358cc06e1cbce3c2e00ca67c946f9164b2a8Chris Lattner expected-warning {{implicit declaration of function 'fprintf' is invalid in C99}} 29370ab3f1373841d70582feac9e35c3c6b3489f63Douglas Gregor} 30cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor 31cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor// PR2892 32cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregorvoid __builtin_object_size(); // expected-error{{conflicting types}} \ 33cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor// expected-note{{'__builtin_object_size' is a builtin with type}} 34cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor 35cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregorint a[10]; 36cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor 37cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregorint f0() { 38cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor return __builtin_object_size(&a); // expected-error {{too few arguments to function}} 39cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor} 40cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor 41374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregorvoid * realloc(void *p, int size) { // expected-warning{{incompatible redeclaration of library function 'realloc'}} \ 42edbb94cee89ba366989f0a6d05debbb5d54d4342Eli Friedman// expected-note{{'realloc' is a builtin with type 'void *(void *,}} 43cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor return p; 44cda9c674998aedeb9319e95a0284f4d266dcef32Douglas Gregor} 45374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregor 46374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregor// PR3855 47374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregorvoid snprintf(); // expected-warning{{incompatible redeclaration of library function 'snprintf'}} \ 48ff59a8ab68326c7f50c78f0cc5a99b1f8fd02b01Eli Friedman // expected-note{{'snprintf' is a builtin}} 49374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregor 50374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregorint 51374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregormain(int argc, char *argv[]) 52374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregor{ 53374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregor snprintf(); 54374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregor} 55374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregor 56374e156647e4250274eb66102839abf0ee9d7fe8Douglas Gregorvoid snprintf() { } 576b9109e9d5446f213b12d2a6b76495bffb06b794Douglas Gregor 586b9109e9d5446f213b12d2a6b76495bffb06b794Douglas Gregor// PR8316 596b9109e9d5446f213b12d2a6b76495bffb06b794Douglas Gregorvoid longjmp(); // expected-warning{{declaration of built-in function 'longjmp' requires inclusion of the header <setjmp.h>}} 605f164afca376b05b6fcbc5ab85ea108b6d6ee2b9Douglas Gregor 615f164afca376b05b6fcbc5ab85ea108b6d6ee2b9Douglas Gregorextern float fmaxf(float, float); 62651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 63651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesstruct __jmp_buf_tag {}; 64651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid sigsetjmp(struct __jmp_buf_tag[1], int); // expected-warning{{declaration of built-in function 'sigsetjmp' requires inclusion of the header <setjmp.h>}} 65651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 66651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: FunctionDecl {{.*}} <line:[[@LINE-2]]:1, col:44> col:6 sigsetjmp ' 67651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-NOT: FunctionDecl 68651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: ReturnsTwiceAttr {{.*}} <{{.*}}> Implicit 69