@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
@@ -7,7 +7,9 @@ const Diagnostics = @import("Diagnostics.zig");
7
7
  const Parser = @import("Parser.zig");
8
8
  const Tree = @import("Tree.zig");
9
9
  const TokenIndex = Tree.TokenIndex;
10
- const QualType = @import("TypeStore.zig").QualType;
10
+ const TypeStore = @import("TypeStore.zig");
11
+ const Type = TypeStore.Type;
12
+ const QualType = TypeStore.QualType;
11
13
  const Value = @import("Value.zig");
12
14
 
13
15
  const Attribute = @This();
@@ -341,7 +343,6 @@ fn diagnoseField(
341
343
 
342
344
  pub fn diagnose(attr: Tag, arguments: *Arguments, arg_idx: u32, res: Parser.Result, arg_start: TokenIndex, node: Tree.Node, p: *Parser) !bool {
343
345
  switch (attr) {
344
- .nonnull => return false,
345
346
  inline else => |tag| {
346
347
  const decl = @typeInfo(attributes).@"struct".decls[@intFromEnum(tag)];
347
348
  const max_arg_count = comptime maxArgCount(tag);
@@ -529,7 +530,10 @@ const attributes = struct {
529
530
  pub const @"noinline" = struct {};
530
531
  pub const noipa = struct {};
531
532
  // TODO: arbitrary number of arguments
532
- pub const nonnull = struct {};
533
+ // const nonnull = struct {
534
+ // // arg_index: []const u32,
535
+ // };
536
+ // };
533
537
  pub const nonstring = struct {};
534
538
  pub const noplt = struct {};
535
539
  pub const @"noreturn" = struct {};
@@ -577,6 +581,7 @@ const attributes = struct {
577
581
  };
578
582
  } = null,
579
583
  };
584
+ pub const single = struct {};
580
585
  pub const spectre = struct {
581
586
  arg: enum {
582
587
  nomitigation,
@@ -618,6 +623,7 @@ const attributes = struct {
618
623
  __name_tok: TokenIndex,
619
624
  };
620
625
  pub const uninitialized = struct {};
626
+ pub const unsafe_indexable = struct {};
621
627
  pub const unsequenced = struct {};
622
628
  pub const unused = struct {};
623
629
  pub const used = struct {};
@@ -723,6 +729,7 @@ pub const Arguments = blk: {
723
729
  name.* = decl.name;
724
730
  T.* = @field(attributes, decl.name);
725
731
  }
732
+
726
733
  break :blk @Union(.auto, null, &names, &types, &@splat(.{}));
727
734
  };
728
735
 
@@ -784,15 +791,8 @@ fn ignoredAttrErr(p: *Parser, tok: TokenIndex, attr: Attribute.Tag, context: []c
784
791
  try p.err(tok, .ignored_attribute, .{ @tagName(attr), context });
785
792
  }
786
793
 
787
- pub fn applyParameterAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diagnostic: ?Parser.Diagnostic) !QualType {
788
- return applyVariableOrParameterAttributes(p, qt, attr_buf_start, diagnostic, .parameter);
789
- }
790
-
794
+ pub const applyParameterAttributes = applyVariableAttributes;
791
795
  pub fn applyVariableAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diagnostic: ?Parser.Diagnostic) !QualType {
792
- return applyVariableOrParameterAttributes(p, qt, attr_buf_start, diagnostic, .variable);
793
- }
794
-
795
- fn applyVariableOrParameterAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diagnostic: ?Parser.Diagnostic, context: enum { parameter, variable }) !QualType {
796
796
  const gpa = p.comp.gpa;
797
797
  const attrs = p.attr_buf.items(.attr)[attr_buf_start..];
798
798
  const toks = p.attr_buf.items(.tok)[attr_buf_start..];
@@ -804,6 +804,7 @@ fn applyVariableOrParameterAttributes(p: *Parser, qt: QualType, attr_buf_start:
804
804
  // zig fmt: off
805
805
  .alias, .may_alias, .deprecated, .unavailable, .unused, .warn_if_not_aligned, .weak, .used,
806
806
  .noinit, .retain, .persistent, .section, .mode, .asm_label, .nullability, .unaligned, .selectany, .internal_linkage,
807
+ .visibility,
807
808
  => try p.attr_application_buf.append(gpa, attr),
808
809
  // zig fmt: on
809
810
  .common => if (nocommon) {
@@ -820,12 +821,6 @@ fn applyVariableOrParameterAttributes(p: *Parser, qt: QualType, attr_buf_start:
820
821
  },
821
822
  .vector_size => try attr.applyVectorSize(p, tok, &base_qt),
822
823
  .aligned => try attr.applyAligned(p, base_qt, diagnostic),
823
- .nonnull => {
824
- switch (context) {
825
- .parameter => try p.err(tok, .attribute_todo, .{ "nonnull", "parameters" }),
826
- .variable => try p.err(tok, .nonnull_not_applicable, .{}),
827
- }
828
- },
829
824
  .nonstring => {
830
825
  if (base_qt.get(p.comp, .array)) |array_ty| {
831
826
  if (array_ty.elem.get(p.comp, .int)) |int_ty| switch (int_ty) {
@@ -848,11 +843,28 @@ fn applyVariableOrParameterAttributes(p: *Parser, qt: QualType, attr_buf_start:
848
843
  } else {
849
844
  try p.attr_application_buf.append(gpa, attr);
850
845
  },
851
- .calling_convention => try applyCallingConvention(attr, p, tok, base_qt),
846
+ .single,
847
+ .unsafe_indexable,
848
+ => try applyBoundsSafetyAttr(.fromTag(attr.tag), p, tok, &base_qt),
849
+
850
+ .calling_convention => try applyKeywordCallingConvention(attr, p, tok, base_qt),
851
+
852
+ .fastcall,
853
+ .stdcall,
854
+ .thiscall,
855
+ .vectorcall,
856
+ .cdecl,
857
+ .pcs,
858
+ .riscv_vector_cc,
859
+ .aarch64_sve_pcs,
860
+ .aarch64_vector_pcs,
861
+ .sysv_abi,
862
+ .ms_abi,
863
+ => try applyGnuAttrCallingConvention(attr, p, tok, base_qt),
864
+
852
865
  .alloc_size,
853
866
  .copy,
854
867
  .tls_model,
855
- .visibility,
856
868
  => |t| try p.err(tok, .attribute_todo, .{ @tagName(t), "variables" }),
857
869
  // There is already an error in Parser for _Noreturn keyword
858
870
  .noreturn => if (attr.syntax != .keyword) try ignoredAttrErr(p, tok, attr.tag, "variables"),
@@ -903,7 +915,25 @@ pub fn applyTypeAttributes(p: *Parser, qt: QualType, attr_buf_start: usize, diag
903
915
  } else {
904
916
  try p.err(tok, .designated_init_invalid, .{});
905
917
  },
906
- .calling_convention => try applyCallingConvention(attr, p, tok, base_qt),
918
+ .calling_convention => try applyKeywordCallingConvention(attr, p, tok, base_qt),
919
+
920
+ .fastcall,
921
+ .stdcall,
922
+ .thiscall,
923
+ .vectorcall,
924
+ .cdecl,
925
+ .pcs,
926
+ .riscv_vector_cc,
927
+ .aarch64_sve_pcs,
928
+ .aarch64_vector_pcs,
929
+ .sysv_abi,
930
+ .ms_abi,
931
+ => try applyGnuAttrCallingConvention(attr, p, tok, base_qt),
932
+
933
+ .single,
934
+ .unsafe_indexable,
935
+ => try applyBoundsSafetyAttr(.fromTag(attr.tag), p, tok, &base_qt),
936
+
907
937
  .alloc_size,
908
938
  .copy,
909
939
  .scalar_storage_order,
@@ -931,6 +961,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
931
961
  .@"const", .warn_unused_result, .section, .returns_nonnull, .returns_twice, .@"error",
932
962
  .externally_visible, .retain, .flatten, .gnu_inline, .alias, .asm_label, .nodiscard,
933
963
  .reproducible, .unsequenced, .nothrow, .nullability, .unaligned, .internal_linkage,
964
+ .visibility,
934
965
  => try p.attr_application_buf.append(gpa, attr),
935
966
  // zig fmt: on
936
967
  .hot => if (cold) {
@@ -959,97 +990,21 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
959
990
  },
960
991
  .aligned => try attr.applyAligned(p, base_qt, null),
961
992
  .format => try attr.applyFormat(p, base_qt),
962
- .calling_convention => try applyCallingConvention(attr, p, tok, base_qt),
963
- .fastcall => if (p.comp.target.cpu.arch == .x86) {
964
- try p.attr_application_buf.append(gpa, .{
965
- .tag = .calling_convention,
966
- .args = .{ .calling_convention = .{ .cc = .fastcall } },
967
- .syntax = attr.syntax,
968
- });
969
- } else {
970
- try p.err(tok, .callconv_not_supported, .{"fastcall"});
971
- },
972
- .stdcall => if (p.comp.target.cpu.arch == .x86) {
973
- try p.attr_application_buf.append(gpa, .{
974
- .tag = .calling_convention,
975
- .args = .{ .calling_convention = .{ .cc = .stdcall } },
976
- .syntax = attr.syntax,
977
- });
978
- } else {
979
- try p.err(tok, .callconv_not_supported, .{"stdcall"});
980
- },
981
- .thiscall => if (p.comp.target.cpu.arch == .x86) {
982
- try p.attr_application_buf.append(gpa, .{
983
- .tag = .calling_convention,
984
- .args = .{ .calling_convention = .{ .cc = .thiscall } },
985
- .syntax = attr.syntax,
986
- });
987
- } else {
988
- try p.err(tok, .callconv_not_supported, .{"thiscall"});
989
- },
990
- .vectorcall => if (p.comp.target.cpu.arch == .x86 or p.comp.target.cpu.arch.isAARCH64()) {
991
- try p.attr_application_buf.append(gpa, .{
992
- .tag = .calling_convention,
993
- .args = .{ .calling_convention = .{ .cc = .vectorcall } },
994
- .syntax = attr.syntax,
995
- });
996
- } else {
997
- try p.err(tok, .callconv_not_supported, .{"vectorcall"});
998
- },
999
- .cdecl => {},
1000
- .pcs => if (p.comp.target.cpu.arch.isArm()) {
1001
- try p.attr_application_buf.append(gpa, .{
1002
- .tag = .calling_convention,
1003
- .args = .{ .calling_convention = .{ .cc = switch (attr.args.pcs.kind) {
1004
- .aapcs => .arm_aapcs,
1005
- .@"aapcs-vfp" => .arm_aapcs_vfp,
1006
- } } },
1007
- .syntax = attr.syntax,
1008
- });
1009
- } else {
1010
- try p.err(tok, .callconv_not_supported, .{"pcs"});
1011
- },
1012
- .riscv_vector_cc => if (p.comp.target.cpu.arch.isRISCV()) {
1013
- try p.attr_application_buf.append(gpa, .{
1014
- .tag = .calling_convention,
1015
- .args = .{ .calling_convention = .{ .cc = .riscv_vector } },
1016
- .syntax = attr.syntax,
1017
- });
1018
- } else {
1019
- try p.err(tok, .callconv_not_supported, .{"pcs"});
1020
- },
1021
- .aarch64_sve_pcs => if (p.comp.target.cpu.arch.isAARCH64()) {
1022
- try p.attr_application_buf.append(gpa, .{
1023
- .tag = .calling_convention,
1024
- .args = .{ .calling_convention = .{ .cc = .aarch64_sve_pcs } },
1025
- .syntax = attr.syntax,
1026
- });
1027
- } else {
1028
- try p.err(tok, .callconv_not_supported, .{"pcs"});
1029
- },
1030
- .aarch64_vector_pcs => if (p.comp.target.cpu.arch.isAARCH64()) {
1031
- try p.attr_application_buf.append(gpa, .{
1032
- .tag = .calling_convention,
1033
- .args = .{ .calling_convention = .{ .cc = .aarch64_vector_pcs } },
1034
- .syntax = attr.syntax,
1035
- });
1036
- } else {
1037
- try p.err(tok, .callconv_not_supported, .{"pcs"});
1038
- },
1039
- .sysv_abi => if (p.comp.target.cpu.arch == .x86_64 and p.comp.target.os.tag == .windows) {
1040
- try p.attr_application_buf.append(gpa, .{
1041
- .tag = .calling_convention,
1042
- .args = .{ .calling_convention = .{ .cc = .x86_64_sysv } },
1043
- .syntax = attr.syntax,
1044
- });
1045
- },
1046
- .ms_abi => if (p.comp.target.cpu.arch == .x86_64 and p.comp.target.os.tag != .windows) {
1047
- try p.attr_application_buf.append(gpa, .{
1048
- .tag = .calling_convention,
1049
- .args = .{ .calling_convention = .{ .cc = .x86_64_win } },
1050
- .syntax = attr.syntax,
1051
- });
1052
- },
993
+ .calling_convention => try applyKeywordCallingConvention(attr, p, tok, base_qt),
994
+
995
+ .fastcall,
996
+ .stdcall,
997
+ .thiscall,
998
+ .vectorcall,
999
+ .cdecl,
1000
+ .pcs,
1001
+ .riscv_vector_cc,
1002
+ .aarch64_sve_pcs,
1003
+ .aarch64_vector_pcs,
1004
+ .sysv_abi,
1005
+ .ms_abi,
1006
+ => try applyGnuAttrCallingConvention(attr, p, tok, base_qt),
1007
+
1053
1008
  .malloc => {
1054
1009
  if (base_qt.get(p.comp, .func).?.return_type.isPointer(p.comp)) {
1055
1010
  try p.attr_application_buf.append(gpa, attr);
@@ -1102,7 +1057,7 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
1102
1057
  .no_stack_protector,
1103
1058
  .noclone,
1104
1059
  .noipa,
1105
- .nonnull,
1060
+ // .nonnull,
1106
1061
  .noplt,
1107
1062
  // .optimize,
1108
1063
  .patchable_function_entry,
@@ -1112,7 +1067,6 @@ pub fn applyFunctionAttributes(p: *Parser, qt: QualType, attr_buf_start: usize)
1112
1067
  .symver,
1113
1068
  .target,
1114
1069
  .target_clones,
1115
- .visibility,
1116
1070
  .weakref,
1117
1071
  .zero_call_used_regs,
1118
1072
  => |t| try p.err(tok, .attribute_todo, .{ @tagName(t), "functions" }),
@@ -1262,9 +1216,129 @@ fn applyFormat(attr: Attribute, p: *Parser, qt: QualType) !void {
1262
1216
  try p.attr_application_buf.append(p.comp.gpa, attr);
1263
1217
  }
1264
1218
 
1265
- fn applyCallingConvention(attr: Attribute, p: *Parser, tok: TokenIndex, qt: QualType) !void {
1266
- if (!qt.is(p.comp, .func)) {
1267
- return p.err(tok, .callconv_non_func, .{ p.tok_ids[tok].symbol(), qt });
1219
+ /// These come from GNU attributes like __attribute__((sysv_abi))
1220
+ fn applyGnuAttrCallingConvention(attr: Attribute, p: *Parser, tok: TokenIndex, qt: QualType) !void {
1221
+ if (!qt.isCallable(p.comp)) {
1222
+ return p.err(tok, .callconv_non_func, .{ p.tokSlice(tok), qt });
1223
+ }
1224
+ const gpa = p.comp.gpa;
1225
+ switch (attr.tag) {
1226
+ .fastcall => if (p.comp.target.cpu.arch == .x86) {
1227
+ try p.attr_application_buf.append(gpa, .{
1228
+ .tag = .calling_convention,
1229
+ .args = .{ .calling_convention = .{ .cc = .fastcall } },
1230
+ .syntax = attr.syntax,
1231
+ });
1232
+ } else {
1233
+ try p.err(tok, .callconv_not_supported, .{"fastcall"});
1234
+ },
1235
+ .stdcall => if (p.comp.target.cpu.arch == .x86) {
1236
+ try p.attr_application_buf.append(gpa, .{
1237
+ .tag = .calling_convention,
1238
+ .args = .{ .calling_convention = .{ .cc = .stdcall } },
1239
+ .syntax = attr.syntax,
1240
+ });
1241
+ } else {
1242
+ try p.err(tok, .callconv_not_supported, .{"stdcall"});
1243
+ },
1244
+ .thiscall => if (p.comp.target.cpu.arch == .x86) {
1245
+ try p.attr_application_buf.append(gpa, .{
1246
+ .tag = .calling_convention,
1247
+ .args = .{ .calling_convention = .{ .cc = .thiscall } },
1248
+ .syntax = attr.syntax,
1249
+ });
1250
+ } else {
1251
+ try p.err(tok, .callconv_not_supported, .{"thiscall"});
1252
+ },
1253
+ .vectorcall => if (p.comp.target.cpu.arch == .x86 or p.comp.target.cpu.arch.isAARCH64()) {
1254
+ try p.attr_application_buf.append(gpa, .{
1255
+ .tag = .calling_convention,
1256
+ .args = .{ .calling_convention = .{ .cc = .vectorcall } },
1257
+ .syntax = attr.syntax,
1258
+ });
1259
+ } else {
1260
+ try p.err(tok, .callconv_not_supported, .{"vectorcall"});
1261
+ },
1262
+ .cdecl => {},
1263
+ .pcs => if (p.comp.target.cpu.arch.isArm()) {
1264
+ try p.attr_application_buf.append(gpa, .{
1265
+ .tag = .calling_convention,
1266
+ .args = .{ .calling_convention = .{ .cc = switch (attr.args.pcs.kind) {
1267
+ .aapcs => .arm_aapcs,
1268
+ .@"aapcs-vfp" => .arm_aapcs_vfp,
1269
+ } } },
1270
+ .syntax = attr.syntax,
1271
+ });
1272
+ } else {
1273
+ try p.err(tok, .callconv_not_supported, .{"pcs"});
1274
+ },
1275
+ .riscv_vector_cc => if (p.comp.target.cpu.arch.isRISCV()) {
1276
+ try p.attr_application_buf.append(gpa, .{
1277
+ .tag = .calling_convention,
1278
+ .args = .{ .calling_convention = .{ .cc = .riscv_vector } },
1279
+ .syntax = attr.syntax,
1280
+ });
1281
+ } else {
1282
+ try p.err(tok, .callconv_not_supported, .{"pcs"});
1283
+ },
1284
+ .aarch64_sve_pcs => if (p.comp.target.cpu.arch.isAARCH64()) {
1285
+ try p.attr_application_buf.append(gpa, .{
1286
+ .tag = .calling_convention,
1287
+ .args = .{ .calling_convention = .{ .cc = .aarch64_sve_pcs } },
1288
+ .syntax = attr.syntax,
1289
+ });
1290
+ } else {
1291
+ try p.err(tok, .callconv_not_supported, .{"pcs"});
1292
+ },
1293
+ .aarch64_vector_pcs => if (p.comp.target.cpu.arch.isAARCH64()) {
1294
+ try p.attr_application_buf.append(gpa, .{
1295
+ .tag = .calling_convention,
1296
+ .args = .{ .calling_convention = .{ .cc = .aarch64_vector_pcs } },
1297
+ .syntax = attr.syntax,
1298
+ });
1299
+ } else {
1300
+ try p.err(tok, .callconv_not_supported, .{"pcs"});
1301
+ },
1302
+ .sysv_abi => if (p.comp.target.cpu.arch == .x86_64 and p.comp.target.os.tag == .windows) {
1303
+ try p.attr_application_buf.append(gpa, .{
1304
+ .tag = .calling_convention,
1305
+ .args = .{ .calling_convention = .{ .cc = .x86_64_sysv } },
1306
+ .syntax = attr.syntax,
1307
+ });
1308
+ },
1309
+ .ms_abi => if (p.comp.target.cpu.arch == .x86_64 and p.comp.target.os.tag != .windows) {
1310
+ try p.attr_application_buf.append(gpa, .{
1311
+ .tag = .calling_convention,
1312
+ .args = .{ .calling_convention = .{ .cc = .x86_64_win } },
1313
+ .syntax = attr.syntax,
1314
+ });
1315
+ },
1316
+ else => unreachable,
1317
+ }
1318
+ }
1319
+
1320
+ fn applyBoundsSafetyAttr(bounds: Type.Pointer.Bounds, p: *Parser, tok: TokenIndex, qt: *QualType) !void {
1321
+ if (qt.isInvalid()) return;
1322
+ const pointer = qt.get(p.comp, .pointer) orelse {
1323
+ return p.err(tok, .attribute_requires_pointer, .{@tagName(bounds)});
1324
+ };
1325
+ if (pointer.bounds == bounds) {
1326
+ return p.err(tok, .redundant_bounds_annotation, .{@tagName(bounds)});
1327
+ }
1328
+ if (pointer.bounds != .c) {
1329
+ return p.err(tok, .multiple_bounds_annotations, .{});
1330
+ }
1331
+ qt.* = try p.comp.type_store.put(p.comp.gpa, .{ .pointer = .{
1332
+ .child = pointer.child,
1333
+ .decayed = pointer.decayed,
1334
+ .bounds = bounds,
1335
+ } });
1336
+ }
1337
+
1338
+ /// These come from explicit MSVC keywords like __stdcall, __fastcall, etc
1339
+ fn applyKeywordCallingConvention(attr: Attribute, p: *Parser, tok: TokenIndex, qt: QualType) !void {
1340
+ if (!qt.isCallable(p.comp)) {
1341
+ return p.err(tok, .callconv_non_func, .{ p.tokSlice(tok), qt });
1268
1342
  }
1269
1343
  switch (attr.args.calling_convention.cc) {
1270
1344
  .c => {},
@@ -1295,3 +1369,15 @@ fn applySelected(qt: QualType, p: *Parser) !QualType {
1295
1369
  .attributes = p.attr_application_buf.items,
1296
1370
  } })).withQualifiers(qt);
1297
1371
  }
1372
+
1373
+ pub fn visibilityFromString(s: []const u8) ?std.builtin.SymbolVisibility {
1374
+ if (mem.eql(u8, s, "internal")) {
1375
+ return .hidden;
1376
+ }
1377
+ const visibility = std.meta.stringToEnum(std.builtin.SymbolVisibility, s) orelse return null;
1378
+ // compiler will notify us if .internal is added as a visibility type
1379
+ switch (visibility) {
1380
+ .default, .hidden, .protected => {},
1381
+ }
1382
+ return visibility;
1383
+ }