diff options
author | John Hodge <tpg@mutabah.net> | 2017-09-23 14:25:09 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2017-09-23 14:25:09 +0800 |
commit | cfb45e3564ebfedc4b40adcf53286f9737f8d25e (patch) | |
tree | 29f2e51ec857cebd28172ee82f2d9973559f8505 /src | |
parent | 285116d4de4a866725f3ae9c3f282f07e5fac72e (diff) | |
download | mrust-cfb45e3564ebfedc4b40adcf53286f9737f8d25e.tar.gz |
Codegen C - Use static when a destructor would be locally defined, extern otherwise
Diffstat (limited to 'src')
-rw-r--r-- | src/trans/codegen_c.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 5e600c90..1ec2d2cd 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -520,7 +520,10 @@ namespace { is_windows = true; // TODO: Look up these paths in the registry and use CreateProcess instead of system args.push_back(cache_str( detect_msvc().path_vcvarsall )); - //args.push_back("amd64"); // NOTE: Doesn't support inline assembly + if( Target_GetCurSpec().m_arch.m_pointer_bits == 64 ) + { + args.push_back("amd64"); // NOTE: Doesn't support inline assembly, only works with overrides + } args.push_back("&"); args.push_back("cl.exe"); args.push_back("/nologo"); @@ -869,8 +872,16 @@ namespace { ::std::vector< ::std::pair<::HIR::Pattern,::HIR::TypeRef> > args; if( item.m_markings.has_drop_impl ) { + // If the type is defined outside the current crate, define as static (to avoid conflicts when we define it) if( p.m_path.m_crate_name != m_crate.m_crate_name ) - m_of << "static "; + { + if( item.m_params.m_types.size() > 0 ) { + m_of << "static "; + } + else { + m_of << "extern "; + } + } m_of << "tUNIT " << Trans_Mangle( ::HIR::Path(struct_ty.clone(), m_resolve.m_lang_Drop, "drop") ) << "("; emit_ctype(struct_ty_ptr, FMT_CB(ss, ss << "rv";)); m_of << ");\n"; } else if( m_resolve.is_type_owned_box(struct_ty) ) @@ -1780,7 +1791,7 @@ namespace { } } - m_of << "// extern \"" << item.m_abi << "\" " << p << "\n"; + m_of << "// EXTERN extern \"" << item.m_abi << "\" " << p << "\n"; m_of << "extern "; emit_function_header(p, item, params); if( item.m_linkage.name != "" && m_compiler == Compiler::Gcc) @@ -1797,6 +1808,7 @@ namespace { m_mir_res = &top_mir_res; TRACE_FUNCTION_F(p); + m_of << "// PROTO extern \"" << item.m_abi << "\" " << p << "\n"; if( item.m_linkage.name != "" ) { m_of << "#define " << Trans_Mangle(p) << " " << item.m_linkage.name << "\n"; |