@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
@@ -1,5 +1,4 @@
1
1
  const std = @import("std");
2
- const Io = std.Io;
3
2
  const mem = std.mem;
4
3
  const Allocator = mem.Allocator;
5
4
  const process = std.process;
@@ -9,6 +8,7 @@ const Assembly = backend.Assembly;
9
8
  const Ir = backend.Ir;
10
9
  const Object = backend.Object;
11
10
 
11
+ const Attribute = @import("Attribute.zig");
12
12
  const Compilation = @import("Compilation.zig");
13
13
  const Diagnostics = @import("Diagnostics.zig");
14
14
  const DepFile = @import("DepFile.zig");
@@ -52,6 +52,7 @@ implicit_includes: std.ArrayList(Source) = .empty,
52
52
  /// List of includes that will be used to construct the compilation's search path
53
53
  includes: std.ArrayList(Compilation.Include) = .empty,
54
54
  link_objects: std.ArrayList([]const u8) = .empty,
55
+ macro_prefix_map: std.ArrayList(struct { []const u8, []const u8 }) = .empty,
55
56
  output_name: ?[]const u8 = null,
56
57
  sysroot: ?[]const u8 = null,
57
58
  resource_dir: ?[]const u8 = null,
@@ -134,9 +135,8 @@ strip: bool = false,
134
135
  unwindlib: ?[]const u8 = null,
135
136
 
