Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Richard Smith | 8c7bd6a | 2014-01-22 23:07:19 +0000 | [diff] [blame] | 2 | // RUN: not %clang_cc1 -fsyntax-only -ast-dump %s | FileCheck %s |
| 3 | |
Douglas Gregor | b9063fc | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 4 | void f() { |
Jean-Daniel Dupas | 400dd1c | 2012-01-27 23:21:02 +0000 | [diff] [blame] | 5 | int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring library function 'malloc' with type}} \ |
Alp Toker | 5d96e0a | 2014-07-11 20:53:51 +0000 | [diff] [blame^] | 6 | // expected-note{{include the header <stdlib.h> or explicitly provide a declaration for 'malloc'}} \ |
Douglas Gregor | 75a45ba | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 7 | // expected-note{{'malloc' is a builtin with type 'void *}} |
Douglas Gregor | b9063fc | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 8 | } |
| 9 | |
| 10 | void *alloca(__SIZE_TYPE__); // redeclaration okay |
| 11 | |
Douglas Gregor | 893c2c9 | 2009-03-23 17:47:24 +0000 | [diff] [blame] | 12 | int *calloc(__SIZE_TYPE__, __SIZE_TYPE__); // expected-warning{{incompatible redeclaration of library function 'calloc'}} \ |
Douglas Gregor | 75a45ba | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 13 | // expected-note{{'calloc' is a builtin with type 'void *}} |
Douglas Gregor | b9063fc | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | void g(int malloc) { // okay: these aren't functions |
| 17 | int calloc = 1; |
| 18 | } |
| 19 | |
| 20 | void h() { |
Douglas Gregor | 893c2c9 | 2009-03-23 17:47:24 +0000 | [diff] [blame] | 21 | int malloc(int); // expected-warning{{incompatible redeclaration of library function 'malloc'}} |
| 22 | int strcpy(int); // expected-warning{{incompatible redeclaration of library function 'strcpy'}} \ |
Chris Lattner | 53fa049 | 2010-09-05 00:04:01 +0000 | [diff] [blame] | 23 | // expected-note{{'strcpy' is a builtin with type 'char *(char *, const char *)'}} |
Douglas Gregor | b9063fc | 2009-02-13 23:20:09 +0000 | [diff] [blame] | 24 | } |
Douglas Gregor | 538c3d8 | 2009-02-14 01:52:53 +0000 | [diff] [blame] | 25 | |
| 26 | void f2() { |
Douglas Gregor | bfe022c | 2011-01-03 09:37:44 +0000 | [diff] [blame] | 27 | fprintf(0, "foo"); // expected-warning{{declaration of built-in function 'fprintf' requires inclusion of the header <stdio.h>}} \ |
Chris Lattner | f9895c4 | 2010-01-09 20:43:19 +0000 | [diff] [blame] | 28 | expected-warning {{implicit declaration of function 'fprintf' is invalid in C99}} |
Douglas Gregor | 538c3d8 | 2009-02-14 01:52:53 +0000 | [diff] [blame] | 29 | } |
Douglas Gregor | 75a45ba | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 30 | |
| 31 | // PR2892 |
| 32 | void __builtin_object_size(); // expected-error{{conflicting types}} \ |
| 33 | // expected-note{{'__builtin_object_size' is a builtin with type}} |
| 34 | |
| 35 | int a[10]; |
| 36 | |
| 37 | int f0() { |
| 38 | return __builtin_object_size(&a); // expected-error {{too few arguments to function}} |
| 39 | } |
| 40 | |
Douglas Gregor | 893c2c9 | 2009-03-23 17:47:24 +0000 | [diff] [blame] | 41 | void * realloc(void *p, int size) { // expected-warning{{incompatible redeclaration of library function 'realloc'}} \ |
Eli Friedman | 1e3a02f | 2009-02-18 00:52:29 +0000 | [diff] [blame] | 42 | // expected-note{{'realloc' is a builtin with type 'void *(void *,}} |
Douglas Gregor | 75a45ba | 2009-02-16 17:45:42 +0000 | [diff] [blame] | 43 | return p; |
| 44 | } |
Douglas Gregor | 893c2c9 | 2009-03-23 17:47:24 +0000 | [diff] [blame] | 45 | |
| 46 | // PR3855 |
| 47 | void snprintf(); // expected-warning{{incompatible redeclaration of library function 'snprintf'}} \ |
Eli Friedman | 703a77f | 2009-03-24 01:11:18 +0000 | [diff] [blame] | 48 | // expected-note{{'snprintf' is a builtin}} |
Douglas Gregor | 893c2c9 | 2009-03-23 17:47:24 +0000 | [diff] [blame] | 49 | |
| 50 | int |
| 51 | main(int argc, char *argv[]) |
| 52 | { |
| 53 | snprintf(); |
| 54 | } |
| 55 | |
| 56 | void snprintf() { } |
Douglas Gregor | bfe022c | 2011-01-03 09:37:44 +0000 | [diff] [blame] | 57 | |
| 58 | // PR8316 |
| 59 | void longjmp(); // expected-warning{{declaration of built-in function 'longjmp' requires inclusion of the header <setjmp.h>}} |
Douglas Gregor | a5f9c06 | 2012-05-08 18:29:52 +0000 | [diff] [blame] | 60 | |
| 61 | extern float fmaxf(float, float); |
Richard Smith | 8c7bd6a | 2014-01-22 23:07:19 +0000 | [diff] [blame] | 62 | |
| 63 | struct __jmp_buf_tag {}; |
| 64 | void sigsetjmp(struct __jmp_buf_tag[1], int); // expected-warning{{declaration of built-in function 'sigsetjmp' requires inclusion of the header <setjmp.h>}} |
| 65 | |
David Blaikie | 5ee3d00 | 2014-04-02 05:48:29 +0000 | [diff] [blame] | 66 | // CHECK: FunctionDecl {{.*}} <line:[[@LINE-2]]:1, col:44> col:6 sigsetjmp ' |
Richard Smith | 8c7bd6a | 2014-01-22 23:07:19 +0000 | [diff] [blame] | 67 | // CHECK-NOT: FunctionDecl |
| 68 | // CHECK: ReturnsTwiceAttr {{.*}} <{{.*}}> Implicit |