@zigc/lib 0.16.0-test.1 → 0.17.0-dev.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/LICENSE +19 -0
  2. package/c/math.zig +135 -35
  3. package/c/stropts.zig +17 -0
  4. package/c.zig +1 -0
  5. package/compiler/aro/aro/Attribute/names.zig +604 -589
  6. package/compiler/aro/aro/Attribute.zig +202 -116
  7. package/compiler/aro/aro/Builtins/common.zig +874 -863
  8. package/compiler/aro/aro/Builtins/eval.zig +15 -7
  9. package/compiler/aro/aro/Builtins.zig +0 -1
  10. package/compiler/aro/aro/CodeGen.zig +3 -1
  11. package/compiler/aro/aro/Compilation.zig +120 -97
  12. package/compiler/aro/aro/Diagnostics.zig +21 -17
  13. package/compiler/aro/aro/Driver/GCCDetector.zig +635 -0
  14. package/compiler/aro/aro/Driver.zig +124 -50
  15. package/compiler/aro/aro/LangOpts.zig +12 -2
  16. package/compiler/aro/aro/Parser/Diagnostic.zig +79 -19
  17. package/compiler/aro/aro/Parser.zig +336 -142
  18. package/compiler/aro/aro/Preprocessor/Diagnostic.zig +21 -0
  19. package/compiler/aro/aro/Preprocessor.zig +127 -56
  20. package/compiler/aro/aro/Target.zig +17 -12
  21. package/compiler/aro/aro/Tokenizer.zig +31 -14
  22. package/compiler/aro/aro/Toolchain.zig +4 -7
  23. package/compiler/aro/aro/Tree.zig +178 -148
  24. package/compiler/aro/aro/TypeStore.zig +82 -24
  25. package/compiler/aro/aro/Value.zig +13 -17
  26. package/compiler/aro/aro/features.zig +1 -0
  27. package/compiler/aro/aro/pragmas/once.zig +0 -1
  28. package/compiler/aro/aro/record_layout.zig +3 -3
  29. package/compiler/aro/assembly_backend/x86_64.zig +3 -4
  30. package/compiler/aro/backend/Assembly.zig +1 -2
  31. package/compiler/aro/backend/Interner.zig +2 -2
  32. package/compiler/aro/backend/Ir.zig +100 -92
  33. package/compiler/aro/include/ptrcheck.h +49 -0
  34. package/compiler/aro/main.zig +26 -10
  35. package/compiler/build_runner.zig +1 -0
  36. package/compiler/objdump.zig +93 -0
  37. package/compiler/reduce.zig +5 -1
  38. package/compiler/resinator/compile.zig +2 -2
  39. package/compiler/resinator/main.zig +7 -1
  40. package/compiler/resinator/preprocess.zig +1 -3
  41. package/compiler/std-docs.zig +8 -1
  42. package/compiler/test_runner.zig +193 -61
  43. package/compiler/translate-c/MacroTranslator.zig +80 -11
  44. package/compiler/translate-c/PatternList.zig +1 -9
  45. package/compiler/translate-c/Scope.zig +43 -6
  46. package/compiler/translate-c/Translator.zig +364 -126
  47. package/compiler/translate-c/ast.zig +19 -11
  48. package/compiler/translate-c/main.zig +75 -16
  49. package/compiler_rt/cos.zig +141 -52
  50. package/compiler_rt/limb64.zig +266 -0
  51. package/compiler_rt/long_double.zig +37 -0
  52. package/compiler_rt/mulo.zig +6 -1
  53. package/compiler_rt/rem_pio2l.zig +173 -0
  54. package/compiler_rt/sin.zig +140 -55
  55. package/compiler_rt/sincos.zig +279 -72
  56. package/compiler_rt/tan.zig +118 -47
  57. package/compiler_rt/trig.zig +256 -6
  58. package/compiler_rt.zig +2 -0
  59. package/fuzzer.zig +855 -307
  60. package/libc/musl/src/math/pow.c +343 -0
  61. package/package.json +1 -1
  62. package/std/Build/Fuzz.zig +6 -19
  63. package/std/Build/Module.zig +1 -1
  64. package/std/Build/Step/CheckObject.zig +3 -3
  65. package/std/Build/Step/Compile.zig +18 -0
  66. package/std/Build/Step/ConfigHeader.zig +49 -33
  67. package/std/Build/Step/InstallArtifact.zig +18 -0
  68. package/std/Build/Step/Run.zig +536 -87
  69. package/std/Build/Step/TranslateC.zig +0 -6
  70. package/std/Build/Step.zig +8 -15
  71. package/std/Build/WebServer.zig +29 -17
  72. package/std/Build/abi.zig +47 -11
  73. package/std/Build.zig +17 -14
  74. package/std/Io/Dispatch.zig +2 -0
  75. package/std/Io/File/Reader.zig +3 -1
  76. package/std/Io/File.zig +1 -0
  77. package/std/Io/Kqueue.zig +2 -2
  78. package/std/Io/Threaded.zig +181 -143
  79. package/std/Io/Uring.zig +2 -1
  80. package/std/Io.zig +970 -2
  81. package/std/Target.zig +3 -2
  82. package/std/Thread.zig +8 -3
  83. package/std/array_hash_map.zig +96 -555
  84. package/std/array_list.zig +22 -31
  85. package/std/bit_set.zig +22 -6
  86. package/std/builtin/assembly.zig +68 -0
  87. package/std/c.zig +17 -17
  88. package/std/compress/flate/Compress.zig +3 -3
  89. package/std/crypto/Certificate/Bundle.zig +15 -1
  90. package/std/crypto/codecs/asn1.zig +33 -18
  91. package/std/crypto/codecs/base64_hex_ct.zig +14 -4
  92. package/std/debug/Dwarf.zig +29 -9
  93. package/std/debug/Info.zig +4 -0
  94. package/std/debug/MachOFile.zig +46 -8
  95. package/std/debug/Pdb.zig +539 -36
  96. package/std/debug/SelfInfo/Elf.zig +19 -18
  97. package/std/debug/SelfInfo/MachO.zig +18 -7
  98. package/std/debug/SelfInfo/Windows.zig +138 -36
  99. package/std/debug.zig +179 -65
  100. package/std/enums.zig +25 -19
  101. package/std/heap/ArenaAllocator.zig +145 -154
  102. package/std/heap/debug_allocator.zig +7 -7
  103. package/std/http/Client.zig +10 -6
  104. package/std/http.zig +11 -9
  105. package/std/json/Stringify.zig +3 -3
  106. package/std/json/dynamic.zig +4 -4
  107. package/std/math/big/int.zig +16 -17
  108. package/std/mem/Allocator.zig +4 -5
  109. package/std/mem.zig +48 -0
  110. package/std/os/emscripten.zig +2 -18
  111. package/std/os/linux/arc.zig +144 -0
  112. package/std/os/linux.zig +21 -4
  113. package/std/os/windows.zig +2 -2
  114. package/std/pdb.zig +143 -4
  115. package/std/posix.zig +6 -12
  116. package/std/priority_dequeue.zig +13 -12
  117. package/std/priority_queue.zig +5 -4
  118. package/std/process/Child.zig +1 -1
  119. package/std/process/Environ.zig +1 -1
  120. package/std/start.zig +17 -4
  121. package/std/std.zig +19 -6
  122. package/std/testing/FailingAllocator.zig +4 -4
  123. package/std/testing/Smith.zig +37 -2
  124. package/std/zig/Ast/Render.zig +186 -458
  125. package/std/zig/Ast.zig +0 -4
  126. package/std/zig/AstGen.zig +44 -7
  127. package/std/zig/AstSmith.zig +2602 -0
  128. package/std/zig/Client.zig +8 -3
  129. package/std/zig/Parse.zig +83 -74
  130. package/std/zig/Server.zig +26 -0
  131. package/std/zig/Zir.zig +17 -0
  132. package/std/zig/c_translation/helpers.zig +14 -9
  133. package/std/zig/llvm/Builder.zig +107 -48
  134. package/std/zig/system.zig +20 -4
  135. package/std/zig/tokenizer.zig +2 -1
  136. package/std/zig.zig +6 -0
  137. package/compiler/aro/aro/Driver/Filesystem.zig +0 -241
  138. package/libc/mingw/complex/cabs.c +0 -48
  139. package/libc/mingw/complex/cabsf.c +0 -48
  140. package/libc/mingw/complex/cacos.c +0 -50
  141. package/libc/mingw/complex/cacosf.c +0 -50
  142. package/libc/mingw/complex/carg.c +0 -48
  143. package/libc/mingw/complex/cargf.c +0 -48
  144. package/libc/mingw/complex/casin.c +0 -50
  145. package/libc/mingw/complex/casinf.c +0 -50
  146. package/libc/mingw/complex/catan.c +0 -50
  147. package/libc/mingw/complex/catanf.c +0 -50
  148. package/libc/mingw/complex/ccos.c +0 -50
  149. package/libc/mingw/complex/ccosf.c +0 -50
  150. package/libc/mingw/complex/cexp.c +0 -48
  151. package/libc/mingw/complex/cexpf.c +0 -48
  152. package/libc/mingw/complex/cimag.c +0 -48
  153. package/libc/mingw/complex/cimagf.c +0 -48
  154. package/libc/mingw/complex/clog.c +0 -48
  155. package/libc/mingw/complex/clog10.c +0 -49
  156. package/libc/mingw/complex/clog10f.c +0 -49
  157. package/libc/mingw/complex/clogf.c +0 -48
  158. package/libc/mingw/complex/conj.c +0 -48
  159. package/libc/mingw/complex/conjf.c +0 -48
  160. package/libc/mingw/complex/cpow.c +0 -48
  161. package/libc/mingw/complex/cpowf.c +0 -48
  162. package/libc/mingw/complex/cproj.c +0 -48
  163. package/libc/mingw/complex/cprojf.c +0 -48
  164. package/libc/mingw/complex/creal.c +0 -48
  165. package/libc/mingw/complex/crealf.c +0 -48
  166. package/libc/mingw/complex/csin.c +0 -50
  167. package/libc/mingw/complex/csinf.c +0 -50
  168. package/libc/mingw/complex/csqrt.c +0 -48
  169. package/libc/mingw/complex/csqrtf.c +0 -48
  170. package/libc/mingw/complex/ctan.c +0 -50
  171. package/libc/mingw/complex/ctanf.c +0 -50
  172. package/libc/mingw/math/arm/s_rint.c +0 -86
  173. package/libc/mingw/math/arm/s_rintf.c +0 -51
  174. package/libc/mingw/math/arm/sincos.S +0 -30
  175. package/libc/mingw/math/arm-common/sincosl.c +0 -13
  176. package/libc/mingw/math/arm64/rint.c +0 -12
  177. package/libc/mingw/math/arm64/rintf.c +0 -12
  178. package/libc/mingw/math/arm64/sincos.S +0 -32
  179. package/libc/mingw/math/bsd_private_base.h +0 -148
  180. package/libc/mingw/math/frexpf.c +0 -13
  181. package/libc/mingw/math/frexpl.c +0 -71
  182. package/libc/mingw/math/x86/acosf.c +0 -29
  183. package/libc/mingw/math/x86/atanf.c +0 -23
  184. package/libc/mingw/math/x86/atanl.c +0 -18
  185. package/libc/mingw/math/x86/cos.def.h +0 -65
  186. package/libc/mingw/math/x86/cosl.c +0 -46
  187. package/libc/mingw/math/x86/cosl_internal.S +0 -55
  188. package/libc/mingw/math/x86/ldexp.c +0 -23
  189. package/libc/mingw/math/x86/scalbn.S +0 -41
  190. package/libc/mingw/math/x86/scalbnf.S +0 -40
  191. package/libc/mingw/math/x86/sin.def.h +0 -65
  192. package/libc/mingw/math/x86/sinl.c +0 -46
  193. package/libc/mingw/math/x86/sinl_internal.S +0 -58
  194. package/libc/mingw/math/x86/tanl.S +0 -62
  195. package/libc/mingw/misc/btowc.c +0 -28
  196. package/libc/mingw/misc/wcstof.c +0 -66
  197. package/libc/mingw/misc/wcstoimax.c +0 -132
  198. package/libc/mingw/misc/wcstoumax.c +0 -126
  199. package/libc/mingw/misc/wctob.c +0 -29
  200. package/libc/mingw/misc/winbs_uint64.c +0 -6
  201. package/libc/mingw/misc/winbs_ulong.c +0 -6
  202. package/libc/mingw/misc/winbs_ushort.c +0 -6
  203. package/libc/mingw/stdio/_Exit.c +0 -10
  204. package/libc/mingw/stdio/_findfirst64i32.c +0 -21
  205. package/libc/mingw/stdio/_findnext64i32.c +0 -21
  206. package/libc/mingw/stdio/_fstat64i32.c +0 -37
  207. package/libc/mingw/stdio/_stat64i32.c +0 -37
  208. package/libc/mingw/stdio/_wfindfirst64i32.c +0 -21
  209. package/libc/mingw/stdio/_wfindnext64i32.c +0 -21
  210. package/libc/mingw/stdio/_wstat64i32.c +0 -37
  211. package/libc/musl/src/legacy/isastream.c +0 -7
  212. package/libc/musl/src/legacy/valloc.c +0 -8
  213. package/libc/musl/src/math/__cosl.c +0 -96
  214. package/libc/musl/src/math/__sinl.c +0 -78
  215. package/libc/musl/src/math/__tanl.c +0 -143
  216. package/libc/musl/src/math/aarch64/lrint.c +0 -10
  217. package/libc/musl/src/math/aarch64/lrintf.c +0 -10
  218. package/libc/musl/src/math/aarch64/rintf.c +0 -7
  219. package/libc/musl/src/math/cosl.c +0 -39
  220. package/libc/musl/src/math/fdim.c +0 -10
  221. package/libc/musl/src/math/finite.c +0 -7
  222. package/libc/musl/src/math/finitef.c +0 -7
  223. package/libc/musl/src/math/frexp.c +0 -23
  224. package/libc/musl/src/math/frexpf.c +0 -23
  225. package/libc/musl/src/math/frexpl.c +0 -29
  226. package/libc/musl/src/math/i386/lrint.c +0 -8
  227. package/libc/musl/src/math/i386/lrintf.c +0 -8
  228. package/libc/musl/src/math/i386/rintf.c +0 -7
  229. package/libc/musl/src/math/lrint.c +0 -72
  230. package/libc/musl/src/math/lrintf.c +0 -8
  231. package/libc/musl/src/math/powerpc64/lrint.c +0 -16
  232. package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
  233. package/libc/musl/src/math/rintf.c +0 -30
  234. package/libc/musl/src/math/s390x/rintf.c +0 -15
  235. package/libc/musl/src/math/sincosl.c +0 -60
  236. package/libc/musl/src/math/sinl.c +0 -41
  237. package/libc/musl/src/math/tanl.c +0 -29
  238. package/libc/musl/src/math/x32/lrint.s +0 -5
  239. package/libc/musl/src/math/x32/lrintf.s +0 -5
  240. package/libc/musl/src/math/x86_64/lrint.c +0 -8
  241. package/libc/musl/src/math/x86_64/lrintf.c +0 -8
  242. package/libc/wasi/libc-bottom-half/sources/reallocarray.c +0 -14