136
137
  pub fn deinit(d: *Driver) void {
137
- const io = d.comp.io;
138
138
  for (d.link_objects.items[d.link_objects.items.len - d.temp_file_count ..]) |obj| {
139
- Io.Dir.deleteFileAbsolute(io, obj) catch {};
139
+ std.Io.Dir.deleteFileAbsolute(d.comp.io, obj) catch {};
140
140
  d.comp.gpa.free(obj);
141
141
  }
142
142
  d.inputs.deinit(d.comp.gpa);
@@ -144,6 +144,7 @@ pub fn deinit(d: *Driver) void {
144
144
  d.implicit_includes.deinit(d.comp.gpa);
145
145
  d.includes.deinit(d.comp.gpa);
146
146
  d.link_objects.deinit(d.comp.gpa);
147
+ d.macro_prefix_map.deinit(d.comp.gpa);
147
148
  d.* = undefined;
148
149
  }
149
150
 
@@ -177,6 +178,10 @@ pub const usage =
177
178
  \\ -darwin-target-variant-triple
178
179
  \\ Specify the darwin target variant triple
179
180
  \\ -fapple-kext Use Apple's kernel extensions ABI
181
+ \\ -fexperimental-bounds-safety
182
+ \\ Enable experimental clang-style bounds safety attributes (INCOMPLETE)
183
+ \\ -fno-experimental-bounds-safety
184
+ \\ Disable experimental clang-style bounds safety attributes
180
185
  \\ -fchar8_t Enable char8_t (enabled by default in C23 and later)
181
186
  \\ -fno-char8_t Disable char8_t (disabled by default for pre-C23)
182
187
  \\ -fcolor-diagnostics Enable colors in diagnostics
@@ -218,6 +223,8 @@ pub const usage =
218
223
  \\ -fuse-line-directives Use `#line <num>` linemarkers in preprocessed output
219
224
  \\ -fno-use-line-directives
220
225
  \\ Use `# <num>` linemarkers in preprocessed output
226
+ \\ -fvisibility=[default|hidden|internal|protected]
227
+ \\ Set the default ELF image symbol visibility to the specified option—all symbols are marked with this unless overridden within the code
221
228
  \\ -iquote <dir> Add directory to QUOTE include search path
222
229
  \\ -I <dir> Add directory to include search path
223
230
  \\ -idirafter <dir> Add directory to AFTER include search path
@@ -375,6 +382,17 @@ pub fn parseArgs(
375
382
  d.use_line_directives = false;
376
383
  } else if (mem.eql(u8, arg, "-fapple-kext")) {
377
384
  d.apple_kext = true;
385
+ } else if (option(arg, "-fvisibility=")) |visibility| {
386
+ d.comp.langopts.default_symbol_visibility = Attribute.visibilityFromString(visibility) orelse
387
+ return d.fatal("unsupported value '{s}'' in '{s}'", .{ visibility, arg });
388
+ } else if (option(arg, "-frandom-seed=")) |_| {
389
+ // Ignore
390
+ } else if (option(arg, "-fmacro-prefix-map=")) |kv| {
391
+ const pair = mem.cutScalar(u8, kv, '=') orelse {
392
+ try d.err("invalid argument '{s}' to '-fmacro-prefix-map=", .{kv});
393
+ continue;
394
+ };
395
+ try d.macro_prefix_map.append(gpa, pair);
378
396
  } else if (option(arg, "-mcmodel=")) |cmodel| {
379
397
  d.comp.cmodel = std.meta.stringToEnum(std.builtin.CodeModel, cmodel) orelse
380
398
  return d.fatal("unsupported machine code model: '{s}'", .{arg});
@@ -415,6 +433,10 @@ pub fn parseArgs(
415
433
  d.dependencies.file = path;
416
434
  } else if (mem.eql(u8, arg, "-MV")) {
417
435
  d.dependencies.format = .nmake;
436
+ } else if (mem.eql(u8, arg, "-fexperimental-bounds-safety")) {
437
+ d.comp.langopts.bounds_safety = .clang;
438
+ } else if (mem.eql(u8, arg, "-fno-experimental-bounds-safety")) {
439
+ d.comp.langopts.bounds_safety = .none;
418
440
  } else if (mem.eql(u8, arg, "-fchar8_t")) {
419
441
  d.comp.langopts.has_char8_t_override = true;
420
442
  } else if (mem.eql(u8, arg, "-fno-char8_t")) {
@@ -635,6 +657,42 @@ pub fn parseArgs(
635
657
  d.output_name = file;
636
658
  } else if (option(arg, "--sysroot=")) |sysroot| {
637
659
  d.sysroot = sysroot;
660
+ } else if (mem.eql(u8, arg, "--sysroot")) {
661
+ i += 1;
662
+ if (i >= args.len) {
663
+ try d.err("expected argument after --sysroot", .{});
664
+ continue;
665
+ }
666
+ d.sysroot = args[i];
667
+ } else if (mem.startsWith(u8, arg, "-isysroot")) {
668
+ var path = arg["-isysroot".len..];
669
+ if (path.len == 0) {
670
+ i += 1;
671
+ if (i >= args.len) {
672
+ try d.err("expected argument after -isysroot", .{});
673
+ continue;
674
+ }
675
+ path = args[i];
676
+ }
677
+ d.sysroot = path;
678
+ } else if (mem.eql(u8, arg, "-rpath")) {
679
+ i += 1;
680
+ if (i >= args.len) {
681
+ try d.err("expected argument after -rpath", .{});
682
+ continue;
683
+ }
684
+ // ignore for now
685
+ } else if (mem.startsWith(u8, arg, "-L")) {
686
+ var path = arg["-L".len..];
687
+ if (path.len == 0) {
688
+ i += 1;
689
+ if (i >= args.len) {
690
+ try d.err("expected argument after -L", .{});
691
+ continue;
692
+ }
693
+ path = args[i];
694
+ }
695
+ // ignore for now
638
696
  } else if (mem.eql(u8, arg, "-Wp,-v")) {
639
697
  // TODO this is not how this argument should work
640
698
  d.verbose_search_path = true;
@@ -706,6 +764,10 @@ pub fn parseArgs(
706
764
  d.comp.langopts.preserve_comments = true;
707
765
  d.comp.langopts.preserve_comments_in_macros = true;
708
766
  comment_arg = arg;
767
+ } else if (option(arg, "-fuse-ld=")) |linker_name| {
768
+ d.use_linker = linker_name;
769
+ } else if (mem.eql(u8, arg, "-fuse-ld=")) {
770
+ d.use_linker = null;
709
771
  } else if (option(arg, "--ld-path=")) |linker_path| {
710
772
  d.linker_path = linker_path;
711
773
  } else if (mem.eql(u8, arg, "-r")) {
@@ -810,6 +872,7 @@ pub fn parseArgs(
810
872
  .clang => try d.diagnostics.set("clang", .off),
811
873
  .gcc => try d.diagnostics.set("gnu", .off),
812
874
  .msvc => try d.diagnostics.set("microsoft", .off),
875
+ .no => {},
813
876
  }
814
877
  }
815
878
  if (d.comp.langopts.preserve_comments and !d.only_preprocess) {
@@ -1063,20 +1126,22 @@ pub fn printDiagnosticsStats(d: *Driver) void {
1063
1126
  }
1064
1127
  }
1065
1128
 
1066
- pub fn detectConfig(d: *Driver, file: Io.File) std.Io.tty.Config {
1129
+ pub fn detectMode(d: *Driver, file: std.Io.File) std.Io.Cancelable!std.Io.Terminal.Mode {
1067
1130
  if (d.diagnostics.color == false) return .no_color;
1068
1131
  const force_color = d.diagnostics.color == true;
1069
1132
 
1070
- if (file.supportsAnsiEscapeCodes()) return .escape_codes;
1071
- if (@import("builtin").os.tag == .windows and file.isTty()) {
1072
- var info: std.os.windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
1073
- if (std.os.windows.kernel32.GetConsoleScreenBufferInfo(file.handle, &info) == std.os.windows.FALSE) {
1074
- return if (force_color) .escape_codes else .no_color;
1133
+ const io = d.comp.io;
1134
+ if (try file.supportsAnsiEscapeCodes(io)) return .escape_codes;
1135
+ if (@import("builtin").os.tag == .windows and try file.isTty(io)) {
1136
+ var get_console_info = std.os.windows.CONSOLE.USER_IO.GET_SCREEN_BUFFER_INFO;
1137
+ switch (try get_console_info.operate(io, file)) {
1138
+ .SUCCESS => return .{ .windows_api = .{
1139
+ .io = io,
1140
+ .file = file,
1141
+ .reset_attributes = get_console_info.Data.wAttributes,
1142
+ } },
1143
+ else => {},
1075
1144
  }
1076
- return .{ .windows_api = .{
1077
- .handle = file.handle,
1078
- .reset_attributes = info.wAttributes,
1079
- } };
1080
1145
  }
1081
1146
 
1082
1147
  return if (force_color) .escape_codes else .no_color;
@@ -1105,13 +1170,13 @@ pub fn errorDescription(e: anyerror) []const u8 {
1105
1170
 
1106
1171
  /// The entry point of the Aro compiler.
1107
1172
  /// **MAY call `exit` if `fast_exit` is set.**
1108
- pub fn main(d: *Driver, tc: *Toolchain, args: []const []const u8, comptime fast_exit: bool, asm_gen_fn: ?AsmCodeGenFn) Compilation.Error!void {
1173
+ pub fn main(d: *Driver, tc: *Toolchain, args: []const []const u8, comptime fast_exit: bool, asm_gen_fn: ?AsmCodeGenFn) (Compilation.Error || std.Io.Cancelable)!void {
1109
1174
  const user_macros = macros: {
1110
1175
  var macro_buf: std.ArrayList(u8) = .empty;
1111
1176
  defer macro_buf.deinit(d.comp.gpa);
1112
1177
 
1113
1178
  var stdout_buf: [256]u8 = undefined;
1114
- var stdout = Io.File.stdout().writer(&stdout_buf);
1179
+ var stdout = std.Io.File.stdout().writer(d.comp.io, &stdout_buf);
1115
1180
  if (parseArgs(d, &stdout.interface, &macro_buf, args) catch |er| switch (er) {
1116
1181
  error.WriteFailed => return d.fatal("failed to write to stdout: {s}", .{errorDescription(er)}),
1117
1182
  error.OutOfMemory => return error.OutOfMemory,
@@ -1217,14 +1282,13 @@ pub fn getDepFileName(d: *Driver, source: Source, buf: *[std.fs.max_name_bytes]u
1217
1282
  }
1218
1283
 
1219
1284
  fn getRandomFilename(d: *Driver, buf: *[std.fs.max_name_bytes]u8, extension: []const u8) ![]const u8 {
1220
- const io = d.comp.io;
1221
1285
  const random_bytes_count = 12;
1222
- const sub_path_len = comptime std.base64.url_safe.Encoder.calcSize(random_bytes_count);
1286
+ const sub_path_len = comptime std.fs.base64_encoder.calcSize(random_bytes_count);
1223
1287
 
1224
1288
  var random_bytes: [random_bytes_count]u8 = undefined;
1225
- io.random(&random_bytes);
1289
+ d.comp.io.random(&random_bytes);
1226
1290
  var random_name: [sub_path_len]u8 = undefined;
1227
- _ = std.base64.url_safe.Encoder.encode(&random_name, &random_bytes);
1291
+ _ = std.fs.base64_encoder.encode(&random_name, &random_bytes);
1228
1292
 
1229
1293
  const fmt_template = "/tmp/{s}{s}";
1230
1294
  const fmt_args = .{
@@ -1251,12 +1315,11 @@ fn getOutFileName(d: *Driver, source: Source, buf: *[std.fs.max_name_bytes]u8) !
1251
1315
  }
1252
1316
 
1253
1317
  fn invokeAssembler(d: *Driver, tc: *Toolchain, input_path: []const u8, output_path: []const u8) !void {
1254
- const io = d.comp.io;
1255
1318
  var assembler_path_buf: [std.fs.max_path_bytes]u8 = undefined;
1256
1319
  const assembler_path = try tc.getAssemblerPath(&assembler_path_buf);
1257
1320
  const argv = [_][]const u8{ assembler_path, input_path, "-o", output_path };
1258
1321
 
1259
- var child = std.process.spawn(io, .{
1322
+ var child = std.process.spawn(d.comp.io, .{
1260
1323
  .argv = &argv,
1261
1324
  // TODO handle better
1262
1325
  .stdin = .inherit,
@@ -1265,8 +1328,8 @@ fn invokeAssembler(d: *Driver, tc: *Toolchain, input_path: []const u8, output_pa
1265
1328
  }) catch |er| {
1266
1329
  return d.fatal("unable to spawn linker: {s}", .{errorDescription(er)});
1267
1330
  };
1268
- const term = child.wait(io) catch |er| {
1269
- return d.fatal("unable to wait linker: {s}", .{errorDescription(er)});
1331
+ const term = child.wait(d.comp.io) catch |er| {
1332
+ return d.fatal("error waiting for linker: {s}", .{errorDescription(er)});
1270
1333
  };
1271
1334
  switch (term) {
1272
1335
  .exited => |code| if (code != 0) {
@@ -1289,13 +1352,16 @@ fn processSource(
1289
1352
  comptime fast_exit: bool,
1290
1353
  asm_gen_fn: ?AsmCodeGenFn,
1291
1354
  ) !void {
1292
- const gpa = d.comp.gpa;
1293
- d.comp.generated_buf.items.len = 0;
1355
+ const comp = d.comp;
1356
+ const io = comp.io;
1357
+ const gpa = comp.gpa;
1358
+ comp.generated_buf.items.len = 0;
1294
1359
  const prev_total = d.diagnostics.errors;
1295
1360
 
1296
- const io = d.comp.io;
1297
-
1298
- var pp = try Preprocessor.initDefault(d.comp);
1361
+ var pp = try Preprocessor.init(comp, .{
1362
+ .base_file = source.id,
1363
+ .path_replacements = d.macro_prefix_map.items,
1364
+ });
1299
1365
  defer pp.deinit();
1300
1366
 
1301
1367
  var name_buf: [std.fs.max_name_bytes]u8 = undefined;
@@ -1304,8 +1370,8 @@ fn processSource(
1304
1370
 
1305
1371
  if (opt_dep_file) |*dep_file| pp.dep_file = dep_file;
1306
1372
 
1307
- if (d.comp.langopts.ms_extensions) {
1308
- d.comp.ms_cwd_source_id = source.id;
1373
+ if (comp.langopts.ms_extensions) {
1374
+ comp.ms_cwd_source_id = source.id;
1309
1375
  }
1310
1376
  const dump_mode = d.debug_dump_letters.getPreprocessorDumpMode();
1311
1377
  if (d.verbose_pp) pp.verbose = true;
@@ -1333,10 +1399,10 @@ fn processSource(
1333
1399
  const dep_file_name = try d.getDepFileName(source, writer_buf[0..std.fs.max_name_bytes]);
1334
1400
 
1335
1401
  const file = if (dep_file_name) |path|
1336
- d.comp.cwd.createFile(io, path, .{}) catch |er|
1402
+ comp.cwd.createFile(io, path, .{}) catch |er|
1337
1403
  return d.fatal("unable to create dependency file '{s}': {s}", .{ path, errorDescription(er) })
1338
1404
  else
1339
- Io.File.stdout();
1405
+ std.Io.File.stdout();
1340
1406
  defer if (dep_file_name != null) file.close(io);
1341
1407
 
1342
1408
  var file_writer = file.writer(io, &writer_buf);
@@ -1358,10 +1424,10 @@ fn processSource(
1358
1424
  }
1359
1425
 
1360
1426
  const file = if (d.output_name) |some|
1361
- d.comp.cwd.createFile(io, some, .{}) catch |er|
1427
+ comp.cwd.createFile(io, some, .{}) catch |er|
1362
1428
  return d.fatal("unable to create output file '{s}': {s}", .{ some, errorDescription(er) })
1363
1429
  else
1364
- Io.File.stdout();
1430
+ std.Io.File.stdout();
1365
1431
  defer if (d.output_name != null) file.close(io);
1366
1432
 
1367
1433
  var file_writer = file.writer(io, &writer_buf);
@@ -1376,8 +1442,11 @@ fn processSource(
1376
1442
  defer tree.deinit();
1377
1443
 
1378
1444
  if (d.verbose_ast) {
1379
- var stdout = Io.File.stdout().writer(&writer_buf);
1380
- tree.dump(d.detectConfig(stdout.file), &stdout.interface) catch {};
1445
+ var stdout = std.Io.File.stdout().writer(io, &writer_buf);
1446
+ tree.dump(.{
1447
+ .mode = try d.detectMode(stdout.file),
1448
+ .writer = &stdout.interface,
1449
+ }) catch {};
1381
1450
  }
1382
1451
 
1383
1452
  d.printDiagnosticsStats();
@@ -1392,10 +1461,10 @@ fn processSource(
1392
1461
  return;
1393
1462
  }
1394
1463
 
1395
- if (d.comp.target.ofmt != .elf or d.comp.target.cpu.arch != .x86_64) {
1464
+ if (comp.target.ofmt != .elf or comp.target.cpu.arch != .x86_64) {
1396
1465
  return d.fatal(
1397
1466
  "unsupported target {s}-{s}-{s}, currently only x86-64 elf is supported",
1398
- .{ @tagName(d.comp.target.cpu.arch), @tagName(d.comp.target.os.tag), @tagName(d.comp.target.abi) },
1467
+ .{ @tagName(comp.target.cpu.arch), @tagName(comp.target.os.tag), @tagName(comp.target.abi) },
1399
1468
  );
1400
1469
  }
1401
1470
 
@@ -1407,15 +1476,15 @@ fn processSource(
1407
1476
  .{},
1408
1477
  );
1409
1478
 
1410
- const assembly = try asm_fn(d.comp.target.toZigTarget(), &tree);
1479
+ const assembly = try asm_fn(comp.target.toZigTarget(), &tree);
1411
1480
  defer assembly.deinit(gpa);
1412
1481
 
1413
1482
  if (d.only_preprocess_and_compile) {
1414
- const out_file = d.comp.cwd.createFile(io, out_file_name, .{}) catch |er|
1483
+ const out_file = comp.cwd.createFile(io, out_file_name, .{}) catch |er|
1415
1484
  return d.fatal("unable to create output file '{s}': {s}", .{ out_file_name, errorDescription(er) });
1416
1485
  defer out_file.close(io);
1417
1486
 
1418
- assembly.writeToFile(out_file) catch |er|
1487
+ assembly.writeToFile(io, out_file) catch |er|
1419
1488
  return d.fatal("unable to write to output file '{s}': {s}", .{ out_file_name, errorDescription(er) });
1420
1489
  if (fast_exit) std.process.exit(0); // Not linking, no need for cleanup.
1421
1490
  return;
@@ -1425,10 +1494,10 @@ fn processSource(
1425
1494
  // then assemble to out_file_name
1426
1495
  var assembly_name_buf: [std.fs.max_name_bytes]u8 = undefined;
1427
1496
  const assembly_out_file_name = try d.getRandomFilename(&assembly_name_buf, ".s");
1428
- const out_file = d.comp.cwd.createFile(io, assembly_out_file_name, .{}) catch |er|
1497
+ const out_file = comp.cwd.createFile(io, assembly_out_file_name, .{}) catch |er|
1429
1498
  return d.fatal("unable to create output file '{s}': {s}", .{ assembly_out_file_name, errorDescription(er) });
1430
1499
  defer out_file.close(io);
1431
- assembly.writeToFile(out_file) catch |er|
1500
+ assembly.writeToFile(io, out_file) catch |er|
1432
1501
  return d.fatal("unable to write to output file '{s}': {s}", .{ assembly_out_file_name, errorDescription(er) });
1433
1502
  try d.invokeAssembler(tc, assembly_out_file_name, out_file_name);
1434
1503
  if (d.only_compile) {
@@ -1440,8 +1509,11 @@ fn processSource(
1440
1509
  defer ir.deinit(gpa);
1441
1510
 
1442
1511
  if (d.verbose_ir) {
1443
- var stdout = Io.File.stdout().writer(&writer_buf);
1444
- ir.dump(gpa, d.detectConfig(stdout.file), &stdout.interface) catch {};
1512
+ var stdout = std.Io.File.stdout().writer(io, &writer_buf);
1513
+ ir.dump(gpa, .{
1514
+ .mode = try d.detectMode(stdout.file),
1515
+ .writer = &stdout.interface,
1516
+ }) catch {};
1445
1517
  }
1446
1518
 
1447
1519
  var render_errors: Ir.Renderer.ErrorList = .{};
@@ -1494,8 +1566,9 @@ fn dumpLinkerArgs(w: *std.Io.Writer, items: []const []const u8) !void {
1494
1566
  /// The entry point of the Aro compiler.
1495
1567
  /// **MAY call `exit` if `fast_exit` is set.**
1496
1568
  pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) Compilation.Error!void {
1497
- const gpa = d.comp.gpa;
1498
- const io = d.comp.io;
1569
+ const comp = d.comp;
1570
+ const io = comp.io;
1571
+ const gpa = comp.gpa;
1499
1572
  var argv: std.ArrayList([]const u8) = .empty;
1500
1573
  defer argv.deinit(gpa);
1501
1574
 
@@ -1507,7 +1580,7 @@ pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) Compil
1507
1580
 
1508
1581
  if (d.verbose_linker_args) {
1509
1582
  var stdout_buf: [4096]u8 = undefined;
1510
- var stdout = Io.File.stdout().writer(&stdout_buf);
1583
+ var stdout = std.Io.File.stdout().writer(io, &stdout_buf);
1511
1584
  dumpLinkerArgs(&stdout.interface, argv.items) catch {
1512
1585
  return d.fatal("unable to dump linker args: {s}", .{errorDescription(stdout.err.?)});
1513
1586
  };
@@ -1521,8 +1594,9 @@ pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) Compil
1521
1594
  }) catch |er| {
1522
1595
  return d.fatal("unable to spawn linker: {s}", .{errorDescription(er)});
1523
1596
  };
1597
+
1524
1598
  const term = child.wait(io) catch |er| {
1525
- return d.fatal("unable to wait linker: {s}", .{errorDescription(er)});
1599
+ return d.fatal("error waiting for linker: {s}", .{errorDescription(er)});
1526
1600
  };
1527
1601
  switch (term) {
1528
1602
  .exited => |code| if (code != 0) {
@@ -1541,7 +1615,7 @@ pub fn invokeLinker(d: *Driver, tc: *Toolchain, comptime fast_exit: bool) Compil
1541
1615
 
1542
1616
  fn exitWithCleanup(d: *Driver, code: u8) noreturn {
1543
1617
  for (d.link_objects.items[d.link_objects.items.len - d.temp_file_count ..]) |obj| {
1544
- std.fs.deleteFileAbsolute(obj) catch {};
1618
+ std.Io.Dir.deleteFileAbsolute(d.comp.io, obj) catch {};
1545
1619
  }
1546
1620
  std.process.exit(code);
1547
1621
  }
@@ -7,16 +7,22 @@ pub const Compiler = enum {
7
7
  clang,
8
8
  gcc,
9
9
  msvc,
10
+ no,
10
11
 
11
12
  pub fn defaultGccVersion(self: Compiler) u32 {
12
13
  return switch (self) {
13
14
  .clang => 4 * 10_000 + 2 * 100 + 1,
14
- .gcc => 7 * 10_000 + 1 * 100 + 0,
15
+ .no, .gcc => 7 * 10_000 + 1 * 100 + 0,
15
16
  .msvc => 0,
16
17
  };
17
18
  }
18
19
  };
19
20
 
21
+ pub const BoundsSafety = enum {
22
+ none,
23
+ clang,
24
+ };
25
+
20
26
  /// The floating-point evaluation method for intermediate results within a single expression
21
27
  pub const FPEvalMethod = enum(i8) {
22
28
  /// The evaluation method cannot be determined or is inconsistent for this target.
@@ -116,7 +122,7 @@ pub const Standard = enum {
116
122
 
117
123
  const LangOpts = @This();
118
124
 
119
- emulate: Compiler = .clang,
125
+ emulate: Compiler = .no,
120
126
  standard: Standard = .default,
121
127
  /// -fshort-enums option, makes enums only take up as much space as they need to hold all the values.
122
128
  short_enums: bool = false,
@@ -149,6 +155,10 @@ preserve_comments_in_macros: bool = false,
149
155
  /// e.g. 4.2.1 == 40201
150
156
  gnuc_version: ?u32 = null,
151
157
 
158
+ bounds_safety: BoundsSafety = .none,
159
+
160
+ default_symbol_visibility: std.builtin.SymbolVisibility = .default,
161
+
152
162
  pub fn setStandard(self: *LangOpts, name: []const u8) error{InvalidStandard}!void {
153
163
  self.standard = Standard.NameMap.get(name) orelse return error.InvalidStandard;
154
164
  }
@@ -79,9 +79,9 @@ pub const expected_integer_constant_expr: Diagnostic = .{
79
79
  };
80
80
 
81
81
  pub const missing_type_specifier: Diagnostic = .{
82
- .fmt = "type specifier missing, defaults to 'int'",
82
+ .fmt = "type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int",
83
83
  .opt = .@"implicit-int",
84
- .kind = .warning,
84
+ .kind = .@"error",
85
85
  };
86
86
 
87
87
  pub const missing_type_specifier_c23: Diagnostic = .{
@@ -90,9 +90,9 @@ pub const missing_type_specifier_c23: Diagnostic = .{
90
90
  };
91
91
 
92
92
  pub const param_not_declared: Diagnostic = .{
93
- .fmt = "parameter '{s}' was not declared, defaults to 'int'",
93
+ .fmt = "parameter '{s}' was not declared, defaults to 'int'; ISO C99 and later do not support implicit int",
94
94
  .opt = .@"implicit-int",
95
- .kind = .warning,
95
+ .kind = .@"error",
96
96
  .extension = true,
97
97
  };
98
98
 
@@ -216,8 +216,13 @@ pub const illegal_storage_on_func: Diagnostic = .{
216
216
  .kind = .@"error",
217
217
  };
218
218
 
219
- pub const illegal_storage_on_global: Diagnostic = .{
220
- .fmt = "illegal storage class on global variable",
219
+ pub const auto_on_global: Diagnostic = .{
220
+ .fmt = "'auto' specified on global variable",
221
+ .kind = .@"error",
222
+ };
223
+
224
+ pub const register_on_global: Diagnostic = .{
225
+ .fmt = "register name not specified for global variable",
221
226
  .kind = .@"error",
222
227
  };
223
228
 
@@ -1507,13 +1512,38 @@ pub const builtin_must_be_called: Diagnostic = .{
1507
1512
  .kind = .@"error",
1508
1513
  };
1509
1514
 
1510
- pub const va_start_not_in_func: Diagnostic = .{
1511
- .fmt = "'va_start' cannot be used outside a function",
1515
+ pub const va_func_not_in_func: Diagnostic = .{
1516
+ .fmt = "'{s}' cannot be used outside a function",
1517
+ .kind = .@"error",
1518
+ };
1519
+
1520
+ pub const va_func_fixed_args: Diagnostic = .{
1521
+ .fmt = "'{s}' used in a function with fixed args",
1522
+ .kind = .@"error",
1523
+ };
1524
+
1525
+ pub const va_func_not_always_inline: Diagnostic = .{
1526
+ .fmt = "'{s}' used in a function that is not always inlined",
1527
+ .kind = .@"error",
1528
+ };
1529
+
1530
+ pub const va_pack_non_call: Diagnostic = .{
1531
+ .fmt = "'__va_arg_pack' used outside a call",
1532
+ .kind = .@"error",
1533
+ };
1534
+
1535
+ pub const va_pack_non_variadic_call: Diagnostic = .{
1536
+ .fmt = "'__va_arg_pack' passed to non-variadic function",
1537
+ .kind = .@"error",
1538
+ };
1539
+
1540
+ pub const va_pack_non_variadic_arg: Diagnostic = .{
1541
+ .fmt = "'__va_arg_pack' passed as non-variadic argument",
1512
1542
  .kind = .@"error",
1513
1543
  };
1514
1544
 
1515
- pub const va_start_fixed_args: Diagnostic = .{
1516
- .fmt = "'va_start' used in a function with fixed args",
1545
+ pub const va_pack_non_final_arg: Diagnostic = .{
1546
+ .fmt = "'__va_arg_pack' is not the final argument",
1517
1547
  .kind = .@"error",
1518
1548
  };
1519
1549
 
@@ -2258,11 +2288,11 @@ pub const unterminated_char_literal_error: Diagnostic = .{
2258
2288
  .kind = .@"error",
2259
2289
  };
2260
2290
 
2261
- // pub const def_no_proto_deprecated: Diagnostic = .{
2262
- // .fmt = "a function definition without a prototype is deprecated in all versions of C and is not supported in C23",
2263
- // .kind = .warning,
2264
- // .opt = .@"deprecated-non-prototype",
2265
- // };
2291
+ pub const def_no_proto_deprecated: Diagnostic = .{
2292
+ .fmt = "a function definition without a prototype is deprecated in all versions of C and is not supported in C23",
2293
+ .kind = .warning,
2294
+ .opt = .@"deprecated-non-prototype",
2295
+ };
2266
2296
 
2267
2297
  pub const passing_args_to_kr: Diagnostic = .{
2268
2298
  .fmt = "passing arguments to a function without a prototype is deprecated in all versions of C and is not supported in C23",
@@ -2296,6 +2326,11 @@ pub const invalid_compound_literal_storage_class: Diagnostic = .{
2296
2326
  .kind = .@"error",
2297
2327
  };
2298
2328
 
2329
+ pub const register_on_global_compound_literal: Diagnostic = .{
2330
+ .fmt = "file scope compound literal specifies 'register'",
2331
+ .kind = .@"error",
2332
+ };
2333
+
2299
2334
  pub const identifier_not_normalized: Diagnostic = .{
2300
2335
  .fmt = "'{normalized}' is not in NFC",
2301
2336
  .kind = .warning,
@@ -2465,10 +2500,9 @@ pub const declared_const_here: Diagnostic = .{
2465
2500
  .kind = .note,
2466
2501
  };
2467
2502
 
2468
- pub const nonnull_not_applicable: Diagnostic = .{
2469
- .fmt = "'nonnull' attribute only applies to functions, methods, and parameters",
2470
- .kind = .warning,
2471
- .opt = .@"ignored-attributes",
2503
+ pub const pointer_bounds_declared_here: Diagnostic = .{
2504
+ .fmt = "pointer '{s}' declared {s} here",
2505
+ .kind = .note,
2472
2506
  };
2473
2507
 
2474
2508
  pub const mixing_decimal_floats: Diagnostic = .{
@@ -2480,3 +2514,29 @@ pub const invalid_attribute_location: Diagnostic = .{
2480
2514
  .fmt = "{s} cannot appear here",
2481
2515
  .kind = .@"error",
2482
2516
  };
2517
+
2518
+ pub const attribute_requires_pointer: Diagnostic = .{
2519
+ .fmt = "'{s}' attribute only applies to pointer arguments",
2520
+ .kind = .@"error",
2521
+ };
2522
+
2523
+ pub const single_requires_zero_index: Diagnostic = .{
2524
+ .fmt = "array subscript on single pointer must use a constant index of 0 to be in bounds",
2525
+ .kind = .@"error",
2526
+ };
2527
+
2528
+ pub const pointer_arith_single: Diagnostic = .{
2529
+ .fmt = "pointer arithmetic on single pointer is out of bounds; consider adding '__counted_by'",
2530
+ .kind = .@"error",
2531
+ };
2532
+
2533
+ pub const redundant_bounds_annotation: Diagnostic = .{
2534
+ .fmt = "pointer annotated with {s} multiple times. Annotate only once to remove this warning",
2535
+ .kind = .warning,
2536
+ .opt = .@"bounds-attributes-redundant",
2537
+ };
2538
+
2539
+ pub const multiple_bounds_annotations: Diagnostic = .{
2540
+ .fmt = "pointer cannot have more than one bound attribute",
2541
+ .kind = .@"error",
2542
+ };