@zigc/lib 0.16.0-test.0 → 0.16.0

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 (241) 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 +1 -17
  111. package/std/os/linux.zig +7 -2
  112. package/std/os/windows.zig +2 -2
  113. package/std/pdb.zig +143 -4
  114. package/std/posix.zig +6 -12
  115. package/std/priority_dequeue.zig +13 -12
  116. package/std/priority_queue.zig +5 -4
  117. package/std/process/Child.zig +1 -1
  118. package/std/process/Environ.zig +1 -1
  119. package/std/start.zig +17 -4
  120. package/std/std.zig +19 -6
  121. package/std/testing/FailingAllocator.zig +4 -4
  122. package/std/testing/Smith.zig +37 -2
  123. package/std/zig/Ast/Render.zig +186 -458
  124. package/std/zig/Ast.zig +0 -4
  125. package/std/zig/AstGen.zig +44 -7
  126. package/std/zig/AstSmith.zig +2602 -0
  127. package/std/zig/Client.zig +8 -3
  128. package/std/zig/Parse.zig +83 -74
  129. package/std/zig/Server.zig +26 -0
  130. package/std/zig/Zir.zig +17 -0
  131. package/std/zig/c_translation/helpers.zig +14 -9
  132. package/std/zig/llvm/Builder.zig +107 -48
  133. package/std/zig/system.zig +20 -4
  134. package/std/zig/tokenizer.zig +2 -1
  135. package/std/zig.zig +6 -0
  136. package/compiler/aro/aro/Driver/Filesystem.zig +0 -241
  137. package/libc/mingw/complex/cabs.c +0 -48
  138. package/libc/mingw/complex/cabsf.c +0 -48
  139. package/libc/mingw/complex/cacos.c +0 -50
  140. package/libc/mingw/complex/cacosf.c +0 -50
  141. package/libc/mingw/complex/carg.c +0 -48
  142. package/libc/mingw/complex/cargf.c +0 -48
  143. package/libc/mingw/complex/casin.c +0 -50
  144. package/libc/mingw/complex/casinf.c +0 -50
  145. package/libc/mingw/complex/catan.c +0 -50
  146. package/libc/mingw/complex/catanf.c +0 -50
  147. package/libc/mingw/complex/ccos.c +0 -50
  148. package/libc/mingw/complex/ccosf.c +0 -50
  149. package/libc/mingw/complex/cexp.c +0 -48
  150. package/libc/mingw/complex/cexpf.c +0 -48
  151. package/libc/mingw/complex/cimag.c +0 -48
  152. package/libc/mingw/complex/cimagf.c +0 -48
  153. package/libc/mingw/complex/clog.c +0 -48
  154. package/libc/mingw/complex/clog10.c +0 -49
  155. package/libc/mingw/complex/clog10f.c +0 -49
  156. package/libc/mingw/complex/clogf.c +0 -48
  157. package/libc/mingw/complex/conj.c +0 -48
  158. package/libc/mingw/complex/conjf.c +0 -48
  159. package/libc/mingw/complex/cpow.c +0 -48
  160. package/libc/mingw/complex/cpowf.c +0 -48
  161. package/libc/mingw/complex/cproj.c +0 -48
  162. package/libc/mingw/complex/cprojf.c +0 -48
  163. package/libc/mingw/complex/creal.c +0 -48
  164. package/libc/mingw/complex/crealf.c +0 -48
  165. package/libc/mingw/complex/csin.c +0 -50
  166. package/libc/mingw/complex/csinf.c +0 -50
  167. package/libc/mingw/complex/csqrt.c +0 -48
  168. package/libc/mingw/complex/csqrtf.c +0 -48
  169. package/libc/mingw/complex/ctan.c +0 -50
  170. package/libc/mingw/complex/ctanf.c +0 -50
  171. package/libc/mingw/math/arm/s_rint.c +0 -86
  172. package/libc/mingw/math/arm/s_rintf.c +0 -51
  173. package/libc/mingw/math/arm/sincos.S +0 -30
  174. package/libc/mingw/math/arm-common/sincosl.c +0 -13
  175. package/libc/mingw/math/arm64/rint.c +0 -12
  176. package/libc/mingw/math/arm64/rintf.c +0 -12
  177. package/libc/mingw/math/arm64/sincos.S +0 -32
  178. package/libc/mingw/math/bsd_private_base.h +0 -148
  179. package/libc/mingw/math/frexpf.c +0 -13
  180. package/libc/mingw/math/frexpl.c +0 -71
  181. package/libc/mingw/math/x86/acosf.c +0 -29
  182. package/libc/mingw/math/x86/atanf.c +0 -23
  183. package/libc/mingw/math/x86/atanl.c +0 -18
  184. package/libc/mingw/math/x86/cos.def.h +0 -65
  185. package/libc/mingw/math/x86/cosl.c +0 -46
  186. package/libc/mingw/math/x86/cosl_internal.S +0 -55
  187. package/libc/mingw/math/x86/ldexp.c +0 -23
  188. package/libc/mingw/math/x86/scalbn.S +0 -41
  189. package/libc/mingw/math/x86/scalbnf.S +0 -40
  190. package/libc/mingw/math/x86/sin.def.h +0 -65
  191. package/libc/mingw/math/x86/sinl.c +0 -46
  192. package/libc/mingw/math/x86/sinl_internal.S +0 -58
  193. package/libc/mingw/math/x86/tanl.S +0 -62
  194. package/libc/mingw/misc/btowc.c +0 -28
  195. package/libc/mingw/misc/wcstof.c +0 -66
  196. package/libc/mingw/misc/wcstoimax.c +0 -132
  197. package/libc/mingw/misc/wcstoumax.c +0 -126
  198. package/libc/mingw/misc/wctob.c +0 -29
  199. package/libc/mingw/misc/winbs_uint64.c +0 -6
  200. package/libc/mingw/misc/winbs_ulong.c +0 -6
  201. package/libc/mingw/misc/winbs_ushort.c +0 -6
  202. package/libc/mingw/stdio/_Exit.c +0 -10
  203. package/libc/mingw/stdio/_findfirst64i32.c +0 -21
  204. package/libc/mingw/stdio/_findnext64i32.c +0 -21
  205. package/libc/mingw/stdio/_fstat64i32.c +0 -37
  206. package/libc/mingw/stdio/_stat64i32.c +0 -37
  207. package/libc/mingw/stdio/_wfindfirst64i32.c +0 -21
  208. package/libc/mingw/stdio/_wfindnext64i32.c +0 -21
  209. package/libc/mingw/stdio/_wstat64i32.c +0 -37
  210. package/libc/musl/src/legacy/isastream.c +0 -7
  211. package/libc/musl/src/legacy/valloc.c +0 -8
  212. package/libc/musl/src/math/__cosl.c +0 -96
  213. package/libc/musl/src/math/__sinl.c +0 -78
  214. package/libc/musl/src/math/__tanl.c +0 -143
  215. package/libc/musl/src/math/aarch64/lrint.c +0 -10
  216. package/libc/musl/src/math/aarch64/lrintf.c +0 -10
  217. package/libc/musl/src/math/aarch64/rintf.c +0 -7
  218. package/libc/musl/src/math/cosl.c +0 -39
  219. package/libc/musl/src/math/fdim.c +0 -10
  220. package/libc/musl/src/math/finite.c +0 -7
  221. package/libc/musl/src/math/finitef.c +0 -7
  222. package/libc/musl/src/math/frexp.c +0 -23
  223. package/libc/musl/src/math/frexpf.c +0 -23
  224. package/libc/musl/src/math/frexpl.c +0 -29
  225. package/libc/musl/src/math/i386/lrint.c +0 -8
  226. package/libc/musl/src/math/i386/lrintf.c +0 -8
  227. package/libc/musl/src/math/i386/rintf.c +0 -7
  228. package/libc/musl/src/math/lrint.c +0 -72
  229. package/libc/musl/src/math/lrintf.c +0 -8
  230. package/libc/musl/src/math/powerpc64/lrint.c +0 -16
  231. package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
  232. package/libc/musl/src/math/rintf.c +0 -30
  233. package/libc/musl/src/math/s390x/rintf.c +0 -15
  234. package/libc/musl/src/math/sincosl.c +0 -60
  235. package/libc/musl/src/math/sinl.c +0 -41
  236. package/libc/musl/src/math/tanl.c +0 -29
  237. package/libc/musl/src/math/x32/lrint.s +0 -5
  238. package/libc/musl/src/math/x32/lrintf.s +0 -5
  239. package/libc/musl/src/math/x86_64/lrint.c +0 -8
  240. package/libc/musl/src/math/x86_64/lrintf.c +0 -8
  241. package/libc/wasi/libc-bottom-half/sources/reallocarray.c +0 -14
