Skip to content

Commit c1f4160

Browse files
committed
Mark DECL_PUBLIC for main fn or functions with visibility.
This change will need more thought later when it comes to traits and generics etc. Fixes #136
1 parent 9a3ad29 commit c1f4160

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

gcc/rust/backend/rust-compile-item.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,19 @@ class CompileItem : public HIRCompileBase
138138
// convert to the actual function type
139139
auto compiled_fn_type = TyTyCompile::compile (ctx->get_backend (), fnType);
140140

141+
unsigned int flags = 0;
142+
bool is_main_fn = function.function_name.compare ("main") == 0;
143+
144+
// if its the main fn or pub visibility mark its as DECL_PUBLIC
145+
// please see https://github.com/Rust-GCC/gccrs/pull/137
146+
if (is_main_fn || function.has_visibility ())
147+
flags |= Backend::function_is_visible;
148+
149+
// FIXME need name mangling
150+
std::string asm_name = function.function_name;
141151
Bfunction *fndecl
142152
= ctx->get_backend ()->function (compiled_fn_type, function.function_name,
143-
"" /* asm_name */, 0 /* flags */,
144-
function.get_locus ());
153+
asm_name, flags, function.get_locus ());
145154
ctx->insert_function_decl (function.get_mappings ().get_hirid (), fndecl);
146155

147156
// setup the params

0 commit comments

Comments
 (0)