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 SimpleMacroDef<"_IOFBF", "0">, 154 SimpleMacroDef<"_IOLBF", "1">, 155 SimpleMacroDef<"_IONBF", "2">, 156 ]; 157 let Types = ["size_t", "FILE", "cookie_io_functions_t"]; 158} 159 160def StdlibAPI : PublicAPI<"stdlib.h"> { 161 let Types = [ 162 "div_t", 163 "ldiv_t", 164 "lldiv_t", 165 "size_t", 166 "__bsearchcompare_t", 167 "__qsortcompare_t", 168 "__atexithandler_t", 169 ]; 170} 171 172def TimeAPI : PublicAPI<"time.h"> { 173 let Types = ["time_t", "struct tm"]; 174} 175 176def ErrnoAPI : PublicAPI<"errno.h"> { 177 let Macros = [ 178 ErrnoMacro, 179 // We largely depend on linux/errno.h to give us the 180 // various error macro definitions. However, some libc 181 // implementations have chosen to provide definitions 182 // for some of the error macros to account for the ones 183 // missing in linux/errno.h. There is no harm in doing 184 // the same here if we define the macros only when they 185 // are not already defined. 186 MacroDefineIfNot<"ENOTSUP", "EOPNOTSUPP">, 187 MacroDefineIfNot<"ECANCELED", "125">, 188 MacroDefineIfNot<"EOWNERDEAD", "130">, 189 MacroDefineIfNot<"ENOTRECOVERABLE", "131">, 190 MacroDefineIfNot<"ERFKILL", "132">, 191 MacroDefineIfNot<"EHWPOISON", "133">, 192 ]; 193} 194 195def SysMManAPI : PublicAPI<"sys/mman.h"> { 196 let Types = ["off_t", "size_t"]; 197 let Macros = [ 198 SimpleMacroDef<"PROT_NONE", "0">, 199 SimpleMacroDef<"PROT_READ", "1">, 200 SimpleMacroDef<"PROT_WRITE", "2">, 201 SimpleMacroDef<"PROT_EXEC", "4">, 202 203 SimpleMacroDef<"MAP_FIXED", "1">, 204 SimpleMacroDef<"MAP_PRIVATE", "2">, 205 SimpleMacroDef<"MAP_SHARED", "4">, 206 207 SimpleMacroDef<"MAP_FAILED", "((void*)-1)">, 208 209 // TODO: The value of 0x20 is good for x86_64, but has to be extended 210 // in some manner to accommodate other machine architectures. 211 SimpleMacroDef<"MAP_ANONYMOUS", "0x20"> 212 213 // TODO: Add other MAP_* macros used by Linux. 214 ]; 215 216} 217 218def SignalAPI : PublicAPI<"signal.h"> { 219 let Types = ["struct sigaction", "__sighandler_t"]; 220} 221 222def ThreadsAPI : PublicAPI<"threads.h"> { 223 let Macros = [ 224 SimpleMacroDef<"ONCE_FLAG_INIT", "{0}">, 225 ]; 226 227 let Types = [ 228 "__call_once_func_t", 229 "once_flag", 230 "cnd_t", 231 "mtx_t", 232 "thrd_t", 233 "thrd_start_t", 234 ]; 235 236 let Enumerations = [ 237 "mtx_plain", 238 "mtx_recursive", 239 "mtx_timed", 240 "thrd_timedout", 241 "thrd_success", 242 "thrd_busy", 243 "thrd_error", 244 "thrd_nomem", 245 ]; 246} 247 248def PThreadAPI : PublicAPI<"pthread.h"> { 249 let Types = [ 250 "__pthread_start_t", 251 "pthread_attr_t", 252 "pthread_mutex_t", 253 "pthread_mutexattr_t", 254 "pthread_t", 255 ]; 256} 257 258def DirentAPI : PublicAPI<"dirent.h"> { 259 let Types = [ 260 "ino_t", 261 "DIR", 262 "struct dirent", 263 ]; 264} 265 266def UniStdAPI : PublicAPI<"unistd.h"> { 267 let Types = ["off_t", "size_t", "ssize_t"]; 268} 269 270def SysStatAPI : PublicAPI<"sys/stat.h"> { 271 let Types = ["mode_t"]; 272} 273