Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 2 | void 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 Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 5 | // expected-note{{'malloc' is a builtin with type 'void *}} |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 6 | } |
| 7 | |
| 8 | void *alloca(__SIZE_TYPE__); // redeclaration okay |
| 9 | |
Douglas Gregor | 374e156 | 2009-03-23 17:47:24 +0000 | [diff] [blame] | 10 | int *calloc(__SIZE_TYPE__, __SIZE_TYPE__); // expected-warning{{incompatible redeclaration of library function 'calloc'}} \ |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 11 | // expected-note{{'calloc' is a builtin with type 'void *}} |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 12 | |
| 13 | |
| 14 | void g(int malloc) { // okay: these aren't functions |
| 15 | int calloc = 1; |
| 16 | } |
| 17 | |
| 18 | void h() { |
Douglas Gregor | 374e156 | 2009-03-23 17:47:24 +0000 | [diff] [blame] | 19 | int malloc(int); // expected-warning{{incompatible redeclaration of library function 'malloc'}} |
| 20 | int strcpy(int); // expected-warning{{incompatible redeclaration of library function 'strcpy'}} \ |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 21 | // expected-note{{'strcpy' is a builtin with type 'char *(char *, char const *)'}} |
Douglas Gregor | 3e41d60 | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 22 | } |
Douglas Gregor | 370ab3f | 2009-02-14 01:52:53 +0000 | [diff] [blame] | 23 | |
| 24 | void f2() { |
Chris Lattner | e030358 | 2010-01-09 20:43:19 +0000 | [diff] [blame^] | 25 | fprintf(0, "foo"); // expected-error{{implicit declaration of 'fprintf' requires inclusion of the header <stdio.h>}} \ |
| 26 | expected-warning {{implicit declaration of function 'fprintf' is invalid in C99}} |
Douglas Gregor | 370ab3f | 2009-02-14 01:52:53 +0000 | [diff] [blame] | 27 | } |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 28 | |
| 29 | // PR2892 |
| 30 | void __builtin_object_size(); // expected-error{{conflicting types}} \ |
| 31 | // expected-note{{'__builtin_object_size' is a builtin with type}} |
| 32 | |
| 33 | int a[10]; |
| 34 | |
| 35 | int f0() { |
| 36 | return __builtin_object_size(&a); // expected-error {{too few arguments to function}} |
| 37 | } |
| 38 | |
Douglas Gregor | 374e156 | 2009-03-23 17:47:24 +0000 | [diff] [blame] | 39 | void * realloc(void *p, int size) { // expected-warning{{incompatible redeclaration of library function 'realloc'}} \ |
Eli Friedman | edbb94c | 2009-02-18 00:52:29 +0000 | [diff] [blame] | 40 | // expected-note{{'realloc' is a builtin with type 'void *(void *,}} |
Douglas Gregor | cda9c67 | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 41 | return p; |
| 42 | } |
Douglas Gregor | 374e156 | 2009-03-23 17:47:24 +0000 | [diff] [blame] | 43 | |
| 44 | // PR3855 |
| 45 | void snprintf(); // expected-warning{{incompatible redeclaration of library function 'snprintf'}} \ |
Eli Friedman | ff59a8a | 2009-03-24 01:11:18 +0000 | [diff] [blame] | 46 | // expected-note{{'snprintf' is a builtin}} |
Douglas Gregor | 374e156 | 2009-03-23 17:47:24 +0000 | [diff] [blame] | 47 | |
| 48 | int |
| 49 | main(int argc, char *argv[]) |
| 50 | { |
| 51 | snprintf(); |
| 52 | } |
| 53 | |
| 54 | void snprintf() { } |