74 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-unknown -verify=c,expected -DNO_JMP_BUF %s -ast-dump | FileCheck %s --check-prefixes=CHECK1,CHECK22// RUN: %clang_cc1 -triple x86_64-unknown-unknown -verify=c,expected -DWRONG_JMP_BUF %s -ast-dump | FileCheck %s --check-prefixes=CHECK1,CHECK23// RUN: %clang_cc1 -triple x86_64-unknown-unknown -verify=c,expected -DRIGHT_JMP_BUF %s -ast-dump | FileCheck %s --check-prefixes=CHECK1,CHECK24// RUN: %clang_cc1 -triple x86_64-unknown-unknown -verify=c,expected -DONLY_JMP_BUF %s -ast-dump | FileCheck %s --check-prefixes=CHECK1,CHECK25// RUN: %clang_cc1 -triple x86_64-unknown-unknown -verify=c,expected -DNO_SETJMP %s -ast-dump 2>&1 | FileCheck %s --check-prefixes=CHECK1,CHECK26// RUN: %clang_cc1 -triple x86_64-unknown-unknown -verify=cxx,expected -x c++ -DNO_JMP_BUF %s -ast-dump | FileCheck %s --check-prefixes=CHECK1,CHECK27// RUN: %clang_cc1 -triple x86_64-unknown-unknown -verify=cxx,expected -x c++ -DWRONG_JMP_BUF %s -ast-dump | FileCheck %s --check-prefixes=CHECK1,CHECK28// RUN: %clang_cc1 -triple x86_64-unknown-unknown -verify=cxx,expected -x c++ -DRIGHT_JMP_BUF %s -ast-dump | FileCheck %s --check-prefixes=CHECK1,CHECK29// RUN: %clang_cc1 -triple x86_64-unknown-unknown -verify=cxx,expected -x c++ -DONLY_JMP_BUF %s -ast-dump | FileCheck %s --check-prefixes=CHECK210// RUN: %clang_cc1 -triple x86_64-unknown-unknown -verify=cxx,expected -x c++ -DNO_SETJMP %s -ast-dump | FileCheck %s --check-prefixes=CHECK211 12#ifdef __cplusplus13extern "C" {14#endif15 16#ifdef NO_JMP_BUF17// This happens in some versions of glibc: the declaration of __sigsetjmp18// precedes the declaration of sigjmp_buf.19extern long setjmp(long *); // Can't check, so we trust that this is the right type20// FIXME: We could still diagnose the missing `jmp_buf` at the point of the call.21// c-no-diagnostics22#elif WRONG_JMP_BUF23typedef long jmp_buf;24// FIXME: Consider producing a similar warning in C++.25extern int setjmp(char); // c-warning {{incompatible redeclaration of library function 'setjmp'}}26 // c-note@-1 {{'setjmp' is a builtin with type 'int (jmp_buf)' (aka 'int (long)')}}27#elif RIGHT_JMP_BUF28typedef long jmp_buf;29extern int setjmp(long); // OK, right type.30#elif ONLY_JMP_BUF31typedef int *jmp_buf;32#endif33 34void use(void) {35 setjmp(0);36 #if NO_SETJMP37 // cxx-error@-2 {{undeclared identifier 'setjmp'}}38 // c-error@-3 {{call to undeclared function 'setjmp'; ISO C99 and later do not support implicit function declarations}}39 #elif ONLY_JMP_BUF40 // cxx-error@-5 {{undeclared identifier 'setjmp'}}41 // c-error@-6 {{call to undeclared library function 'setjmp' with type 'int (jmp_buf)' (aka 'int (int *)'); ISO C99 and later do not support implicit function declarations}}42 // c-note@-7 {{include the header <setjmp.h> or explicitly provide a declaration for 'setjmp'}}43 #else44 // cxx-no-diagnostics45 #endif46 47 #ifdef NO_SETJMP48 // In this case, the regular AST dump doesn't dump the implicit declaration of 'setjmp'.49 #pragma clang __debug dump setjmp50 #endif51}52 53// CHECK1: FunctionDecl {{.*}} used setjmp54// CHECK1: BuiltinAttr {{.*}} Implicit55// CHECK1: ReturnsTwiceAttr {{.*}} Implicit56 57// mingw declares _setjmp with an unusual signature.58int _setjmp(void *, void *);59#if !defined(NO_JMP_BUF) && !defined(NO_SETJMP)60// c-warning@-2 {{incompatible redeclaration of library function '_setjmp'}}61// c-note@-3 {{'_setjmp' is a builtin with type 'int (jmp_buf)'}}62#endif63void use_mingw(void) {64 _setjmp(0, 0);65}66 67// CHECK2: FunctionDecl {{.*}} used _setjmp68// CHECK2: BuiltinAttr {{.*}} Implicit69// CHECK2: ReturnsTwiceAttr {{.*}} Implicit70 71#ifdef __cplusplus72}73#endif74