@@ -219,9 +219,9 @@ pub const QualType = packed struct(u32) {
219
219
  .float_dfloat64 => return .{ .float = .dfloat64 },
220
220
  .float_dfloat128 => return .{ .float = .dfloat128 },
221
221
  .float_dfloat64x => return .{ .float = .dfloat64x },
222
- .void_pointer => return .{ .pointer = .{ .child = .void, .decayed = null } },
223
- .char_pointer => return .{ .pointer = .{ .child = .char, .decayed = null } },
224
- .int_pointer => return .{ .pointer = .{ .child = .int, .decayed = null } },
222
+ .void_pointer => return .{ .pointer = .{ .child = .void } },
223
+ .char_pointer => return .{ .pointer = .{ .child = .char } },
224
+ .int_pointer => return .{ .pointer = .{ .child = .int } },
225
225
 
226
226
  else => {},
227
227
  }
@@ -280,7 +280,7 @@ pub const QualType = packed struct(u32) {
280
280
  },
281
281
  .pointer => .{ .pointer = .{
282
282
  .child = @bitCast(repr.data[0]),
283
- .decayed = null,
283
+ .bounds = @enumFromInt(repr.data[1]),
284
284
  } },
285
285
  .pointer_decayed => .{ .pointer = .{
286
286
  .child = @bitCast(repr.data[0]),
@@ -800,7 +800,6 @@ pub const QualType = packed struct(u32) {
800
800
 
801
801
  return comp.type_store.put(comp.gpa, .{ .pointer = .{
802
802
  .child = qt,
803
- .decayed = null,
804
803
  } });
805
804
  },
806
805
  else => return qt,
@@ -1013,6 +1012,15 @@ pub const QualType = packed struct(u32) {
1013
1012
  return qt.scalarKind(comp).isPointer();
1014
1013
  }
1015
1014
 
1015
+ /// Function or function pointer
1016
+ pub fn isCallable(qt: QualType, comp: *const Compilation) bool {
1017
+ return switch (qt.base(comp).type) {
1018
+ .func => true,
1019
+ .pointer => |ptr| ptr.child.is(comp, .func),
1020
+ else => false,
1021
+ };
1022
+ }
1023
+
1016
1024
  pub fn eqlQualified(a_qt: QualType, b_qt: QualType, comp: *const Compilation) bool {
1017
1025
  if (a_qt.@"const" != b_qt.@"const") return false;
1018
1026
  if (a_qt.@"volatile" != b_qt.@"volatile") return false;
@@ -1632,7 +1640,25 @@ pub const Type = union(enum) {
1632
1640
 
1633
1641
  pub const Pointer = struct {
1634
1642
  child: QualType,
1635
- decayed: ?QualType,
1643
+ decayed: ?QualType = null,
1644
+ bounds: Bounds = .c,
1645
+
1646
+ pub const Bounds = enum {
1647
+ /// C pointer with no bounds attribute
1648
+ c,
1649
+ /// No pointer arithmetic or non-zero indexing
1650
+ single,
1651
+ /// Explicitly specified as a traditional C pointer
1652
+ unsafe_indexable,
1653
+
1654
+ pub fn fromTag(tag: Attribute.Tag) Bounds {
1655
+ return switch (tag) {
1656
+ .single => .single,
1657
+ .unsafe_indexable => .unsafe_indexable,
1658
+ else => unreachable,
1659
+ };
1660
+ }
1661
+ };
1636
1662
  };
1637
1663
 
1638
1664
  pub const Array = struct {
@@ -1784,6 +1810,7 @@ attributes: std.ArrayList(Attribute) = .empty,
1784
1810
  anon_name_arena: std.heap.ArenaAllocator.State = .{},
1785
1811
 
1786
1812
  wchar: QualType = .invalid,
1813
+ wint: QualType = .invalid,
1787
1814
  uint_least16_t: QualType = .invalid,
1788
1815
  uint_least32_t: QualType = .invalid,
1789
1816
  ptrdiff: QualType = .invalid,
@@ -1918,10 +1945,12 @@ pub fn set(ts: *TypeStore, gpa: std.mem.Allocator, ty: Type, index: usize) !void
1918
1945
  .pointer => |pointer| {
1919
1946
  repr.data[0] = @bitCast(pointer.child);
1920
1947
  if (pointer.decayed) |array| {
1948
+ std.debug.assert(pointer.bounds == .c);
1921
1949
  repr.tag = .pointer_decayed;
1922
1950
  repr.data[1] = @bitCast(array);
1923
1951
  } else {
1924
1952
  repr.tag = .pointer;
1953
+ repr.data[1] = @intFromEnum(pointer.bounds);
1925
1954
  }
1926
1955
  },
1927
1956
  .array => |array| {
@@ -2070,17 +2099,44 @@ pub fn set(ts: *TypeStore, gpa: std.mem.Allocator, ty: Type, index: usize) !void
2070
2099
 
2071
2100
  pub fn initNamedTypes(ts: *TypeStore, comp: *Compilation) !void {
2072
2101
  const os = comp.target.os.tag;
2073
- ts.wchar = switch (comp.target.cpu.arch) {
2074
- .xcore => .uchar,
2075
- .ve, .msp430 => .uint,
2076
- .arm, .armeb, .thumb, .thumbeb => if (os != .windows and os != .netbsd and os != .openbsd) .uint else .int,
2077
- .aarch64, .aarch64_be => if (!os.isDarwin() and os != .netbsd) .uint else .int,
2078
- .x86_64, .x86 => if (os == .windows) .ushort else .int,
2079
- else => .int,
2102
+ const arch = comp.target.cpu.arch;
2103
+ ts.wchar = switch (os) {
2104
+ .openbsd, .netbsd => .int,
2105
+ .ps4, .ps5 => .ushort,
2106
+ .uefi => .ushort,
2107
+ .windows => .ushort,
2108
+ .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => .int,
2109
+ else => switch (arch) {
2110
+ .aarch64, .aarch64_be => .uint,
2111
+ .arm, .armeb, .thumb, .thumbeb => .uint,
2112
+ .ve, .msp430 => .uint,
2113
+ .x86_64, .x86 => .int,
2114
+ .xcore => .uchar,
2115
+ else => .int,
2116
+ },
2117
+ };
2118
+
2119
+ ts.wint = switch (os) {
2120
+ .fuchsia => .uint,
2121
+ .linux => .uint,
2122
+ .openbsd => .int,
2123
+ .uefi => .ushort,
2124
+ .windows => .ushort,
2125
+ else => switch (arch) {
2126
+ .csky => .uint,
2127
+ .loongarch32, .loongarch64 => .uint,
2128
+ .riscv32, .riscv32be, .riscv64, .riscv64be => .uint,
2129
+ .ve => .uint,
2130
+ .xcore => .uint,
2131
+ .xtensa, .xtensaeb => .uint,
2132
+ else => .int,
2133
+ },
2080
2134
  };
2081
2135
 
2082
2136
  const ptr_width = comp.target.ptrBitWidth();
2083
- ts.ptrdiff = if (os == .windows and ptr_width == 64)
2137
+ ts.ptrdiff = if (arch == .wasm32)
2138
+ .long
2139
+ else if (os == .windows and ptr_width == 64)
2084
2140
  .long_long
2085
2141
  else switch (ptr_width) {
2086
2142
  16 => .int,
@@ -2089,7 +2145,9 @@ pub fn initNamedTypes(ts: *TypeStore, comp: *Compilation) !void {
2089
2145
  else => unreachable,
2090
2146
  };
2091
2147
 
2092
- ts.size = if (os == .windows and ptr_width == 64)
2148
+ ts.size = if (arch == .wasm32)
2149
+ .ulong
2150
+ else if (os == .windows and ptr_width == 64)
2093
2151
  .ulong_long
2094
2152
  else switch (ptr_width) {
2095
2153
  16 => .uint,
@@ -2206,9 +2264,9 @@ fn generateVaListType(ts: *TypeStore, comp: *Compilation) !QualType {
2206
2264
  };
2207
2265
 
2208
2266
  const struct_qt = switch (kind) {
2209
- .aarch64_va_list => blk: {
2267
+ .aarch64_va_list => {
2210
2268
  var record: Type.Record = .{
2211
- .name = try comp.internString("__va_list_tag"),
2269
+ .name = try comp.internString("__va_list"),
2212
2270
  .decl_node = undefined, // TODO
2213
2271
  .layout = null,
2214
2272
  .fields = &.{},
@@ -2226,11 +2284,11 @@ fn generateVaListType(ts: *TypeStore, comp: *Compilation) !QualType {
2226
2284
  record.layout = record_layout.compute(&fields, qt, comp, null) catch unreachable;
2227
2285
  try ts.set(comp.gpa, .{ .@"struct" = record }, @intFromEnum(qt._index));
2228
2286
 
2229
- break :blk qt;
2287
+ return qt;
2230
2288
  },
2231
- .arm_va_list => blk: {
2289
+ .arm_va_list => {
2232
2290
  var record: Type.Record = .{
2233
- .name = try comp.internString("__va_list_tag"),
2291
+ .name = try comp.internString("__va_list"),
2234
2292
  .decl_node = undefined, // TODO
2235
2293
  .layout = null,
2236
2294
  .fields = &.{},
@@ -2244,7 +2302,7 @@ fn generateVaListType(ts: *TypeStore, comp: *Compilation) !QualType {
2244
2302
  record.layout = record_layout.compute(&fields, qt, comp, null) catch unreachable;
2245
2303
  try ts.set(comp.gpa, .{ .@"struct" = record }, @intFromEnum(qt._index));
2246
2304
 
2247
- break :blk qt;
2305
+ return qt;
2248
2306
  },
2249
2307
  .hexagon_va_list => blk: {
2250
2308
  var record: Type.Record = .{
@@ -2330,7 +2388,7 @@ fn generateVaListType(ts: *TypeStore, comp: *Compilation) !QualType {
2330
2388
 
2331
2389
  break :blk qt;
2332
2390
  },
2333
- .xtensa_va_list => blk: {
2391
+ .xtensa_va_list => {
2334
2392
  var record: Type.Record = .{
2335
2393
  .name = try comp.internString("__va_list_tag"),
2336
2394
  .decl_node = undefined, // TODO
@@ -2348,7 +2406,7 @@ fn generateVaListType(ts: *TypeStore, comp: *Compilation) !QualType {
2348
2406
  record.layout = record_layout.compute(&fields, qt, comp, null) catch unreachable;
2349
2407
  try ts.set(comp.gpa, .{ .@"struct" = record }, @intFromEnum(qt._index));
2350
2408
 
2351
- break :blk qt;
2409
+ return qt;
2352
2410
  },
2353
2411
  };
2354
2412
 
@@ -2830,7 +2888,7 @@ pub const Builder = struct {
2830
2888
  }
2831
2889
 
2832
2890
  fn duplicateSpec(b: *Builder, source_tok: TokenIndex, spec: []const u8) !void {
2833
- if (b.parser.comp.langopts.emulate != .clang) return b.cannotCombine(source_tok);
2891
+ if (b.parser.comp.langopts.emulate == .gcc) return b.cannotCombine(source_tok);
2834
2892
  try b.parser.err(b.parser.tok_i, .duplicate_decl_spec, .{spec});
2835
2893
  }
2836
2894
 
@@ -1,5 +1,4 @@
1
1
  const std = @import("std");
2
- const Io = std.Io;
3
2
  const assert = std.debug.assert;
4
3
  const BigIntConst = std.math.big.int.Const;
5
4
  const BigIntMutable = std.math.big.int.Mutable;
@@ -9,8 +8,8 @@ const BigIntSpace = Interner.Tag.Int.BigIntSpace;
9
8
 
10
9
  const annex_g = @import("annex_g.zig");
11
10
  const Compilation = @import("Compilation.zig");
12
- const Target = @import("Target.zig");
13
11
  const QualType = @import("TypeStore.zig").QualType;
12
+ const Target = @import("Target.zig");
14
13
 
15
14
  const Value = @This();
16
15
 
@@ -77,11 +76,7 @@ test "minUnsignedBits" {
77
76
  }
78
77
  };
79
78
 
80
- var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator);
81
- defer arena_state.deinit();
82
- const arena = arena_state.allocator();
83
-
84
- var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, undefined, Io.Dir.cwd());
79
+ var comp = try Compilation.init(.testing);
85
80
  defer comp.deinit();
86
81
  const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" });
87
82
  comp.target = .fromZigTarget(try std.zig.system.resolveTargetQuery(std.testing.io, target_query));
@@ -116,11 +111,7 @@ test "minSignedBits" {
116
111
  }
117
112
  };
118
113
 
119
- var arena_state: std.heap.ArenaAllocator = .init(std.testing.allocator);
120
- defer arena_state.deinit();
121
- const arena = arena_state.allocator();
122
-
123
- var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, undefined, Io.Dir.cwd());
114
+ var comp = try Compilation.init(.testing);
124
115
  defer comp.deinit();
125
116
  const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" });
126
117
  comp.target = .fromZigTarget(try std.zig.system.resolveTargetQuery(std.testing.io, target_query));
@@ -465,6 +456,11 @@ pub fn isNan(v: Value, comp: *const Compilation) bool {
465
456
  };
466
457
  }
467
458
 
459
+ pub fn isPointer(v: Value, comp: *const Compilation) bool {
460
+ if (v.opt_ref == .none) return false;
461
+ return comp.interner.get(v.ref()) == .pointer;
462
+ }
463
+
468
464
  /// Converts value to zero or one;
469
465
  /// `.none` value remains unchanged.
470
466
  pub fn boolCast(v: *Value, comp: *const Compilation) void {
@@ -1044,9 +1040,9 @@ fn twosCompIntLimit(limit: std.math.big.int.TwosCompIntLimit, qt: QualType, comp
1044
1040
  const mag_bits: usize = @intCast(qt.bitSizeof(comp));
1045
1041
  switch (mag_bits) {
1046
1042
  inline 8, 16, 32, 64 => |bits| {
1047
- if (limit == .min) return Value.int(@as(i64, std.math.minInt(std.meta.Int(.signed, bits))), comp);
1043
+ if (limit == .min) return Value.int(@as(i64, std.math.minInt(@Int(.signed, bits))), comp);
1048
1044
  return switch (signedness) {
1049
- inline else => |sign| Value.int(std.math.maxInt(std.meta.Int(sign, bits)), comp),
1045
+ inline else => |sign| Value.int(std.math.maxInt(@Int(sign, bits)), comp),
1050
1046
  };
1051
1047
  },
1052
1048
  else => {},
@@ -1081,7 +1077,7 @@ const NestedPrint = union(enum) {
1081
1077
  },
1082
1078
  };
1083
1079
 
1084
- pub fn printPointer(offset: Value, base: []const u8, comp: *const Compilation, w: *Io.Writer) Io.Writer.Error!void {
1080
+ pub fn printPointer(offset: Value, base: []const u8, comp: *const Compilation, w: *std.Io.Writer) std.Io.Writer.Error!void {
1085
1081
  try w.writeByte('&');
1086
1082
  try w.writeAll(base);
1087
1083
  if (!offset.isZero(comp)) {
@@ -1090,7 +1086,7 @@ pub fn printPointer(offset: Value, base: []const u8, comp: *const Compilation, w
1090
1086
  }
1091
1087
  }
1092
1088
 
1093
- pub fn print(v: Value, qt: QualType, comp: *const Compilation, w: *Io.Writer) Io.Writer.Error!?NestedPrint {
1089
+ pub fn print(v: Value, qt: QualType, comp: *const Compilation, w: *std.Io.Writer) std.Io.Writer.Error!?NestedPrint {
1094
1090
  if (qt.is(comp, .bool)) {
1095
1091
  try w.writeAll(if (v.isZero(comp)) "false" else "true");
1096
1092
  return null;
@@ -1117,7 +1113,7 @@ pub fn print(v: Value, qt: QualType, comp: *const Compilation, w: *Io.Writer) Io
1117
1113
  return null;
1118
1114
  }
1119
1115
 
1120
- pub fn printString(bytes: []const u8, qt: QualType, comp: *const Compilation, w: *Io.Writer) Io.Writer.Error!void {
1116
+ pub fn printString(bytes: []const u8, qt: QualType, comp: *const Compilation, w: *std.Io.Writer) std.Io.Writer.Error!void {
1121
1117
  const size: Compilation.CharUnitSize = @enumFromInt(qt.childType(comp).sizeof(comp));
1122
1118
  const without_null = bytes[0 .. bytes.len - @intFromEnum(size)];
1123
1119
  try w.writeByte('"');
@@ -44,6 +44,7 @@ pub fn hasFeature(comp: *Compilation, ext: []const u8) bool {
44
44
  .c_generic_selections = comp.langopts.standard.atLeast(.c11),
45
45
  .c_static_assert = comp.langopts.standard.atLeast(.c11),
46
46
  .c_thread_local = comp.langopts.standard.atLeast(.c11) and comp.target.isTlsSupported(),
47
+ .bounds_attributes = comp.langopts.bounds_safety == .clang,
47
48
  };
48
49
  inline for (@typeInfo(@TypeOf(list)).@"struct".fields) |f| {
49
50
  if (std.mem.eql(u8, f.name, ext)) return @field(list, f.name);
@@ -35,7 +35,6 @@ fn deinit(pragma: *Pragma, comp: *Compilation) void {
35
35
  var self: *Once = @fieldParentPtr("pragma", pragma);
36
36
  self.pragma_once.deinit(comp.gpa);
37
37
  comp.gpa.destroy(self);
38
- pragma.* = undefined;
39
38
  }
40
39
 
41
40
  fn preprocessorHandler(pragma: *Pragma, pp: *Preprocessor, start_idx: TokenIndex) Pragma.Error!void {
@@ -332,7 +332,7 @@ const SysVContext = struct {
332
332
  }
333
333
  }
334
334
  } else {
335
- std.debug.assert(self.comp.langopts.emulate == .clang);
335
+ std.debug.assert(self.comp.langopts.emulate == .no or self.comp.langopts.emulate == .clang);
336
336
 
337
337
  // On Clang, the alignment requested by annotations is not respected if it is
338
338
  // larger than the value of #pragma pack. See test case 0083.
@@ -569,7 +569,7 @@ const MsvcContext = struct {
569
569
 
570
570
  pub fn compute(fields: []Type.Record.Field, qt: QualType, comp: *const Compilation, pragma_pack: ?u8) Error!Type.Record.Layout {
571
571
  switch (comp.langopts.emulate) {
572
- .gcc, .clang => {
572
+ .no, .gcc, .clang => {
573
573
  var context = SysVContext.init(qt, comp, pragma_pack);
574
574
 
575
575
  try context.layoutFields(fields);
@@ -620,7 +620,7 @@ fn computeLayout(qt: QualType, comp: *const Compilation) RecordLayout {
620
620
  else => {
621
621
  const type_align = qt.alignof(comp) * BITS_PER_BYTE;
622
622
  return .{
623
- .size_bits = qt.bitSizeofOrNull(comp) orelse 0,
623
+ .size_bits = BITS_PER_BYTE * (qt.sizeofOrNull(comp) orelse 0),
624
624
  .pointer_alignment_bits = type_align,
625
625
  .field_alignment_bits = type_align,
626
626
  .required_alignment_bits = BITS_PER_BYTE,
@@ -5,15 +5,14 @@ const assert = std.debug.assert;
5
5
  const aro = @import("aro");
6
6
  const Assembly = aro.Assembly;
7
7
  const Compilation = aro.Compilation;
8
- const Node = Tree.Node;
9
8
  const Source = aro.Source;
10
9
  const Tree = aro.Tree;
11
10
  const QualType = aro.QualType;
12
11
  const Value = aro.Value;
13
-
14
- const AsmCodeGen = @This();
15
12
  const Error = aro.Compilation.Error;
13
+ const Node = Tree.Node;
16
14
 
15
+ const AsmCodeGen = @This();
17
16
  tree: *const Tree,
18
17
  comp: *Compilation,
19
18
  text: *std.Io.Writer,
@@ -58,7 +57,7 @@ fn serializeFloat(comptime T: type, value: T, w: *std.Io.Writer) !void {
58
57
  },
59
58
  else => {
60
59
  const size = @bitSizeOf(T);
61
- const storage_unit = std.enums.fromInt(StorageUnit, size).?;
60
+ const storage_unit = std.enums.fromInt(StorageUnit, size) orelse unreachable;
62
61
  const IntTy = @Int(.unsigned, size);
63
62
  const int_val: IntTy = @bitCast(value);
64
63
  return serializeInt(int_val, storage_unit, w);
@@ -1,5 +1,4 @@
1
1
  const std = @import("std");
2
- const Io = std.Io;
3
2
  const Allocator = std.mem.Allocator;
4
3
 
5
4
  data: []const u8,
@@ -12,7 +11,7 @@ pub fn deinit(self: *const Assembly, gpa: Allocator) void {
12
11
  gpa.free(self.text);
13
12
  }
14
13
 
15
- pub fn writeToFile(self: Assembly, io: Io, file: Io.File) !void {
14
+ pub fn writeToFile(self: Assembly, io: std.Io, file: std.Io.File) !void {
16
15
  var file_writer = file.writer(io, &.{});
17
16
 
18
17
  var buffers = [_][]const u8{ self.data, self.text };
@@ -102,13 +102,13 @@ pub const Key = union(enum) {
102
102
  .float => |repr| switch (repr) {
103
103
  inline else => |data| std.hash.autoHash(
104
104
  &hasher,
105
- @as(std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(data))), @bitCast(data)),
105
+ @as(@Int(.unsigned, @bitSizeOf(@TypeOf(data))), @bitCast(data)),
106
106
  ),
107
107
  },
108
108
  .complex => |repr| switch (repr) {
109
109
  inline else => |data| std.hash.autoHash(
110
110
  &hasher,
111
- @as(std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(data))), @bitCast(data)),
111
+ @as(@Int(.unsigned, @bitSizeOf(@TypeOf(data))), @bitCast(data)),
112
112
  ),
113
113
  },
114
114
  .int => |repr| {