Implicit include of checked header files (#440)
* Support for implicit and explicit inclusion of checked header files. * Added comment header. * Removed redundant blank lines. * Fix to handle the presence of clang-specific declarations in header files plus the fix to push/pop checked scopes. * Modified header files to check for the __checkedc flag and added test cases. * Some header files like threads.h, unistd.h, arpa/inet.h and sys/socket.h may not be present in all compilation environments (Ex. Windows). Therefore, the wrapper header files and the Checked C header files should guard their inclusion using __has_include_next. This will also cause changes in the expected output of some test cases. * Incorporated review comments. * The Checked-C-specific declarations in assert_checked.h, stdlib_checked.h and inttypes_checked.h use the type wchar_t, whose definition is available in stddef.h. The file inttypes_checked.h includes stddef.h but the other two don't.
This commit is contained in:
Родитель
0426d49020
Коммит
f3af449e8b
|
@ -9,18 +9,30 @@
|
|||
|
||||
set(files
|
||||
assert_checked.h
|
||||
assert.h
|
||||
errno_checked.h
|
||||
errno.h
|
||||
fenv_checked.h
|
||||
fenv.h
|
||||
inttypes_checked.h
|
||||
inttypes_checked_internal.h
|
||||
math_checked.h
|
||||
math.h
|
||||
signal_checked.h
|
||||
signal.h
|
||||
stdchecked.h
|
||||
stdio_checked.h
|
||||
stdio.h
|
||||
stdlib_checked.h
|
||||
stdlib.h
|
||||
string_checked.h
|
||||
string.h
|
||||
threads_checked.h
|
||||
threads.h
|
||||
time_checked.h
|
||||
time.h
|
||||
unistd_checked.h
|
||||
unistd.h
|
||||
_builtin_stdio_checked.h
|
||||
_builtin_string_checked.h
|
||||
_builtin_common.h
|
||||
|
@ -29,10 +41,12 @@ set(files
|
|||
|
||||
set(posix_arpa_files
|
||||
arpa/inet_checked.h
|
||||
arpa/inet.h
|
||||
)
|
||||
|
||||
set(posix_sys_files
|
||||
sys/socket_checked.h
|
||||
sys/socket.h
|
||||
)
|
||||
|
||||
# Hack - compute the CLANG version from the LLVM version. The
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
// The Windows environment may not have arpa/inet.h
|
||||
#if defined __has_include_next
|
||||
#if __has_include_next(<arpa/inet.h>)
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <arpa/inet.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#endif // has inet.h
|
||||
#endif // defined __has_include_next
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <arpa/inet_checked.h>
|
||||
#endif
|
|
@ -5,28 +5,35 @@
|
|||
// These are POSIX-only //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
// The Windows environment may not have arpa/inet.h
|
||||
#if defined __has_include_next
|
||||
#if __has_include_next(<arpa/inet.h>)
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include_next <arpa/inet.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#ifndef __INET_CHECKED_H
|
||||
#define __INET_CHECKED_H
|
||||
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE ON
|
||||
#pragma CHECKED_SCOPE on
|
||||
|
||||
extern in_addr_t inet_addr (const char *__cp : itype(_Nt_array_ptr<const char>)) __THROW;
|
||||
|
||||
|
||||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif // guard
|
||||
#endif // Checked C
|
||||
|
||||
#endif // has inet.h
|
||||
#endif // defined __has_include_next
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <assert.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <assert_checked.h>
|
||||
#endif
|
|
@ -4,23 +4,24 @@
|
|||
// //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include_next <assert.h>
|
||||
#include <stddef.h> // define wchar_t for wcstoimax and wcstoumax
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#ifndef __ASSERT_CHECKED_H
|
||||
#define __ASSERT_CHECKED_H
|
||||
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE ON
|
||||
#pragma CHECKED_SCOPE on
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
_ACRTIMP void __cdecl _wassert(_In_z_ wchar_t const *_Message : itype(_Nt_array_ptr<const wchar_t>),
|
||||
|
@ -50,4 +51,4 @@ __THROW __attribute__ ((__noreturn__));
|
|||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif // guard
|
||||
#endif // no c++
|
||||
#endif // Checked C
|
||||
|
|
|
@ -4,11 +4,16 @@
|
|||
// choose to use these over the default bounds-safe interfaces. //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdlib_checked.h>
|
||||
#include <string_checked.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
|
||||
#ifndef __CHECKED_C_EXTENSIONS_H
|
||||
#define __CHECKED_C_EXTENSIONS_H
|
||||
|
||||
#include <stdlib_checked.h>
|
||||
#include <string_checked.h>
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE on
|
||||
|
||||
// default strncmp has a bounds-safe interface nt_array_ptr;
|
||||
// this option is for array_ptr
|
||||
|
@ -24,4 +29,7 @@ int snprintf_array_ptr(char * restrict s : itype(restrict _Array_ptr<char>) coun
|
|||
const char * restrict format : itype(restrict _Nt_array_ptr<const char>),
|
||||
...);
|
||||
|
||||
#endif /* __CHECKED_C_EXTENSIONS_H */
|
||||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif // guard
|
||||
#endif // Checked C
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <errno.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <errno_checked.h>
|
||||
#endif
|
|
@ -3,23 +3,23 @@
|
|||
// //
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include_next <errno.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#ifndef __ERRNO_CHECKED_H
|
||||
#define __ERRNO_CHECKED_H
|
||||
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE ON
|
||||
#pragma CHECKED_SCOPE on
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
__declspec(dllimport) int* __cdecl _errno(void) : itype(_Ptr<int>);
|
||||
|
@ -32,4 +32,4 @@ extern int* __errno_location(void) : itype(_Ptr<int>) __THROW __attribute_const_
|
|||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif // guards
|
||||
#endif // c++
|
||||
#endif // Checked C
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <fenv.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <fenv_checked.h>
|
||||
#endif
|
|
@ -6,23 +6,23 @@
|
|||
// specification. //
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <fenv.h>
|
||||
#include_next <fenv.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#ifndef __FENV_CHECKED_H
|
||||
#define __FENV_CHECKED_H
|
||||
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE ON
|
||||
#pragma CHECKED_SCOPE on
|
||||
|
||||
int fesetexceptflag(const fexcept_t *flagp : itype(_Ptr<const fexcept_t>),
|
||||
int excepts);
|
||||
|
@ -33,5 +33,5 @@ int feupdateenv(const fenv_t *envp : itype(_Ptr<const fenv_t>));
|
|||
|
||||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif // guard
|
||||
#endif // Checked C
|
||||
|
|
|
@ -1,58 +1,11 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Bounds-safe interfaces for functions in inttypes.h that //
|
||||
// take pointer arguments. //
|
||||
// //
|
||||
// These are listed in the same order that they occur in the C11 //
|
||||
// specification. //
|
||||
// Wrapper header file that includes Checked-C-specific declarations //
|
||||
// explicitly. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <stddef.h> // define wchar_t for wcstoimax and wcstoumax
|
||||
// Ensure that clang-specific declarations are included.
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifndef __INTTYPES_CHECKED_H
|
||||
#define __INTTYPES_CHECKED_H
|
||||
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE ON
|
||||
|
||||
_Unchecked
|
||||
intmax_t strtoimax(const char * restrict nptr :
|
||||
itype(restrict _Nt_array_ptr<const char>),
|
||||
char ** restrict endptr :
|
||||
itype(restrict _Ptr<_Nt_array_ptr<char>>),
|
||||
int base);
|
||||
_Unchecked
|
||||
uintmax_t strtoumax(const char * restrict nptr :
|
||||
itype(restrict _Nt_array_ptr<const char>),
|
||||
char ** restrict endptr :
|
||||
itype(restrict _Ptr<_Nt_array_ptr<char >>),
|
||||
int base);
|
||||
|
||||
_Unchecked
|
||||
intmax_t wcstoimax(const wchar_t * restrict nptr :
|
||||
itype(restrict _Nt_array_ptr<const wchar_t>),
|
||||
wchar_t ** restrict endptr :
|
||||
itype(restrict _Ptr<_Nt_array_ptr<wchar_t>>),
|
||||
int base);
|
||||
|
||||
_Unchecked
|
||||
uintmax_t wcstoumax(const wchar_t * restrict nptr :
|
||||
itype(restrict _Nt_array_ptr<const wchar_t>),
|
||||
wchar_t ** restrict endptr :
|
||||
itype(restrict _Ptr<_Nt_array_ptr<wchar_t>>),
|
||||
int base);
|
||||
|
||||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif // guard
|
||||
#endif // no c++
|
||||
// Ensure that Checked-C-specific declarations are included even if
|
||||
// implicit inclusion is disabled.
|
||||
#include <inttypes_checked_internal.h>
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Bounds-safe interfaces for functions in inttypes.h that //
|
||||
// take pointer arguments. //
|
||||
// //
|
||||
// These are listed in the same order that they occur in the C11 //
|
||||
// specification. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <stddef.h> // define wchar_t for wcstoimax and wcstoumax
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifdef __checkedc
|
||||
#ifndef __INTTYPES_CHECKED_H
|
||||
#define __INTTYPES_CHECKED_H
|
||||
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE on
|
||||
|
||||
_Unchecked
|
||||
intmax_t strtoimax(const char * restrict nptr :
|
||||
itype(restrict _Nt_array_ptr<const char>),
|
||||
char ** restrict endptr :
|
||||
itype(restrict _Ptr<_Nt_array_ptr<char>>),
|
||||
int base);
|
||||
_Unchecked
|
||||
uintmax_t strtoumax(const char * restrict nptr :
|
||||
itype(restrict _Nt_array_ptr<const char>),
|
||||
char ** restrict endptr :
|
||||
itype(restrict _Ptr<_Nt_array_ptr<char >>),
|
||||
int base);
|
||||
|
||||
_Unchecked
|
||||
intmax_t wcstoimax(const wchar_t * restrict nptr :
|
||||
itype(restrict _Nt_array_ptr<const wchar_t>),
|
||||
wchar_t ** restrict endptr :
|
||||
itype(restrict _Ptr<_Nt_array_ptr<wchar_t>>),
|
||||
int base);
|
||||
|
||||
_Unchecked
|
||||
uintmax_t wcstoumax(const wchar_t * restrict nptr :
|
||||
itype(restrict _Nt_array_ptr<const wchar_t>),
|
||||
wchar_t ** restrict endptr :
|
||||
itype(restrict _Ptr<_Nt_array_ptr<wchar_t>>),
|
||||
int base);
|
||||
|
||||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif // guard
|
||||
#endif // Checked C
|
|
@ -0,0 +1,23 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <math.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <math_checked.h>
|
||||
#endif
|
|
@ -6,23 +6,23 @@
|
|||
// specification. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include_next <math.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#ifndef __MATH_CHECKED_H
|
||||
#define __MATH_CHECKED_H
|
||||
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE ON
|
||||
#pragma CHECKED_SCOPE on
|
||||
|
||||
double frexp(double value, int *exp : itype(_Ptr<int>));
|
||||
float frexpf(float value, int *exp : itype(_Ptr<int>));
|
||||
|
@ -43,5 +43,5 @@ long double nanl(const char *t : itype(_Nt_array_ptr<const char>));
|
|||
|
||||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif //guard
|
||||
#endif // no c++
|
||||
#endif // guard
|
||||
#endif // Checked C
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <signal.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <signal_checked.h>
|
||||
#endif
|
|
@ -3,18 +3,18 @@
|
|||
// take pointer arguments. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
#include_next <signal.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#ifndef __SIGNAL_CHECKED_H
|
||||
#define __SIGNAL_CHECKED_H
|
||||
|
||||
|
@ -30,5 +30,5 @@ void (*signal(int sig,
|
|||
|
||||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif // guard
|
||||
#endif // Checked C
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <stdio.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <stdio_checked.h>
|
||||
#endif
|
|
@ -8,18 +8,18 @@
|
|||
// TODO: Better Support for _FORTIFY_SOURCE > 0 //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include_next <stdio.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#ifndef __STDIO_CHECKED_H
|
||||
#define __STDIO_CHECKED_H
|
||||
|
||||
|
@ -205,4 +205,4 @@ void perror(const char *s : itype(_Nt_array_ptr<const char>));
|
|||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif // guard
|
||||
#endif // no C++
|
||||
#endif // Checked C
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <stdlib.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <stdlib_checked.h>
|
||||
#endif
|
|
@ -6,18 +6,19 @@
|
|||
// specification. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include_next <stdlib.h>
|
||||
#include <stddef.h> // define wchar_t for wcstoimax and wcstoumax
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#ifndef __STDLIB_CHECKED_H
|
||||
#define __STDLIB_CHECKED_H
|
||||
|
||||
|
@ -125,4 +126,4 @@ size_t wcstombs(char * restrict output : count(n),
|
|||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif // guard
|
||||
#endif // no c++
|
||||
#endif // Checked C
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <string.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <string_checked.h>
|
||||
#endif
|
|
@ -11,24 +11,24 @@
|
|||
// TODO: Better Support for _FORTIFY_SOURCE > 0 //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include_next <string.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
|
||||
#ifndef __STRING_CHECKED_H
|
||||
#define __STRING_CHECKED_H
|
||||
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE ON
|
||||
#pragma CHECKED_SCOPE on
|
||||
|
||||
// GCC has macros that it uses as part of its string implementation to optimize cases
|
||||
// where one or both strings are compile-time constants. I'm not sure
|
||||
|
@ -173,4 +173,4 @@ char *strdup(const char *s : itype(_Nt_array_ptr<const char>)) : itype(_Nt_array
|
|||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif // guard
|
||||
#endif // no C++
|
||||
#endif // Checked C
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
// The Windows environment may not have sys/socket.h
|
||||
#if defined __has_include_next
|
||||
#if __has_include_next(<sys/socket.h>)
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <sys/socket.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#endif // has socket.h
|
||||
#endif // defined __has_include_next
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <sys/socket_checked.h>
|
||||
#endif
|
|
@ -1,26 +1,30 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Bounds-safe interfaces for functions in POSIX socket.h. //
|
||||
// Bounds-safe interfaces for functions in POSIX socket.h. //
|
||||
// //
|
||||
// //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
// The Windows environment may not have sys/socket.h
|
||||
#if defined __has_include_next
|
||||
#if __has_include_next(<sys/socket.h>)
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include_next <sys/socket.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#ifndef __SOCKET_CHECKED_H
|
||||
#define __SOCKET_CHECKED_H
|
||||
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE ON
|
||||
#pragma CHECKED_SCOPE on
|
||||
|
||||
#ifdef __APPLE__
|
||||
// Seems not to be a thing for Mac
|
||||
|
@ -134,4 +138,7 @@ extern int accept4 (
|
|||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif // guard
|
||||
#endif // C++
|
||||
#endif // Checked C
|
||||
|
||||
#endif // has socket.h
|
||||
#endif // defined __has_include_next
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
// C implementations may not support the C11 threads package or even the
|
||||
// macro that says C11 threads are not supported.
|
||||
#if defined __has_include_next
|
||||
#if __has_include_next(<threads.h>)
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <threads.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#endif // has threads.h
|
||||
#endif // defined __has_include_next
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <threads_checked.h>
|
||||
#endif
|
|
@ -23,23 +23,34 @@ typedef void (tss_dtor_t)(void *);
|
|||
struct timespec;
|
||||
#else
|
||||
|
||||
#ifndef __cplusplus
|
||||
#if defined __has_include_next
|
||||
#if __has_include_next(<threads.h>)
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
#include <threads.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include_next <threads.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#endif // has threads.h
|
||||
#endif // defined __has_include_next
|
||||
#endif // _CHECKEDC_MOCKUP_THREADS
|
||||
|
||||
|
||||
#if defined _CHECKEDC_MOCKUP_THREADS || \
|
||||
(defined __has_include_next && __has_include_next(<threads.h>))
|
||||
|
||||
#ifdef __checkedc
|
||||
#ifndef __THREADS_CHECKED_H
|
||||
#define __THREADS_CHECKED_H
|
||||
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE ON
|
||||
#pragma CHECKED_SCOPE on
|
||||
|
||||
void call_once(once_flag *flag : itype(_Ptr<once_flag>),
|
||||
void ((*fn)(void)) : itype(_Ptr<void (void)>));
|
||||
|
@ -82,4 +93,6 @@ int tss_set(tss_t key, void *value : itype(_Ptr<void>));
|
|||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif // guard
|
||||
#endif // no C++
|
||||
#endif // Checked C
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <time.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <time_checked.h>
|
||||
#endif
|
|
@ -6,23 +6,23 @@
|
|||
// specification. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
#include_next <time.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#ifndef __TIME_CHECKED_H
|
||||
#define __TIME_CHECKED_H
|
||||
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE ON
|
||||
#pragma CHECKED_SCOPE on
|
||||
|
||||
time_t mktime(struct tm *timeptr : itype(_Ptr<struct tm>));
|
||||
|
||||
|
@ -49,5 +49,5 @@ size_t strftime(char * restrict output : count(maxsize),
|
|||
|
||||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif // guard
|
||||
#endif // Checked C
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
//---------------------------------------------------------------------//
|
||||
// Wrapper header file that excludes Checked-C-specific declarations //
|
||||
// if the compilation is not for Checked C, or if is for Checked C //
|
||||
// but the implicit inclusion of checked header files is disabled. //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if !defined __checkedc || defined NO_IMPLICIT_INCLUDE_CHECKED_HDRS
|
||||
|
||||
// Uses clang-specific __has_include macro to detect unistd.h
|
||||
// which is required by Posix Standard.
|
||||
// The Windows environment also may not have unistd.h
|
||||
#if defined __has_include_next
|
||||
#if __has_include_next(<unistd.h>)
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include_next <unistd.h>
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#endif // has unistd.h
|
||||
#endif // defined __has_include_next
|
||||
|
||||
#else // checkedc && implicit include enabled
|
||||
#include <unistd_checked.h>
|
||||
#endif
|
|
@ -5,18 +5,25 @@
|
|||
// These are POSIX-only //
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
// Uses clang-specific __has_include macro to detect unistd.h
|
||||
// which is required by Posix Standard.
|
||||
// The Windows environment also may not have unistd.h
|
||||
#if defined __has_include_next
|
||||
#if __has_include_next(<unistd.h>)
|
||||
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE push
|
||||
#pragma CHECKED_SCOPE off
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include_next <unistd.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#pragma CHECKED_SCOPE pop
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifdef __checkedc
|
||||
#ifndef __UNISTD_CHECKED_H
|
||||
#define __UNISTD_CHECKED_H
|
||||
|
||||
|
@ -44,5 +51,8 @@ extern ssize_t write (int __fd, const void *__buf : byte_count(__n), size_t __n)
|
|||
|
||||
#pragma CHECKED_SCOPE pop
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif // guard
|
||||
#endif // Checked C
|
||||
|
||||
#endif // has unistd.h
|
||||
#endif // defined __has_include_next
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
// Feature tests of typechecking bounds-safe
|
||||
// interfaces for the C standard library.
|
||||
//
|
||||
// The following lines are for the LLVM test harness:
|
||||
//
|
||||
// Test include files in an unchecked scope
|
||||
//
|
||||
// RUN: %clang -fsyntax-only %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=0 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=1 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=2 %s
|
||||
//
|
||||
// Test include files in a checked scope.
|
||||
//
|
||||
// RUN: %clang -fsyntax-only -DCHECKED_SCOPE=1 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=0 -DCHECKED_SCOPE=1 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=1 -DCHECKED_SCOPE=1 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=2 -DCHECKED_SCOPE=1 %s
|
||||
|
||||
#if CHECKED_SCOPE
|
||||
#pragma CHECKED_SCOPE on
|
||||
#endif
|
||||
|
||||
// C Standard
|
||||
#include "../../include/assert_checked.h"
|
||||
#include "../../include/errno_checked.h"
|
||||
#include "../../include/fenv_checked.h"
|
||||
#include "../../include/inttypes_checked.h"
|
||||
#include "../../include/math_checked.h"
|
||||
#include "../../include/signal_checked.h"
|
||||
#include "../../include/stdio_checked.h"
|
||||
#include "../../include/stdlib_checked.h"
|
||||
#include "../../include/string_checked.h"
|
||||
#define _CHECKEDC_MOCKUP_THREADS 1
|
||||
#include "../../include/threads_checked.h"
|
||||
#include "../../include/time_checked.h"
|
||||
#include "../../include/checkedc_extensions.h"
|
||||
|
||||
// Posix Headers
|
||||
//
|
||||
// Uses clang-specific __has_include macro to detect unistd.h
|
||||
// which is required by Posix Standard.
|
||||
#if defined(__has_include)
|
||||
#if __has_include(<unistd.h>)
|
||||
#include "../../include/unistd_checked.h"
|
||||
#endif
|
||||
|
||||
#if __has_include(<sys/socket.h>)
|
||||
#include "../../include/sys/socket_checked.h"
|
||||
#endif
|
||||
|
||||
#if __has_include(<arpa/inet.h>)
|
||||
#include "../../include/arpa/inet_checked.h"
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,120 @@
|
|||
// Feature tests of typechecking bounds-safe
|
||||
// interfaces for the C standard library.
|
||||
//
|
||||
// The following lines are for the LLVM test harness:
|
||||
//
|
||||
// Test include files in an unchecked scope
|
||||
//
|
||||
// RUN: %clang -fsyntax-only %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=0 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=1 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=2 %s
|
||||
//
|
||||
// Test include files in a checked scope.
|
||||
//
|
||||
// RUN: %clang -fsyntax-only -DCHECKED_SCOPE=1 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=0 -DCHECKED_SCOPE=1 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=1 -DCHECKED_SCOPE=1 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=2 -DCHECKED_SCOPE=1 %s
|
||||
//
|
||||
// Test include files for all combinations of Checked C enabled/disabled,
|
||||
// and implicit inclusion of checked headers enabled/disabled. By default, both
|
||||
// are enabled.
|
||||
//
|
||||
// Checked headers are disabled for no Checked C.
|
||||
// RUN: %clang -fno-checkedc-extension -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
// RUN: %clang -fno-checkedc-extension -DNO_IMPLICIT_INCLUDE_CHECKED_HDRS -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
//
|
||||
// Checked headers are enabled for Checked C and implicit inclusion.
|
||||
// RUN: %clang -E %s | FileCheck %s --check-prefix CHECK_ENABLED
|
||||
//
|
||||
// Checked headers are enabled because explicit inclusion overrides the
|
||||
// disabling of implicit inclusion.
|
||||
// RUN: %clang -DNO_IMPLICIT_INCLUDE_CHECKED_HDRS -E %s | FileCheck %s --check-prefix CHECK_ENABLED
|
||||
|
||||
|
||||
#if CHECKED_SCOPE
|
||||
#pragma CHECKED_SCOPE on
|
||||
#endif
|
||||
|
||||
// C Standard
|
||||
#include <assert_checked.h>
|
||||
// CHECK_ENABLED: assert_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: assert_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <errno_checked.h>
|
||||
// CHECK_ENABLED: errno_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: errno_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <fenv_checked.h>
|
||||
// CHECK_ENABLED: fenv_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: fenv_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <inttypes_checked.h>
|
||||
// CHECK_ENABLED: inttypes_checked_internal.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: inttypes_checked_internal.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <math_checked.h>
|
||||
// CHECK_ENABLED: math_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: math_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <signal_checked.h>
|
||||
// CHECK_ENABLED: signal_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: signal_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <stdio_checked.h>
|
||||
// CHECK_ENABLED: stdio_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: stdio_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <stdlib_checked.h>
|
||||
// CHECK_ENABLED: stdlib_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: stdlib_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <string_checked.h>
|
||||
// CHECK_ENABLED: string_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: string_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#define _CHECKEDC_MOCKUP_THREADS 1
|
||||
#include <threads_checked.h>
|
||||
// CHECK_ENABLED: threads_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: threads_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <time_checked.h>
|
||||
// CHECK_ENABLED: time_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: time_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <checkedc_extensions.h>
|
||||
// CHECK_ENABLED: checkedc_extensions.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: checkedc_extensions.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
|
||||
|
||||
// Posix Headers
|
||||
// These header files may or may not be present in all environments.
|
||||
#include <unistd_checked.h>
|
||||
#include <sys/socket_checked.h>
|
||||
#include <arpa/inet_checked.h>
|
|
@ -0,0 +1,42 @@
|
|||
// UNSUPPORTED: system-windows
|
||||
//
|
||||
// Test include files for all combinations of Checked C enabled/disabled,
|
||||
// and implicit inclusion of checked headers enabled/disabled. By default, both
|
||||
// are enabled.
|
||||
//
|
||||
// Checked headers are disabled for no Checked C.
|
||||
// RUN: %clang -fno-checkedc-extension -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
// RUN: %clang -fno-checkedc-extension -DNO_IMPLICIT_INCLUDE_CHECKED_HDRS -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
//
|
||||
// Checked headers are enabled for Checked C and implicit inclusion.
|
||||
// RUN: %clang -E %s | FileCheck %s --check-prefix CHECK_ENABLED
|
||||
//
|
||||
// Checked headers are enabled because explicit inclusion overrides the
|
||||
// disabling of implicit inclusion.
|
||||
// RUN: %clang -DNO_IMPLICIT_INCLUDE_CHECKED_HDRS -E %s | FileCheck %s --check-prefix CHECK_ENABLED
|
||||
|
||||
|
||||
#if CHECKED_SCOPE
|
||||
#pragma CHECKED_SCOPE on
|
||||
#endif
|
||||
|
||||
|
||||
// Posix Headers
|
||||
// These header files are not present in the Windows compilation environment.
|
||||
#include <unistd_checked.h>
|
||||
// CHECK_ENABLED: unistd_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: unistd_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <sys/socket_checked.h>
|
||||
// CHECK_ENABLED: socket_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: socket_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <arpa/inet_checked.h>
|
||||
// CHECK_ENABLED: inet_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED: inet_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
|
@ -0,0 +1,113 @@
|
|||
// Feature tests of typechecking bounds-safe
|
||||
// interfaces for the C standard library.
|
||||
//
|
||||
// The following lines are for the LLVM test harness:
|
||||
//
|
||||
// Test include files in an unchecked scope
|
||||
//
|
||||
// RUN: %clang -fsyntax-only %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=0 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=1 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=2 %s
|
||||
//
|
||||
// Test include files in a checked scope.
|
||||
//
|
||||
// RUN: %clang -fsyntax-only -DCHECKED_SCOPE=1 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=0 -DCHECKED_SCOPE=1 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=1 -DCHECKED_SCOPE=1 %s
|
||||
// RUN: %clang -fsyntax-only -D_FORTIFY_SOURCE=2 -DCHECKED_SCOPE=1 %s
|
||||
//
|
||||
// Test include files for all combinations of Checked C enabled/disabled,
|
||||
// and implicit inclusion of checked headers enabled/disabled. By default, both
|
||||
// are enabled.
|
||||
//
|
||||
// Checked headers are disabled for no Checked C.
|
||||
// RUN: %clang -fno-checkedc-extension -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
// RUN: %clang -fno-checkedc-extension -DNO_IMPLICIT_INCLUDE_CHECKED_HDRS -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
//
|
||||
// Checked headers are enabled for Checked C and implicit inclusion.
|
||||
// RUN: %clang -E %s | FileCheck %s --check-prefix CHECK_ENABLED
|
||||
//
|
||||
// Checked headers are disabled because implicit inclusion is disabled.
|
||||
// RUN: %clang -DNO_IMPLICIT_INCLUDE_CHECKED_HDRS -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
|
||||
|
||||
#if CHECKED_SCOPE
|
||||
#pragma CHECKED_SCOPE on
|
||||
#endif
|
||||
|
||||
// C Standard
|
||||
#include <assert.h>
|
||||
// CHECK_ENABLED: assert_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: assert_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <errno.h>
|
||||
// CHECK_ENABLED: errno_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: errno_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <fenv.h>
|
||||
// CHECK_ENABLED: fenv_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: fenv_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <inttypes.h>
|
||||
// CHECK_ENABLED: inttypes_checked_internal.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: inttypes_checked_internal.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <math.h>
|
||||
// CHECK_ENABLED: math_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: math_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <signal.h>
|
||||
// CHECK_ENABLED: signal_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: signal_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <stdio.h>
|
||||
// CHECK_ENABLED: stdio_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: stdio_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <stdlib.h>
|
||||
// CHECK_ENABLED: stdlib_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: stdlib_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <string.h>
|
||||
// CHECK_ENABLED: string_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: string_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#define _CHECKEDC_MOCKUP_THREADS 1
|
||||
#include <threads.h>
|
||||
// CHECK_ENABLED: threads_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: threads_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <time.h>
|
||||
// CHECK_ENABLED: time_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: time_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
|
||||
|
||||
// Posix Headers
|
||||
// These header files may or may not be present in all environments.
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
|
@ -0,0 +1,36 @@
|
|||
// UNSUPPORTED: system-windows
|
||||
//
|
||||
// Test include files for all combinations of Checked C enabled/disabled,
|
||||
// and implicit inclusion of checked headers enabled/disabled. By default, both
|
||||
// are enabled.
|
||||
//
|
||||
// Checked headers are disabled for no Checked C.
|
||||
// RUN: %clang -fno-checkedc-extension -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
// RUN: %clang -fno-checkedc-extension -DNO_IMPLICIT_INCLUDE_CHECKED_HDRS -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
//
|
||||
// Checked headers are enabled for Checked C and implicit inclusion.
|
||||
// RUN: %clang -E %s | FileCheck %s --check-prefix CHECK_ENABLED
|
||||
//
|
||||
// Checked headers are disabled because implicit inclusion is disabled.
|
||||
// RUN: %clang -DNO_IMPLICIT_INCLUDE_CHECKED_HDRS -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
|
||||
|
||||
// Posix Headers
|
||||
// These header files are not present in the Windows compilation environment.
|
||||
#include <unistd.h>
|
||||
// CHECK_ENABLED: unistd_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: unistd_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <sys/socket.h>
|
||||
// CHECK_ENABLED: socket_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: socket_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <arpa/inet.h>
|
||||
// CHECK_ENABLED: inet_checked.h
|
||||
// CHECK_ENABLED: #pragma CHECKED_SCOPE on
|
||||
// CHECK_DISABLED-NOT: inet_checked.h
|
||||
// CHECK_DISABLED-NOT: #pragma CHECKED_SCOPE on
|
|
@ -0,0 +1,77 @@
|
|||
// Feature tests of typechecking bounds-safe
|
||||
// interfaces for the C standard library.
|
||||
//
|
||||
// Test include files for all combinations of Checked C enabled/disabled,
|
||||
// and implicit inclusion of checked headers enabled/disabled. By default, both
|
||||
// are enabled.
|
||||
//
|
||||
// Checked headers are disabled for no Checked C.
|
||||
// Already tested in redeclare_libs_explicit.c and redeclare_libs_implicit.c.
|
||||
// %clang -fno-checkedc-extension -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
// %clang -fno-checkedc-extension -DNO_IMPLICIT_INCLUDE_CHECKED_HDRS -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
//
|
||||
// Checked headers are enabled for Checked C and implicit inclusion.
|
||||
// Already tested in redeclare_libs_explicit.c and redeclare_libs_implicit.c.
|
||||
// %clang -E %s | FileCheck %s --check-prefix CHECK_ENABLED
|
||||
//
|
||||
// Checked headers are enabled/disabled depending on whether foo.h or
|
||||
// foo_checked.h is included for a system header file foo.h.
|
||||
// RUN: %clang -DNO_IMPLICIT_INCLUDE_CHECKED_HDRS -E %s | FileCheck %s --check-prefix CHECK_MIXED
|
||||
|
||||
|
||||
// C Standard
|
||||
#include <assert_checked.h>
|
||||
// CHECK_MIXED: assert_checked.h
|
||||
// CHECK_MIXED: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <errno.h>
|
||||
// CHECK_MIXED-NOT: errno_checked.h
|
||||
// CHECK_MIXED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <fenv_checked.h>
|
||||
// CHECK_MIXED: fenv_checked.h
|
||||
// CHECK_MIXED: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <inttypes.h>
|
||||
// CHECK_MIXED-NOT: inttypes_checked_internal.h
|
||||
// CHECK_MIXED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <math_checked.h>
|
||||
// CHECK_MIXED: math_checked.h
|
||||
// CHECK_MIXED: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <signal.h>
|
||||
// CHECK_MIXED-NOT: signal_checked.h
|
||||
// CHECK_MIXED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <stdio_checked.h>
|
||||
// CHECK_MIXED: stdio_checked.h
|
||||
// CHECK_MIXED: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <stdlib.h>
|
||||
// CHECK_MIXED-NOT: stdlib_checked.h
|
||||
// CHECK_MIXED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <string_checked.h>
|
||||
// CHECK_MIXED: string_checked.h
|
||||
// CHECK_MIXED: #pragma CHECKED_SCOPE on
|
||||
|
||||
#define _CHECKEDC_MOCKUP_THREADS 1
|
||||
#include <threads.h>
|
||||
// CHECK_MIXED-NOT: threads_checked.h
|
||||
// CHECK_MIXED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <time_checked.h>
|
||||
// CHECK_MIXED: time_checked.h
|
||||
// CHECK_MIXED: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <checkedc_extensions.h>
|
||||
// CHECK_MIXED: checkedc_extensions.h
|
||||
// CHECK_MIXED: #pragma CHECKED_SCOPE on
|
||||
|
||||
|
||||
// Posix Headers
|
||||
// These header files may or may not be present in all environments.
|
||||
#include <unistd_checked.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet_checked.h>
|
|
@ -0,0 +1,33 @@
|
|||
// UNSUPPORTED: system-windows
|
||||
//
|
||||
// Test include files for all combinations of Checked C enabled/disabled,
|
||||
// and implicit inclusion of checked headers enabled/disabled. By default, both
|
||||
// are enabled.
|
||||
//
|
||||
// Checked headers are disabled for no Checked C.
|
||||
// Already tested in redeclare_libs_explicit.c and redeclare_libs_implicit.c.
|
||||
// %clang -fno-checkedc-extension -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
// %clang -fno-checkedc-extension -DNO_IMPLICIT_INCLUDE_CHECKED_HDRS -E %s | FileCheck %s --check-prefix CHECK_DISABLED
|
||||
//
|
||||
// Checked headers are enabled for Checked C and implicit inclusion.
|
||||
// Already tested in redeclare_libs_explicit.c and redeclare_libs_implicit.c.
|
||||
// %clang -E %s | FileCheck %s --check-prefix CHECK_ENABLED
|
||||
//
|
||||
// Checked headers are enabled/disabled depending on whether foo.h or
|
||||
// foo_checked.h is included for a system header file foo.h.
|
||||
// RUN: %clang -DNO_IMPLICIT_INCLUDE_CHECKED_HDRS -E %s | FileCheck %s --check-prefix CHECK_MIXED
|
||||
|
||||
|
||||
// Posix Headers
|
||||
// These header files are not present in the Windows compilation environment.
|
||||
#include <unistd_checked.h>
|
||||
// CHECK_MIXED: unistd_checked.h
|
||||
// CHECK_MIXED: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <sys/socket.h>
|
||||
// CHECK_MIXED-NOT: socket_checked.h
|
||||
// CHECK_MIXED-NOT: #pragma CHECKED_SCOPE on
|
||||
|
||||
#include <arpa/inet_checked.h>
|
||||
// CHECK_MIXED: inet_checked.h
|
||||
// CHECK_MIXED: #pragma CHECKED_SCOPE on
|
Загрузка…
Ссылка в новой задаче