zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 88c5e2a96e09270a2ec3045639e7cab3712f5291 (tree)
parent 5ba143e7e3418719cc3c4acba9c9bfeea9803e57
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed,  1 Jan 2020 20:54:17 -0500

translate-c: don't export inline functions

Diffstat:
Msrc-self-hosted/clang.zig | 2++
Msrc-self-hosted/translate_c.zig | 2+-
Msrc/zig_clang.cpp | 10++++++++++
Msrc/zig_clang.h | 2++
Mtest/translate_c.zig | 10++++++++++
5 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src-self-hosted/clang.zig b/src-self-hosted/clang.zig @@ -832,6 +832,8 @@ pub extern fn ZigClangFunctionDecl_hasBody(self: *const ZigClangFunctionDecl) bo pub extern fn ZigClangFunctionDecl_getStorageClass(self: *const ZigClangFunctionDecl) ZigClangStorageClass; pub extern fn ZigClangFunctionDecl_getParamDecl(self: *const ZigClangFunctionDecl, i: c_uint) *const struct_ZigClangParmVarDecl; pub extern fn ZigClangFunctionDecl_getBody(self: *const ZigClangFunctionDecl) *const struct_ZigClangStmt; +pub extern fn ZigClangFunctionDecl_doesDeclarationForceExternallyVisibleDefinition(self: *const ZigClangFunctionDecl) bool; +pub extern fn ZigClangFunctionDecl_isInlineSpecified(self: *const ZigClangFunctionDecl) bool; pub extern fn ZigClangBuiltinType_getKind(self: *const struct_ZigClangBuiltinType) ZigClangBuiltinTypeKind; diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig @@ -423,7 +423,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void { .has_body = has_body, .storage_class = storage_class, .is_export = switch (storage_class) { - .None => has_body, + .None => has_body and !ZigClangFunctionDecl_isInlineSpecified(fn_decl), .Extern, .Static => false, .PrivateExtern => return failDecl(c, fn_decl_loc, fn_name, "unsupported storage class: private extern", .{}), .Auto => unreachable, // Not legal on functions diff --git a/src/zig_clang.cpp b/src/zig_clang.cpp @@ -1686,6 +1686,16 @@ const struct ZigClangStmt *ZigClangFunctionDecl_getBody(const struct ZigClangFun return reinterpret_cast<const ZigClangStmt *>(stmt); } +bool ZigClangFunctionDecl_doesDeclarationForceExternallyVisibleDefinition(const struct ZigClangFunctionDecl *self) { + auto casted = reinterpret_cast<const clang::FunctionDecl *>(self); + return casted->doesDeclarationForceExternallyVisibleDefinition(); +} + +bool ZigClangFunctionDecl_isInlineSpecified(const struct ZigClangFunctionDecl *self) { + auto casted = reinterpret_cast<const clang::FunctionDecl *>(self); + return casted->isInlineSpecified(); +} + const ZigClangTypedefNameDecl *ZigClangTypedefType_getDecl(const ZigClangTypedefType *self) { auto casted = reinterpret_cast<const clang::TypedefType *>(self); const clang::TypedefNameDecl *name_decl = casted->getDecl(); diff --git a/src/zig_clang.h b/src/zig_clang.h @@ -873,6 +873,8 @@ ZIG_EXTERN_C bool ZigClangFunctionDecl_hasBody(const struct ZigClangFunctionDecl ZIG_EXTERN_C enum ZigClangStorageClass ZigClangFunctionDecl_getStorageClass(const struct ZigClangFunctionDecl *); ZIG_EXTERN_C const struct ZigClangParmVarDecl *ZigClangFunctionDecl_getParamDecl(const struct ZigClangFunctionDecl *, unsigned i); ZIG_EXTERN_C const struct ZigClangStmt *ZigClangFunctionDecl_getBody(const struct ZigClangFunctionDecl *); +ZIG_EXTERN_C bool ZigClangFunctionDecl_doesDeclarationForceExternallyVisibleDefinition(const struct ZigClangFunctionDecl *); +ZIG_EXTERN_C bool ZigClangFunctionDecl_isInlineSpecified(const struct ZigClangFunctionDecl *); ZIG_EXTERN_C bool ZigClangRecordDecl_isUnion(const struct ZigClangRecordDecl *record_decl); ZIG_EXTERN_C bool ZigClangRecordDecl_isStruct(const struct ZigClangRecordDecl *record_decl); diff --git a/test/translate_c.zig b/test/translate_c.zig @@ -2302,4 +2302,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , \\pub const bar = 4; }); + + cases.add("don't export inline functions", + \\inline void a(void) {} + \\static void b(void) {} + \\void c(void) {} + , &[_][]const u8{ + \\pub fn a() void {} + \\pub fn b() void {} + \\pub export fn c() void {} + }); }