@@ -472,3 +472,24 @@ pub const pragma_once_in_main_file: Diagnostic = .{
472
472
  .kind = .warning,
473
473
  .opt = .@"pragma-once-outside-header",
474
474
  };
475
+
476
+ pub const file_name_is_clang_extension: Diagnostic = .{
477
+ .fmt = "__FILE_NAME__ is a clang extension",
478
+ .opt = .@"file-name-extension",
479
+ .kind = .off,
480
+ .extension = true,
481
+ };
482
+
483
+ pub const base_file_is_clang_extension: Diagnostic = .{
484
+ .fmt = "__BASE_FILE__ is a clang extension",
485
+ .opt = .@"base-file-extension",
486
+ .kind = .off,
487
+ .extension = true,
488
+ };
489
+
490
+ pub const include_level_is_clang_extension: Diagnostic = .{
491
+ .fmt = "__INCLUDE_LEVEL__ is a clang extension",
492
+ .opt = .@"include-level-extension",
493
+ .kind = .off,
494
+ .extension = true,
495
+ };
@@ -1,6 +1,6 @@
1
1
  const std = @import("std");
2
- const Io = std.Io;
3
2
  const mem = std.mem;
3
+ const path = std.Io.Dir.path;
4
4
  const Allocator = mem.Allocator;
