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 {...@@ -383,7 +383,7 @@ const attributes = struct {
383 write_only,383 write_only,
384 none,384 none,
385385
386 const opts = struct {386 pub const opts = struct {
387 const enum_kind = .identifier;387 const enum_kind = .identifier;
388 };388 };
389 },389 },
...@@ -454,7 +454,7 @@ const attributes = struct {...@@ -454,7 +454,7 @@ const attributes = struct {
454 strftime,454 strftime,
455 strfmon,455 strfmon,
456456
457 const opts = struct {457 pub const opts = struct {
458 const enum_kind = .identifier;458 const enum_kind = .identifier;
459 };459 };
460 },460 },
...@@ -500,7 +500,7 @@ const attributes = struct {...@@ -500,7 +500,7 @@ const attributes = struct {
500 BND32, BND64,500 BND32, BND64,
501 // zig fmt: on501 // zig fmt: on
502502
503 const opts = struct {503 pub const opts = struct {
504 const enum_kind = .identifier;504 const enum_kind = .identifier;
505 };505 };
506 },506 },
...@@ -560,7 +560,7 @@ const attributes = struct {...@@ -560,7 +560,7 @@ const attributes = struct {
560 @"little-endian",560 @"little-endian",
561 @"big-endian",561 @"big-endian",
562562
563 const opts = struct {563 pub const opts = struct {
564 const enum_kind = .string;564 const enum_kind = .string;
565 };565 };
566 },566 },
...@@ -577,7 +577,7 @@ const attributes = struct {...@@ -577,7 +577,7 @@ const attributes = struct {
577 notinbranch,577 notinbranch,
578 inbranch,578 inbranch,
579579
580 const opts = struct {580 pub const opts = struct {
581 const enum_kind = .string;581 const enum_kind = .string;
582 };582 };
583 } = null,583 } = null,
...@@ -587,7 +587,7 @@ const attributes = struct {...@@ -587,7 +587,7 @@ const attributes = struct {
587 arg: enum {587 arg: enum {
588 nomitigation,588 nomitigation,
589589
590 const opts = struct {590 pub const opts = struct {
591 const enum_kind = .identifier;591 const enum_kind = .identifier;
592 };592 };
593 },593 },
...@@ -613,7 +613,7 @@ const attributes = struct {...@@ -613,7 +613,7 @@ const attributes = struct {
613 @"initial-exec",613 @"initial-exec",
614 @"local-exec",614 @"local-exec",
615615
616 const opts = struct {616 pub const opts = struct {
617 const enum_kind = .string;617 const enum_kind = .string;
618 };618 };
619 },619 },
...@@ -642,7 +642,7 @@ const attributes = struct {...@@ -642,7 +642,7 @@ const attributes = struct {
642 internal,642 internal,
643 protected,643 protected,
644644
645 const opts = struct {645 pub const opts = struct {
646 const enum_kind = .string;646 const enum_kind = .string;
647 };647 };
648 },648 },
...@@ -671,7 +671,7 @@ const attributes = struct {...@@ -671,7 +671,7 @@ const attributes = struct {
671 @"all-arg",671 @"all-arg",
672 @"all-gpr-arg",672 @"all-gpr-arg",
673673
674 const opts = struct {674 pub const opts = struct {
675 const enum_kind = .string;675 const enum_kind = .string;
676 };676 };
677 },677 },
...@@ -689,7 +689,7 @@ const attributes = struct {...@@ -689,7 +689,7 @@ const attributes = struct {
689 nullable_result,689 nullable_result,
690 unspecified,690 unspecified,
691691
692 const opts = struct {692 pub const opts = struct {
693 const enum_kind = .identifier;693 const enum_kind = .identifier;
694 };694 };
695 },695 },
...@@ -700,7 +700,7 @@ const attributes = struct {...@@ -700,7 +700,7 @@ const attributes = struct {
700 aapcs,700 aapcs,
701 @"aapcs-vfp",701 @"aapcs-vfp",
702702
703 const opts = struct {703 pub const opts = struct {
704 const enum_kind = .string;704 const enum_kind = .string;
705 };705 };
706 },706 },