blob: 3c2ff94984c0ff553ecebbd22fad7ce2cb6ff3c8 [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Richard Smith8c7bd6a2014-01-22 23:07:19 +00002// RUN: not %clang_cc1 -fsyntax-only -ast-dump %s | FileCheck %s
3
Douglas Gregorb9063fc2009-02-13 23:20:09 +00004void f() {
Jean-Daniel Dupas400dd1c2012-01-27 23:21:02 +00005 int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring library function 'malloc' with type}} \
Alp Toker5d96e0a2014-07-11 20:53:51 +00006 // expected-note{{include the header <stdlib.h> or explicitly provide a declaration for 'malloc'}} \
Douglas Gregor75a45ba2009-02-16 17:45:42 +00007 // expected-note{{'malloc' is a builtin with type 'void *}}
Douglas Gregorb9063fc2009-02-13 23:20:09 +00008}
9
10void *alloca(__SIZE_TYPE__); // redeclaration okay
11
Douglas Gregor893c2c92009-03-23 17:47:24 +000012int *calloc(__SIZE_TYPE__, __SIZE_TYPE__); // expected-warning{{incompatible redeclaration of library function 'calloc'}} \
Douglas Gregor75a45ba2009-02-16 17:45:42 +000013 // expected-note{{'calloc' is a builtin with type 'void *}}
Douglas Gregorb9063fc2009-02-13 23:20:09 +000014
15
16void g(int malloc) { // okay: these aren't functions
17 int calloc = 1;
18}
19
20void h() {
Douglas Gregor893c2c92009-03-23 17:47:24 +000021 int malloc(int); // expected-warning{{incompatible redeclaration of library function 'malloc'}}
22 int strcpy(int); // expected-warning{{incompatible redeclaration of library function 'strcpy'}} \
Chris Lattner53fa0492010-09-05 00:04:01 +000023 // expected-note{{'strcpy' is a builtin with type 'char *(char *, const char *)'}}
Douglas Gregorb9063fc2009-02-13 23:20:09 +000024}
Douglas Gregor538c3d82009-02-14 01:52:53 +000025
26void f2() {
Douglas Gregorbfe022c2011-01-03 09:37:44 +000027 fprintf(0, "foo"); // expected-warning{{declaration of built-in function 'fprintf' requires inclusion of the header <stdio.h>}} \
Chris Lattnerf9895c42010-01-09 20:43:19 +000028 expected-warning {{implicit declaration of function 'fprintf' is invalid in C99}}
Douglas Gregor538c3d82009-02-14 01:52:53 +000029}
Douglas Gregor75a45ba2009-02-16 17:45:42 +000030
31// PR2892
32void __builtin_object_size(); // expected-error{{conflicting types}} \
33// expected-note{{'__builtin_object_size' is a builtin with type}}
34
35int a[10];
36
37int f0() {
38 return __builtin_object_size(&a); // expected-error {{too few arguments to function}}
39}
40
Douglas Gregor893c2c92009-03-23 17:47:24 +000041void * realloc(void *p, int size) { // expected-warning{{incompatible redeclaration of library function 'realloc'}} \
Eli Friedman1e3a02f2009-02-18 00:52:29 +000042// expected-note{{'realloc' is a builtin with type 'void *(void *,}}
Douglas Gregor75a45ba2009-02-16 17:45:42 +000043 return p;
44}
Douglas Gregor893c2c92009-03-23 17:47:24 +000045
46// PR3855
47void snprintf(); // expected-warning{{incompatible redeclaration of library function 'snprintf'}} \
Eli Friedman703a77f2009-03-24 01:11:18 +000048 // expected-note{{'snprintf' is a builtin}}
Douglas Gregor893c2c92009-03-23 17:47:24 +000049
50int
51main(int argc, char *argv[])
52{
53 snprintf();
54}
55
56void snprintf() { }
Douglas Gregorbfe022c2011-01-03 09:37:44 +000057
58// PR8316
59void longjmp(); // expected-warning{{declaration of built-in function 'longjmp' requires inclusion of the header <setjmp.h>}}
Douglas Gregora5f9c062012-05-08 18:29:52 +000060
61extern float fmaxf(float, float);
Richard Smith8c7bd6a2014-01-22 23:07:19 +000062
63struct __jmp_buf_tag {};
64void sigsetjmp(struct __jmp_buf_tag[1], int); // expected-warning{{declaration of built-in function 'sigsetjmp' requires inclusion of the header <setjmp.h>}}
65
David Blaikie5ee3d002014-04-02 05:48:29 +000066// CHECK: FunctionDecl {{.*}} <line:[[@LINE-2]]:1, col:44> col:6 sigsetjmp '
Richard Smith8c7bd6a2014-01-22 23:07:19 +000067// CHECK-NOT: FunctionDecl
68// CHECK: ReturnsTwiceAttr {{.*}} <{{.*}}> Implicit