authorgravatar for evan@lagerdata.comEvan Haas <evan@lagerdata.com> 2021-08-31 13:33:44-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-01 17:54:07-07:00
logf5553bfefcca2690b557ea080d8ae431b7d9b5d9
treec2149c305441eeb6683a28effaf4a2e680bc69ac
parentdf589eecd61a4a2c93922302f8f486f18d0ff06b

translate-c: Only consider public decls in isBuiltinDefined


2 files changed, 7 insertions(+), 0 deletions(-)

src/translate_c.zig+1
...@@ -1990,6 +1990,7 @@ fn transImplicitCastExpr(...@@ -1990,6 +1990,7 @@ fn transImplicitCastExpr(
19901990
1991fn isBuiltinDefined(name: []const u8) bool {1991fn isBuiltinDefined(name: []const u8) bool {
1992 inline for (meta.declarations(std.zig.c_builtins)) |decl| {1992 inline for (meta.declarations(std.zig.c_builtins)) |decl| {
1993 if (!decl.is_pub) continue;
1993 if (std.mem.eql(u8, name, decl.name)) return true;1994 if (std.mem.eql(u8, name, decl.name)) return true;
1994 }1995 }
1995 return false;1996 return false;
test/translate_c.zig+6
...@@ -3672,4 +3672,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -3672,4 +3672,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
3672 , &[_][]const u8{3672 , &[_][]const u8{
3673 \\pub const FOO = __builtin_popcount;3673 \\pub const FOO = __builtin_popcount;
3674 });3674 });
3675
3676 cases.add("Only consider public decls in `isBuiltinDefined`",
3677 \\#define FOO std
3678 , &[_][]const u8{
3679 \\pub const FOO = @compileError("unable to translate macro: undefined identifier `std`");
3680 });
3675}3681}