Skip to content

Commit adef852

Browse files
committed
c_gen: only generate 'static inline' if it really is an inline fn
1 parent fdb6610 commit adef852

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

ast/function_decl.c2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ public fn CompoundStmt* FunctionDecl.getBody(const FunctionDecl* d) {
205205
return d.body;
206206
}
207207

208+
209+
public fn bool FunctionDecl.isInline(const FunctionDecl* d) {
210+
if (!d.getBody()) return false;
211+
if (!d.hasAttrInline()) return false;
212+
if (!d.parent.isPublic()) return false;
213+
return true;
214+
}
215+
208216
public fn bool FunctionDecl.isType(const FunctionDecl* d) {
209217
return d.parent.functionDeclBits.is_type;
210218
}

generator/c_generator.c2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ fn void Generator.gen_func_proto(Generator* gen, FunctionDecl* fd, string_buffer
840840
// also:
841841
// - generate lib.h for library
842842
// - generate module.h in cgen
843-
if (gen.cur_external && fd.getBody()) out.add("static inline ");
843+
if (gen.cur_external && fd.isInline()) out.add("static inline ");
844844
if (!gen.cur_external && !d.isExported() && !(gen.fast_build && d.isPublic())) out.add("static ");
845845
gen.emitTypePre(out, fd.getRType());
846846
out.space();

0 commit comments

Comments
 (0)