authorgravatar for jay@jayschwa.netJay Petacat <jay@jayschwa.net> 2026-08-29 17:09:01-06:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-08-31 11:36:19+02:00
logaad8da82a5cfd9b7602ee3adbff340c9c15d9165
tree3023950aae90f59ac3c5ac7b7602a0a18fa54397
parente00c6c43924f3c7cb42aea73be77f746dd908b1a

translate-c: Fix "error: attribute argument is invalid"

The recent change (ba74ad55) to `@hasDecl` requiring public declarations caused a regression in the vendored `translate-c`: ```c //example.h #define EXPORT __attribute__((visibility("default"))) EXPORT void example(void); ``` Running `zig translate-c example.h` yields: ``` error: translation failure src/example.h:2:1: error: attribute argument is invalid, expected a string but got a string EXPORT void repro_function(void); ^ src/example.h:1:42: note: expanded from here ``` The bug occurred because `Attribute.zig:319` has a branch condition of `@hasDecl(Wanted, "opts")`. The `opts` declarations exist in the same file and are not public. After the `@hasDecl` behavior change, the condition that may have previously been true is now false. The simple fix is to add `pub` to those `opts` declarations. I looked at the upstream Aro code and it seems significantly different. This particular branch condition no longer exists.

1 files changed, 11 insertions(+), 11 deletions(-)

lib/compiler/aro/aro/Attribute.zig+11-11
......@@ -383,7 +383,7 @@ const attributes = struct {
383383 write_only,
384384 none,
385385
386 const opts = struct {
386 pub const opts = struct {
387387 const enum_kind = .identifier;
388388 };
389389 },
......@@ -454,7 +454,7 @@ const attributes = struct {
454454 strftime,
455455 strfmon,
456456
457 const opts = struct {
457 pub const opts = struct {
458458 const enum_kind = .identifier;
459459 };
460460 },
......@@ -500,7 +500,7 @@ const attributes = struct {
500500 BND32, BND64,
501501 // zig fmt: on
502502
503 const opts = struct {
503 pub const opts = struct {
504504 const enum_kind = .identifier;
505505 };
506506 },
......@@ -560,7 +560,7 @@ const attributes = struct {
560560 @"little-endian",
561561 @"big-endian",
562562
563 const opts = struct {
563 pub const opts = struct {
564564 const enum_kind = .string;
565565 };
566566 },
......@@ -577,7 +577,7 @@ const attributes = struct {
577577 notinbranch,
578578 inbranch,
579579
580 const opts = struct {
580 pub const opts = struct {
581581 const enum_kind = .string;
582582 };
583583 } = null,
......@@ -587,7 +587,7 @@ const attributes = struct {
587587 arg: enum {
588588 nomitigation,
589589
590 const opts = struct {
590 pub const opts = struct {
591591 const enum_kind = .identifier;
592592 };
593593 },
......@@ -613,7 +613,7 @@ const attributes = struct {
613613 @"initial-exec",
614614 @"local-exec",
615615
616 const opts = struct {
616 pub const opts = struct {
617617 const enum_kind = .string;
618618 };
619619 },
......@@ -642,7 +642,7 @@ const attributes = struct {
642642 internal,
643643 protected,
644644
645 const opts = struct {
645 pub const opts = struct {
646646 const enum_kind = .string;
647647 };
648648 },
......@@ -671,7 +671,7 @@ const attributes = struct {
671671 @"all-arg",
672672 @"all-gpr-arg",
673673
674 const opts = struct {
674 pub const opts = struct {
675675 const enum_kind = .string;
676676 };
677677 },
......@@ -689,7 +689,7 @@ const attributes = struct {
689689 nullable_result,
690690 unspecified,
691691
692 const opts = struct {
692 pub const opts = struct {
693693 const enum_kind = .identifier;
694694 };
695695 },
......@@ -700,7 +700,7 @@ const attributes = struct {
700700 aapcs,
701701 @"aapcs-vfp",
702702
703 const opts = struct {
703 pub const opts = struct {
704704 const enum_kind = .string;
705705 };
706706 },