implicit-builtin-decl.c 2.4 KB

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