@@ -6,6 +6,7 @@ use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
66use cranelift_module:: ModuleError ;
77use rustc_ast:: InlineAsmOptions ;
88use rustc_index:: IndexVec ;
9+ use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
910use rustc_middle:: ty:: adjustment:: PointerCoercion ;
1011use rustc_middle:: ty:: layout:: FnAbiOf ;
1112use rustc_middle:: ty:: print:: with_no_trimmed_paths;
@@ -14,6 +15,7 @@ use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphizat
1415
1516use crate :: constant:: ConstantCx ;
1617use crate :: debuginfo:: { FunctionDebugContext , TypeDebugContext } ;
18+ use crate :: inline_asm:: codegen_naked_asm;
1719use crate :: prelude:: * ;
1820use crate :: pretty_clif:: CommentWriter ;
1921
@@ -32,7 +34,7 @@ pub(crate) fn codegen_fn<'tcx>(
3234 cached_func : Function ,
3335 module : & mut dyn Module ,
3436 instance : Instance < ' tcx > ,
35- ) -> CodegenedFunction {
37+ ) -> Option < CodegenedFunction > {
3638 debug_assert ! ( !instance. args. has_infer( ) ) ;
3739
3840 let symbol_name = tcx. symbol_name ( instance) . name . to_string ( ) ;
@@ -48,6 +50,37 @@ pub(crate) fn codegen_fn<'tcx>(
4850 String :: from_utf8_lossy ( & buf) . into_owned ( )
4951 } ) ;
5052
53+ if tcx. codegen_fn_attrs ( instance. def_id ( ) ) . flags . contains ( CodegenFnAttrFlags :: NAKED ) {
54+ assert_eq ! ( mir. basic_blocks. len( ) , 1 ) ;
55+ assert ! ( mir. basic_blocks[ START_BLOCK ] . statements. is_empty( ) ) ;
56+
57+ match & mir. basic_blocks [ START_BLOCK ] . terminator ( ) . kind {
58+ TerminatorKind :: InlineAsm {
59+ template,
60+ operands,
61+ options,
62+ line_spans : _,
63+ targets : _,
64+ unwind : _,
65+ } => {
66+ codegen_naked_asm (
67+ tcx,
68+ cx,
69+ module,
70+ instance,
71+ mir. basic_blocks [ START_BLOCK ] . terminator ( ) . source_info . span ,
72+ & symbol_name,
73+ template,
74+ operands,
75+ * options,
76+ ) ;
77+ }
78+ _ => unreachable ! ( ) ,
79+ }
80+
81+ return None ;
82+ }
83+
5184 // Declare function
5285 let sig = get_function_sig ( tcx, module. target_config ( ) . default_call_conv , instance) ;
5386 let func_id = module. declare_function ( & symbol_name, Linkage :: Local , & sig) . unwrap ( ) ;
@@ -128,7 +161,7 @@ pub(crate) fn codegen_fn<'tcx>(
128161 // Verify function
129162 verify_func ( tcx, & clif_comments, & func) ;
130163
131- CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx }
164+ Some ( CodegenedFunction { symbol_name, func_id, func, clif_comments, func_debug_cx } )
132165}
133166
134167pub ( crate ) fn compile_fn (
0 commit comments