5
5
  const assert = std.debug.assert;
6
6
 
@@ -79,12 +79,15 @@ pub const Macro = struct {
79
79
  });
80
80
 
81
81
  const Object = enum {
82
+ base_file,
82
83
  file,
84
+ file_basename,
83
85
  line,
84
86
  counter,
85
87
  date,
86
88
  time,
87
89
  timestamp,
90
+ include_level,
88
91
  };
89
92
 
90
93
  const Func = enum {
@@ -216,8 +219,6 @@ pub const Macro = struct {
216
219
  }
217
220
  };
218
221
 
219
- const Preprocessor = @This();
220
-
221
222
  const ExpansionEntry = struct {
222
223
  idx: Tree.TokenIndex,
223
224
  locs: [*]Source.Location,
@@ -228,6 +229,8 @@ const TokenState = struct {
228
229
  expansion_entries_len: usize,
229
230
  };
230
231
 
232
+ const Preprocessor = @This();
233
+
231
234
  comp: *Compilation,
232
235
  diagnostics: *Diagnostics,
233
236
 
@@ -275,6 +278,12 @@ m_times: std.AutoHashMapUnmanaged(Source.Id, u64) = .empty,
275
278
  /// The dependency file tracking all includes and embeds.
276
279
  dep_file: ?*DepFile = null,
277
280
 
281
+ /// Path prefixes to replace when expanding __FILE__
282
+ path_replacements: []const struct { []const u8, []const u8 } = &.{},
283
+
284
+ /// File used for __BASE_FILE__ macro.
285
+ base_file: Source.Id,
286
+
278
287
  pub const parse = Parser.parse;
279
288
 
280
289
  pub const Linemarkers = enum {
@@ -286,21 +295,22 @@ pub const Linemarkers = enum {
286
295
  numeric_directives,
287
296
  };
288
297
 
289
- pub fn init(comp: *Compilation, source_epoch: SourceEpoch) Preprocessor {
290
- const pp: Preprocessor = .{
291
- .comp = comp,
292
- .diagnostics = comp.diagnostics,
293
- .arena = .init(comp.gpa),
294
- .hideset = .{ .comp = comp },
295
- .source_epoch = source_epoch,
298
+ pub const InitOptions = struct {
299
+ base_file: Source.Id,
300
+
301
+ source_epoch: ?SourceEpoch = null,
302
+ add_builtin_macros: bool = true,
303
+ path_replacements: []const struct { []const u8, []const u8 } = &.{},
304
+
305
+ pub const testing: InitOptions = .{
306
+ .base_file = undefined,
307
+ .source_epoch = .default,
308
+ .add_builtin_macros = false,
296
309
  };
297
- comp.pragmaEvent(.before_preprocess);
298
- return pp;
299
- }
310
+ };
300
311
 
301
- /// Initialize Preprocessor with builtin macros.
302
- pub fn initDefault(comp: *Compilation) !Preprocessor {
303
- const source_epoch: SourceEpoch = comp.environment.sourceEpoch(comp.io) catch |er| switch (er) {
312
+ pub fn init(comp: *Compilation, options: InitOptions) !Preprocessor {
313
+ const source_epoch: SourceEpoch = options.source_epoch orelse comp.environment.sourceEpoch(comp.io) catch |er| switch (er) {
304
314
  error.InvalidEpoch => blk: {
305
315
  const diagnostic: Diagnostic = .invalid_source_epoch;
306
316
  try comp.diagnostics.add(.{ .text = diagnostic.fmt, .kind = diagnostic.kind, .opt = diagnostic.opt, .location = null });
@@ -308,9 +318,18 @@ pub fn initDefault(comp: *Compilation) !Preprocessor {
308
318
  },
309
319
  };
310
320
 
311
- var pp = init(comp, source_epoch);
321
+ var pp: Preprocessor = .{
322
+ .comp = comp,
323
+ .diagnostics = comp.diagnostics,
324
+ .arena = .init(comp.gpa),
325
+ .hideset = .{ .comp = comp },
326
+ .source_epoch = source_epoch,
327
+ .base_file = options.base_file,
328
+ .path_replacements = options.path_replacements,
329
+ };
312
330
  errdefer pp.deinit();
313
- try pp.addBuiltinMacros();
331
+ comp.pragmaEvent(.before_preprocess);
332
+ if (options.add_builtin_macros) try pp.addBuiltinMacros();
314
333
  return pp;
315
334
  }
316
335
 
@@ -339,7 +358,7 @@ pub fn addBuiltinMacros(pp: *Preprocessor) !void {
339
358
  try pp.addBuiltinMacro("__is_identifier", .{ .func = .is_identifier });
340
359
  try pp.addBuiltinMacro("_Pragma", .{ .func = .pragma_operator });
341
360
 
342
- if (pp.comp.langopts.emulate == .clang) {
361
+ if (pp.comp.langopts.emulate == .no or pp.comp.langopts.emulate == .clang) {
343
362
  try pp.addBuiltinMacro("__is_target_arch", .{ .func = .is_target_arch });
344
363
  try pp.addBuiltinMacro("__is_target_vendor", .{ .func = .is_target_vendor });
345
364
  try pp.addBuiltinMacro("__is_target_os", .{ .func = .is_target_os });
@@ -359,6 +378,12 @@ pub fn addBuiltinMacros(pp: *Preprocessor) !void {
359
378
  try pp.addBuiltinMacro("__DATE__", .{ .obj = .date });
360
379
  try pp.addBuiltinMacro("__TIME__", .{ .obj = .time });
361
380
  try pp.addBuiltinMacro("__TIMESTAMP__", .{ .obj = .timestamp });
381
+
382
+ if (pp.comp.langopts.emulate == .no or pp.comp.langopts.emulate == .clang) {
383
+ try pp.addBuiltinMacro("__BASE_FILE__", .{ .obj = .base_file });
384
+ try pp.addBuiltinMacro("__FILE_NAME__", .{ .obj = .file_basename });
385
+ try pp.addBuiltinMacro("__INCLUDE_LEVEL__", .{ .obj = .include_level });
386
+ }
362
387
  }
363
388
 
364
389
  pub fn deinit(pp: *Preprocessor) void {
@@ -395,7 +420,7 @@ fn mTime(pp: *Preprocessor, source_id: Source.Id) !u64 {
395
420
  return gop.value_ptr.*;
396
421
  }
397
422
 
398
- pub fn expansionSlice(pp: *Preprocessor, tok: Tree.TokenIndex) []Source.Location {
423
+ pub fn expansionSlice(pp: *const Preprocessor, tok: Tree.TokenIndex) []Source.Location {
399
424
  const S = struct {
400
425
  fn orderTokenIndex(context: Tree.TokenIndex, item: Tree.TokenIndex) std.math.Order {
401
426
  return std.math.order(context, item);
@@ -1065,13 +1090,11 @@ fn fatalNotFound(pp: *Preprocessor, tok: TokenWithExpansionLocs, filename: []con
1065
1090
 
1066
1091
  fn verboseLog(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args: anytype) void {
1067
1092
  @branchHint(.cold);
1068
- const comp = pp.comp;
1069
- const io = comp.io;
1070
- const source = comp.getSource(raw.source);
1093
+ const source = pp.comp.getSource(raw.source);
1071
1094
  const line_col = source.lineCol(.{ .id = raw.source, .line = raw.line, .byte_offset = raw.start });
1072
1095
 
1073
1096
  var stderr_buf: [4096]u8 = undefined;
1074
- var stderr = Io.File.stderr().writer(io, &stderr_buf);
1097
+ var stderr = std.Io.File.stderr().writer(pp.comp.io, &stderr_buf);
1075
1098
  const w = &stderr.interface;
1076
1099
 
1077
1100
  w.print("{s}:{d}:{d}: ", .{ source.path, line_col.line_no, line_col.col }) catch return;
@@ -1435,7 +1458,37 @@ fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf
1435
1458
  .file => {
1436
1459
  const start = pp.comp.generated_buf.items.len;
1437
1460
  const source = pp.comp.getSource(pp.expansion_source_loc.id);
1438
- try pp.comp.generated_buf.print(gpa, "\"{f}\"\n", .{fmtEscapes(source.path)});
1461
+ for (pp.path_replacements) |replacement| {
1462
+ if (mem.cutPrefix(u8, source.path, replacement[0])) |rest| {
1463
+ try pp.comp.generated_buf.print(gpa, "\"{f}{f}\"", .{ fmtEscapes(replacement[1]), fmtEscapes(rest) });
1464
+ break;
1465
+ }
1466
+ } else {
1467
+ try pp.comp.generated_buf.print(gpa, "\"{f}\"\n", .{fmtEscapes(source.path)});
1468
+ }
1469
+
1470
+ buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));
1471
+ },
1472
+ .base_file => {
1473
+ try pp.err(pp.expansion_source_loc, .base_file_is_clang_extension, .{});
1474
+ const start = pp.comp.generated_buf.items.len;
1475
+ const base_file = pp.comp.getSource(pp.base_file);
1476
+ for (pp.path_replacements) |replacement| {
1477
+ if (mem.cutPrefix(u8, base_file.path, replacement[0])) |rest| {
1478
+ try pp.comp.generated_buf.print(gpa, "\"{f}{f}\"", .{ fmtEscapes(replacement[1]), fmtEscapes(rest) });
1479
+ }
1480
+ } else {
1481
+ try pp.comp.generated_buf.print(gpa, "\"{f}\"", .{fmtEscapes(base_file.path)});
1482
+ }
1483
+
1484
+ buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));
1485
+ },
1486
+ .file_basename => {
1487
+ try pp.err(pp.expansion_source_loc, .file_name_is_clang_extension, .{});
1488
+ const start = pp.comp.generated_buf.items.len;
1489
+ const source = pp.comp.getSource(pp.expansion_source_loc.id);
1490
+ const basename = path.basename(source.path);
1491
+ try pp.comp.generated_buf.print(gpa, "\"{f}\"", .{fmtEscapes(basename)});
1439
1492
 
1440
1493
  buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));
1441
1494
  },
@@ -1472,6 +1525,13 @@ fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf
1472
1525
  try pp.writeDateTimeStamp(.fromBuiltin(builtin_kind), timestamp);
1473
1526
  buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .string_literal, tok));
1474
1527
  },
1528
+ .include_level => {
1529
+ try pp.err(pp.expansion_source_loc, .include_level_is_clang_extension, .{});
1530
+ const start = pp.comp.generated_buf.items.len;
1531
+ try pp.comp.generated_buf.print(gpa, "{d}\n", .{pp.include_depth});
1532
+
1533
+ buf.appendAssumeCapacity(try pp.makeGeneratedToken(start, .pp_num, tok));
1534
+ },
1475
1535
  },
1476
1536
  else => buf.appendAssumeCapacity(tok),
1477
1537
  }
@@ -1828,7 +1888,11 @@ fn handleBuiltinMacro(pp: *Preprocessor, builtin: Macro.Builtin.Func, param_toks
1828
1888
  features.hasFeature(pp.comp, ident_str)
1829
1889
  else
1830
1890
  features.hasExtension(pp.comp, ident_str),
1831
- .has_builtin => Builtins.fromName(pp.comp, ident_str) != null or (pp.comp.langopts.emulate == .clang and Macro.Builtin.has_builtin_special_cases.has(ident_str)),
1891
+
1892
+ .has_builtin => Builtins.fromName(pp.comp, ident_str) != null or
1893
+ ((pp.comp.langopts.emulate == .no or pp.comp.langopts.emulate == .clang) and
1894
+ Macro.Builtin.has_builtin_special_cases.has(ident_str)),
1895
+
1832
1896
  .is_target_arch => pp.comp.isTargetArch(ident_str),
1833
1897
  .is_target_os => pp.comp.isTargetOs(ident_str),
1834
1898
  .is_target_vendor => pp.comp.isTargetVendor(ident_str),
@@ -1972,7 +2036,7 @@ fn expandFuncMacro(
1972
2036
  },
1973
2037
  .macro_param_no_expand => {
1974
2038
  if (tok_i + 1 < func_macro.tokens.len and func_macro.tokens[tok_i + 1].id == .hash_hash) {
1975
- hideset = pp.hideset.get(tokFromRaw(func_macro.tokens[tok_i + 1]).loc);
2039
+ hideset = .none;
1976
2040
  }
1977
2041
  const slice = getPasteArgs(args.items[raw.end]);
1978
2042
  const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };
@@ -1980,7 +2044,7 @@ fn expandFuncMacro(
1980
2044
  },
1981
2045
  .macro_param => {
1982
2046
  if (tok_i + 1 < func_macro.tokens.len and func_macro.tokens[tok_i + 1].id == .hash_hash) {
1983
- hideset = pp.hideset.get(tokFromRaw(func_macro.tokens[tok_i + 1]).loc);
2047
+ hideset = .none;
1984
2048
  }
1985
2049
  const arg = expanded_args.items[raw.end];
1986
2050
  const raw_loc = Source.Location{ .id = raw.source, .byte_offset = raw.start, .line = raw.line };
@@ -2330,9 +2394,10 @@ fn expandFuncMacro(
2330
2394
  for (buf.items) |*tok| {
2331
2395
  try tok.addExpansionLocation(gpa, &.{macro_tok.loc});
2332
2396
  try tok.addExpansionLocation(gpa, macro_expansion_locs);
2333
- const tok_hidelist = pp.hideset.get(tok.loc);
2334
- const new_hidelist = try pp.hideset.@"union"(tok_hidelist, hideset);
2335
- try pp.hideset.put(tok.loc, new_hidelist);
2397
+ if (tok.id.shouldTrackHideset(.func)) {
2398
+ const new_hideset = try pp.hideset.@"union"(pp.hideset.get(tok.loc), hideset);
2399
+ try pp.hideset.put(tok.loc, new_hideset);
2400
+ }
2336
2401
  }
2337
2402
 
2338
2403
  return buf;
@@ -2698,9 +2763,10 @@ fn expandMacroExhaustive(
2698
2763
  try tok.addExpansionLocation(gpa, &.{macro_tok.loc});
2699
2764
  try tok.addExpansionLocation(gpa, macro_expansion_locs);
2700
2765
 
2701
- const tok_hidelist = pp.hideset.get(tok.loc);
2702
- const new_hidelist = try pp.hideset.@"union"(tok_hidelist, hs);
2703
- try pp.hideset.put(tok.loc, new_hidelist);
2766
+ if (tok.id.shouldTrackHideset(.obj)) {
2767
+ const new_hideset = try pp.hideset.@"union"(pp.hideset.get(tok.loc), hs);
2768
+ try pp.hideset.put(tok.loc, new_hideset);
2769
+ }
2704
2770
 
2705
2771
  if (tok.id == .keyword_defined and eval_ctx == .expr) {
2706
2772
  if (macro.is_func) {
@@ -2914,7 +2980,10 @@ fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenW
2914
2980
  .placemarker
2915
2981
  else
2916
2982
  pasted_token.id;
2917
- try lhs_toks.append(gpa, try pp.makeGeneratedToken(start, pasted_id, lhs));
2983
+
2984
+ const hideset = try pp.hideset.intersection(pp.hideset.get(lhs.loc), pp.hideset.get(rhs.loc));
2985
+ const generated_token = try pp.makeGeneratedTokenExtra(start, pasted_id, lhs, hideset);
2986
+ try lhs_toks.append(gpa, generated_token);
2918
2987
 
2919
2988
  if (next.id != .nl and next.id != .eof) {
2920
2989
  try pp.err(lhs, .pasting_formed_invalid, .{pp.comp.generated_buf.items[start..end]});
@@ -2924,7 +2993,7 @@ fn pasteTokens(pp: *Preprocessor, lhs_toks: *ExpandBuf, rhs_toks: []const TokenW
2924
2993
  try bufCopyTokens(gpa, lhs_toks, rhs_toks[rhs_rest..], &.{});
2925
2994
  }
2926
2995
 
2927
- fn makeGeneratedToken(pp: *Preprocessor, start: usize, id: Token.Id, source: TokenWithExpansionLocs) !TokenWithExpansionLocs {
2996
+ fn makeGeneratedTokenExtra(pp: *Preprocessor, start: usize, id: Token.Id, source: TokenWithExpansionLocs, hideset: Hideset.Index) !TokenWithExpansionLocs {
2928
2997
  const gpa = pp.comp.gpa;
2929
2998
  var pasted_token = TokenWithExpansionLocs{ .id = id, .loc = .{
2930
2999
  .id = .generated,
@@ -2934,9 +3003,15 @@ fn makeGeneratedToken(pp: *Preprocessor, start: usize, id: Token.Id, source: Tok
2934
3003
  pp.generated_line += 1;
2935
3004
  try pasted_token.addExpansionLocation(gpa, &.{source.loc});
2936
3005
  try pasted_token.addExpansionLocation(gpa, source.expansionSlice());
3006
+ try pp.hideset.put(pasted_token.loc, hideset);
3007
+
2937
3008
  return pasted_token;
2938
3009
  }
2939
3010
 
3011
+ fn makeGeneratedToken(pp: *Preprocessor, start: usize, id: Token.Id, source: TokenWithExpansionLocs) !TokenWithExpansionLocs {
3012
+ return pp.makeGeneratedTokenExtra(start, id, source, pp.hideset.get(source.loc));
3013
+ }
3014
+
2940
3015
  /// Defines a new macro and warns if it is a duplicate
2941
3016
  fn defineMacro(pp: *Preprocessor, define_tok: RawToken, name_tok: TokenWithExpansionLocs, macro: Macro) Error!void {
2942
3017
  const name_str = pp.expandedSlice(name_tok);
@@ -3898,16 +3973,14 @@ test "Preserve pragma tokens sometimes" {
3898
3973
  const gpa = std.testing.allocator;
3899
3974
  const Test = struct {
3900
3975
  fn runPreprocessor(source_text: []const u8) ![]const u8 {
3901
- var arena: std.heap.ArenaAllocator = .init(gpa);
3902
- defer arena.deinit();
3903
-
3904
3976
  var diagnostics: Diagnostics = .{ .output = .ignore };
3905
- var comp = Compilation.init(gpa, arena.allocator(), std.testing.io, &diagnostics, Io.Dir.cwd());
3977
+ var comp = try Compilation.init(.testing);
3978
+ comp.diagnostics = &diagnostics;
3906
3979
  defer comp.deinit();
3907
3980
 
3908
3981
  try comp.addDefaultPragmaHandlers();
3909
3982
 
3910
- var pp = Preprocessor.init(&comp, .default);
3983
+ var pp = try Preprocessor.init(&comp, .testing);
3911
3984
  defer pp.deinit();
3912
3985
 
3913
3986
  pp.preserve_whitespace = true;
@@ -3966,12 +4039,10 @@ test "destringify" {
3966
4039
  try std.testing.expectEqualStrings(destringified, pp.char_buf.items);
3967
4040
  }
3968
4041
  };
3969
- var arena: std.heap.ArenaAllocator = .init(gpa);
3970
- defer arena.deinit();
3971
- var diagnostics: Diagnostics = .{ .output = .ignore };
3972
- var comp = Compilation.init(gpa, arena.allocator(), std.testing.io, &diagnostics, Io.Dir.cwd());
4042
+ var comp = try Compilation.init(.testing);
3973
4043
  defer comp.deinit();
3974
- var pp = Preprocessor.init(&comp, .default);
4044
+
4045
+ var pp = try Preprocessor.init(&comp, .testing);
3975
4046
  defer pp.deinit();
3976
4047
 
3977
4048
  try Test.testDestringify(&pp, "hello\tworld\n", "hello\tworld\n");
@@ -4026,20 +4097,20 @@ test "Include guards" {
4026
4097
  };
4027
4098
  }
4028
4099
 
4029
- fn testIncludeGuard(gpa: std.mem.Allocator, comptime template: []const u8, tok_id: RawToken.Id, expected_guards: u32) !void {
4030
- var arena_state: std.heap.ArenaAllocator = .init(gpa);
4031
- defer arena_state.deinit();
4032
- const arena = arena_state.allocator();
4100
+ fn testIncludeGuard(comptime template: []const u8, tok_id: RawToken.Id, expected_guards: u32) !void {
4101
+ const gpa = std.testing.allocator;
4033
4102
 
4034
4103
  var diagnostics: Diagnostics = .{ .output = .ignore };
4035
- var comp = Compilation.init(gpa, arena, std.testing.io, &diagnostics, Io.Dir.cwd());
4104
+ var comp = try Compilation.init(.testing);
4105
+ comp.diagnostics = &diagnostics;
4036
4106
  defer comp.deinit();
4037
- var pp = Preprocessor.init(&comp, .default);
4107
+ var pp = try Preprocessor.init(&comp, .testing);
4038
4108
  defer pp.deinit();
4039
4109
 
4040
- const path = try std.fs.path.join(arena, &.{ ".", "bar.h" });
4110
+ const file_path = try path.join(gpa, &.{ ".", "bar.h" });
4111
+ defer gpa.free(file_path);
4041
4112
 
4042
- _ = try comp.addSourceFromBuffer(path, "int bar = 5;\n");
4113
+ _ = try comp.addSourceFromBuffer(file_path, "int bar = 5;\n");
4043
4114
 
4044
4115
  var buf: std.ArrayList(u8) = .empty;
4045
4116
  defer buf.deinit(gpa);
@@ -4074,14 +4145,14 @@ test "Include guards" {
4074
4145
  \\#endif
4075
4146
  ;
4076
4147
  const expected_guards: u32 = if (Test.pairsWithIfndef(tag)) 0 else 1;
4077
- try Test.testIncludeGuard(std.testing.allocator, inside_ifndef_template, tag, expected_guards);
4148
+ try Test.testIncludeGuard(inside_ifndef_template, tag, expected_guards);
4078
4149
 
4079
4150
  const outside_ifndef_template =
4080
4151
  \\#ifndef FOO
4081
4152
  \\#endif
4082
4153
  \\#{s}{s}
4083
4154
  ;
4084
- try Test.testIncludeGuard(std.testing.allocator, outside_ifndef_template, tag, 0);
4155
+ try Test.testIncludeGuard(outside_ifndef_template, tag, 0);
4085
4156
  }
4086
4157
  }
4087
4158
  }
@@ -229,7 +229,7 @@ pub fn intMaxType(target: *const Target) QualType {
229
229
  => return .long,
230
230
 
231
231
  .x86_64 => switch (target.os.tag) {
232
- .windows, .openbsd => {},
232
+ .windows, .openbsd, .uefi => {},
233
233
  else => switch (target.abi) {
234
234
  .gnux32, .muslx32 => {},
235
235
  else => return .long,
@@ -546,18 +546,10 @@ pub fn systemCompiler(target: *const Target) LangOpts.Compiler {
546
546
  }
547
547
 
548
548
  pub fn hasFloat128(target: *const Target) bool {
549
- if (target.cpu.arch.isWasm()) return true;
550
549
  if (target.os.tag.isDarwin()) return false;
551
- if (target.cpu.arch.isPowerPC()) return std.Target.powerpc.featureSetHas(target.cpu.features, .float128);
552
- return switch (target.os.tag) {
553
- .dragonfly,
554
- .haiku,
555
- .linux,
556
- .openbsd,
557
- .illumos,
558
- => target.cpu.arch.isX86(),
559
- else => false,
560
- };
550
+ if (target.os.tag == .windows) return false;
551
+ if (target.cpu.arch.isX86()) return true;
552
+ return target.cTypeBitSize(.longdouble) == 128;
561
553
  }
562
554
 
563
555
  pub fn hasInt128(target: *const Target) bool {
@@ -1238,6 +1230,7 @@ pub fn toLLVMTriple(target: *const Target, buf: []u8) []const u8 {
1238
1230
  .other,
1239
1231
  .plan9,
1240
1232
  .vita,
1233
+ .psp,
1241
1234
  => "unknown",
1242
1235
  };
1243
1236
  writer.writeAll(llvm_os) catch unreachable;
@@ -1356,6 +1349,18 @@ pub fn isPIEDefault(target: *const Target) DefaultPIStatus {
1356
1349
  };
1357
1350
  }
1358
1351
 
1352
+ pub fn ppcElfVersion(target: *const Target) u32 {
1353
+ std.debug.assert(target.cpu.arch.isPowerPC());
1354
+ return switch (target.cpu.arch) {
1355
+ .powerpc64le => 2,
1356
+ .powerpc64 => if ((target.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0, .patch = 0 }) orelse false) or target.os.tag == .openbsd or target.abi.isMusl())
1357
+ 2
1358
+ else
1359
+ 1,
1360
+ else => 1,
1361
+ };
1362
+ }
1363
+
1359
1364
  pub fn isPICdefault(target: *const Target) DefaultPIStatus {
1360
1365
  return switch (target.os.tag) {
1361
1366
  .haiku,
@@ -1,5 +1,4 @@
1
1
  const std = @import("std");
2
- const Io = std.Io;
3
2
  const assert = std.debug.assert;
4
3
 
5
4
  const Compilation = @import("Compilation.zig");
@@ -891,6 +890,14 @@ pub const Token = struct {
891
890
  else => false,
892
891
  };
893
892
  }
893
+
894
+ pub fn shouldTrackHideset(id: Id, context: enum { func, obj }) bool {
895
+ return switch (id) {
896
+ .identifier, .extended_identifier => true,
897
+ .r_paren => context == .func,
898
+ else => false,
899
+ };
900
+ }
894
901
  };
895
902
 
896
903
  /// double underscore and underscore + capital letter identifiers
@@ -938,6 +945,18 @@ pub const Token = struct {
938
945
  .keyword_unaligned,
939
946
  .keyword_unaligned2,
940
947
  => if (langopts.ms_extensions) kw else .identifier,
948
+
949
+ .keyword_float32,
950
+ .keyword_float64,
951
+ .keyword_float128,
952
+ .keyword_float32x,
953
+ .keyword_float64x,
954
+ .keyword_float128x,
955
+ .keyword_dfloat32,
956
+ .keyword_dfloat64,
957
+ .keyword_dfloat128,
958
+ .keyword_dfloat64x,
959
+ => if (langopts.emulate == .clang) .identifier else kw,
941
960
  else => kw,
942
961
  };
943
962
  }
@@ -2008,11 +2027,11 @@ test "operators" {
2008
2027
  test "keywords" {
2009
2028
  try expectTokens(
2010
2029
  \\auto __auto_type break case char const continue default do
2011
- \\double else enum extern float for goto if int
2012
- \\long register return short signed sizeof static
2013
- \\struct switch typedef union unsigned void volatile
2014
- \\while _Bool _Complex _Imaginary inline restrict _Alignas
2015
- \\_Alignof _Atomic _Generic _Noreturn _Static_assert _Thread_local
2030
+ \\double else enum extern float for goto if int
2031
+ \\long register return short signed sizeof static
2032
+ \\struct switch typedef union unsigned void volatile
2033
+ \\while _Bool _Complex _Imaginary inline restrict _Alignas
2034
+ \\_Alignof _Atomic _Generic _Noreturn _Static_assert _Thread_local
2016
2035
  \\__attribute __attribute__
2017
2036
  \\
2018
2037
  , &.{
@@ -2324,13 +2343,13 @@ test "Universal character names" {
2324
2343
 
2325
2344
  test "Tokenizer fuzz test" {
2326
2345
  const Context = struct {
2327
- fn testOne(_: @This(), input_bytes: []const u8) anyerror!void {
2328
- var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
2329
- defer arena.deinit();
2330
- var comp = Compilation.init(std.testing.allocator, arena.allocator(), std.testing.io, undefined, Io.Dir.cwd());
2346
+ fn testOne(_: @This(), smith: *std.testing.Smith) anyerror!void {
2347
+ var comp = try Compilation.init(.testing);
2331
2348
  defer comp.deinit();
2332
2349
 
2333
- const source = try comp.addSourceFromBuffer("fuzz.c", input_bytes);
2350
+ var buf: [256]u8 = undefined;
2351
+ const contents_len = smith.slice(&buf);
2352
+ const source = try comp.addSourceFromBuffer("fuzz.c", buf[0..contents_len]);
2334
2353
 
2335
2354
  var tokenizer: Tokenizer = .{
2336
2355
  .buf = source.buf,
@@ -2350,9 +2369,7 @@ test "Tokenizer fuzz test" {
2350
2369
  }
2351
2370
 
2352
2371
  fn expectTokensExtra(contents: []const u8, expected_tokens: []const Token.Id, langopts: ?LangOpts) !void {
2353
- var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
2354
- defer arena.deinit();
2355
- var comp = Compilation.init(std.testing.allocator, arena.allocator(), std.testing.io, undefined, Io.Dir.cwd());
2372
+ var comp = try Compilation.init(.testing);
2356
2373
  defer comp.deinit();
2357
2374
  if (langopts) |provided| {
2358
2375
  comp.langopts = provided;
@@ -495,9 +495,9 @@ pub fn addSystemIncludeDir(tc: *const Toolchain, path: []const u8) !void {
495
495
  pub fn addBuiltinIncludeDir(tc: *const Toolchain) !void {
496
496
  const d = tc.driver;
497
497
  const comp = d.comp;
498
+ const io = comp.io;
498
499
  const gpa = comp.gpa;
499
500
  const arena = comp.arena;
500
- const io = comp.io;
501
501
  try d.includes.ensureUnusedCapacity(gpa, 1);
502
502
  if (d.resource_dir) |resource_dir| {
503
503
  const path = try std.fs.path.join(arena, &.{ resource_dir, "include" });
@@ -524,14 +524,12 @@ pub fn addBuiltinIncludeDir(tc: *const Toolchain) !void {
524
524
  /// Otherwise returns a slice of `buf`. If the file is larger than `buf` partial contents are returned
525
525
  pub fn readFile(tc: *const Toolchain, path: []const u8, buf: []u8) ?[]const u8 {
526
526
  const comp = tc.driver.comp;
527
- const io = comp.io;
528
- return comp.cwd.readFile(io, path, buf) catch null;
527
+ return comp.cwd.readFile(comp.io, path, buf) catch null;
529
528
  }
530
529
 
531
530
  pub fn exists(tc: *const Toolchain, path: []const u8) bool {
532
531
  const comp = tc.driver.comp;
533
- const io = comp.io;
534
- comp.cwd.access(io, path, .{}) catch return false;
532
+ comp.cwd.access(comp.io, path, .{}) catch return false;
535
533
  return true;
536
534
  }
537
535
 
@@ -549,8 +547,7 @@ pub fn canExecute(tc: *const Toolchain, path: []const u8) bool {
549
547
  }
550
548
 
551
549
  const comp = tc.driver.comp;
552
- const io = comp.io;
553
- comp.cwd.access(io, path, .{ .execute = true }) catch return false;
550
+ comp.cwd.access(comp.io, path, .{ .execute = true }) catch return false;
554
551
  // Todo: ensure path is not a directory
555
552
  return true;
556
553
  }