1include "config/public_api.td" 2 3include "spec/bsd_ext.td" 4include "spec/gnu_ext.td" 5include "spec/linux.td" 6include "spec/llvm_libc_ext.td" 7include "spec/posix.td" 8include "spec/stdc.td" 9 10def AssertMacro : MacroDef<"assert"> { 11 let Defn = [{ 12 #undef assert 13 14 #ifdef NDEBUG 15 #define assert(e) (void)0 16 #else 17 18 #ifdef __cplusplus 19 extern "C" 20 #endif 21 _Noreturn void __assert_fail(const char *, const char *, unsigned, const char *); 22 23 #define assert(e) \ 24 ((e) ? (void)0 : __assert_fail(#e, __FILE__, __LINE__, __PRETTY_FUNCTION__)) 25 26 #endif 27 }]; 28} 29 30def StaticAssertMacro : MacroDef<"static_assert"> { 31 let Defn = [{ 32 #ifndef __cplusplus 33 #undef static_assert 34 #define static_assert _Static_assert 35 #endif 36 }]; 37} 38 39def NullMacro : MacroDef<"NULL"> { 40 let Defn = [{ 41 #define __need_NULL 42 #include <stddef.h> 43 }]; 44} 45 46def ErrnoMacro : MacroDef<"errno"> { 47 let Defn = [{ 48 extern _Thread_local int __llvmlibc_errno; 49 #define errno __llvmlibc_errno 50 }]; 51} 52 53def AssertAPI : PublicAPI<"assert.h"> { 54 let Macros = [ 55 AssertMacro, 56 StaticAssertMacro, 57 ]; 58} 59 60def CTypeAPI : PublicAPI<"ctype.h"> { 61} 62 63def FCntlAPI : PublicAPI<"fcntl.h"> { 64 let Types = ["mode_t"]; 65} 66 67def IntTypesAPI : PublicAPI<"inttypes.h"> { 68 let Types = ["imaxdiv_t"]; 69} 70 71def MathErrHandlingMacro : MacroDef<"math_errhandling"> { 72 let Defn = [{ 73 #ifndef math_errhandling 74 #ifdef __FAST_MATH__ 75 #define math_errhandling 0 76 #elif defined __NO_MATH_ERRNO__ 77 #define math_errhandling (MATH_ERREXCEPT) 78 #else 79 #define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT) 80 #endif 81 #endif // math_errhandling not defined 82 }]; 83} 84 85def IsFiniteMacro : MacroDef<"isfinite"> { 86 let Defn = [{ 87 #define isfinite(x) __builtin_isfinite(x) 88 }]; 89} 90 91def IsInfMacro : MacroDef<"isinf"> { 92 let Defn = [{ 93 #define isinf(x) __builtin_isinf(x) 94 }]; 95} 96 97def IsNanMacro : MacroDef<"isnan"> { 98 let Defn = [{ 99 #define isnan(x) __builtin_isnan(x) 100 }]; 101} 102 103def MathAPI : PublicAPI<"math.h"> { 104 let Macros = [ 105 SimpleMacroDef<"MATH_ERRNO", "1">, 106 SimpleMacroDef<"MATH_ERREXCEPT", "2">, 107 MathErrHandlingMacro, 108 109 SimpleMacroDef<"INFINITY", "__builtin_inff()">, 110 SimpleMacroDef<"NAN", "__builtin_nanf(\"\")">, 111 112 SimpleMacroDef<"FP_ILOGB0", "(-__INT_MAX__ - 1)">, // INT_MIN 113 SimpleMacroDef<"FP_ILOGBNAN", "__INT_MAX__">, 114 115 IsFiniteMacro, 116 IsInfMacro, 117 IsNanMacro, 118 ]; 119 let Types = ["double_t", "float_t"]; 120} 121 122def FenvAPI: PublicAPI<"fenv.h"> { 123 let Macros = [ 124 SimpleMacroDef<"FE_DIVBYZERO", "1">, 125 SimpleMacroDef<"FE_INEXACT", "2">, 126 SimpleMacroDef<"FE_INVALID", "4">, 127 SimpleMacroDef<"FE_OVERFLOW", "8">, 128 SimpleMacroDef<"FE_UNDERFLOW", "16">, 129 SimpleMacroDef<"FE_ALL_EXCEPT", "(FE_DIVBYZERO|FE_INEXACT|FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW)">, 130 131 SimpleMacroDef<"FE_DOWNWARD", "1">, 132 SimpleMacroDef<"FE_TONEAREST", "2">, 133 SimpleMacroDef<"FE_TOWARDZERO", "4">, 134 SimpleMacroDef<"FE_UPWARD", "8">, 135 136 SimpleMacroDef<"FE_DFL_ENV", "((fenv_t *)-1)">, 137 ]; 138 let Types = ["fenv_t", "fexcept_t"]; 139} 140 141def StringAPI : PublicAPI<"string.h"> { 142 let Types = ["size_t"]; 143 144 let Macros = [ 145 NullMacro, 146 ]; 147} 148 149def StdIOAPI : PublicAPI<"stdio.h"> { 150 let Macros = [ 151 SimpleMacroDef<"stderr", "stderr">, 152 SimpleMacroDef<"stdout", "stdout">, 153 ]; 154 let Types = ["size_t", "FILE", "cookie_io_functions_t"]; 155} 156 157def StdlibAPI : PublicAPI<"stdlib.h"> { 158 let Types = [ 159 "div_t", 160 "ldiv_t", 161 "lldiv_t", 162 "size_t", 163 "__bsearchcompare_t", 164 "__qsortcompare_t", 165 "__atexithandler_t", 166 ]; 167} 168 169def TimeAPI : PublicAPI<"time.h"> { 170 let Types = ["time_t", "struct tm"]; 171} 172 173def ErrnoAPI : PublicAPI<"errno.h"> { 174 let Macros = [ 175 ErrnoMacro, 176 // We largely depend on linux/errno.h to give us the 177 // various error macro definitions. However, some libc 178 // implementations have chosen to provide definitions 179 // for some of the error macros to account for the ones 180 // missing in linux/errno.h. There is no harm in doing 181 // the same here if we define the macros only when they 182 // are not already defined. 183 MacroDefineIfNot<"ENOTSUP", "EOPNOTSUPP">, 184 MacroDefineIfNot<"ECANCELED", "125">, 185 MacroDefineIfNot<"EOWNERDEAD", "130">, 186 MacroDefineIfNot<"ENOTRECOVERABLE", "131">, 187 MacroDefineIfNot<"ERFKILL", "132">, 188 MacroDefineIfNot<"EHWPOISON", "133">, 189 ]; 190} 191 192def SysMManAPI : PublicAPI<"sys/mman.h"> { 193 let Types = ["off_t", "size_t"]; 194 let Macros = [ 195 SimpleMacroDef<"PROT_NONE", "0">, 196 SimpleMacroDef<"PROT_READ", "1">, 197 SimpleMacroDef<"PROT_WRITE", "2">, 198 SimpleMacroDef<"PROT_EXEC", "4">, 199 200 SimpleMacroDef<"MAP_FIXED", "1">, 201 SimpleMacroDef<"MAP_PRIVATE", "2">, 202 SimpleMacroDef<"MAP_SHARED", "4">, 203 204 SimpleMacroDef<"MAP_FAILED", "((void*)-1)">, 205 206 // TODO: The value of 0x20 is good for x86_64, but has to be extended 207 // in some manner to accommodate other machine architectures. 208 SimpleMacroDef<"MAP_ANONYMOUS", "0x20"> 209 210 // TODO: Add other MAP_* macros used by Linux. 211 ]; 212 213} 214 215def SignalAPI : PublicAPI<"signal.h"> { 216 let Types = ["struct sigaction", "__sighandler_t"]; 217} 218 219def ThreadsAPI : PublicAPI<"threads.h"> { 220 let Macros = [ 221 SimpleMacroDef<"ONCE_FLAG_INIT", "{0}">, 222 ]; 223 224 let Types = [ 225 "__call_once_func_t", 226 "once_flag", 227 "cnd_t", 228 "mtx_t", 229 "thrd_t", 230 "thrd_start_t", 231 ]; 232 233 let Enumerations = [ 234 "mtx_plain", 235 "mtx_recursive", 236 "mtx_timed", 237 "thrd_timedout", 238 "thrd_success", 239 "thrd_busy", 240 "thrd_error", 241 "thrd_nomem", 242 ]; 243} 244 245def PThreadAPI : PublicAPI<"pthread.h"> { 246 let Types = [ 247 "__pthread_start_t", 248 "pthread_attr_t", 249 "pthread_mutex_t", 250 "pthread_mutexattr_t", 251 "pthread_t", 252 ]; 253} 254 255def UniStdAPI : PublicAPI<"unistd.h"> { 256 let Types = ["off_t", "size_t", "ssize_t"]; 257} 258 259def SysStatAPI : PublicAPI<"sys/stat.h"> { 260 let Types = ["mode_t"]; 261} 262