File tree 2 files changed +21
-0
lines changed
compiler/rustc_passes/src
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,9 @@ impl<'tcx> Visitor<'tcx> for CheckCustomAbi<'tcx> {
88
88
}
89
89
}
90
90
91
+ // Because `extern "custom"` functions don't accept any parameter, and functions are
92
+ // only methods when some variation on `self` is their first argument, methods cannot
93
+ // use `extern "custom"` in a valid program.
91
94
ExprKind :: MethodCall ( _, receiver, _, span) => {
92
95
let opt_def_id = self
93
96
. tcx
@@ -99,6 +102,7 @@ impl<'tcx> Visitor<'tcx> for CheckCustomAbi<'tcx> {
99
102
( span, sig. abi )
100
103
} )
101
104
}
105
+
102
106
_ => None ,
103
107
} ;
104
108
Original file line number Diff line number Diff line change @@ -47,6 +47,15 @@ trait BitwiseNot {
47
47
48
48
impl BitwiseNot for Thing { }
49
49
50
+ #[ unsafe( naked) ]
51
+ unsafe extern "C" fn const_generic < const N : u64 > ( ) {
52
+ naked_asm ! (
53
+ "mov rax, {}" ,
54
+ "ret" ,
55
+ const N ,
56
+ ) ;
57
+ }
58
+
50
59
pub fn main ( ) {
51
60
let mut x: u64 = 21 ;
52
61
unsafe { asm ! ( "call {}" , sym double, inout( "rax" ) x) } ;
@@ -71,4 +80,12 @@ pub fn main() {
71
80
}
72
81
73
82
assert_eq ! ( caller( double, 2 ) , 4 ) ;
83
+
84
+ let x: u64 ;
85
+ unsafe { asm ! ( "call {}" , sym const_generic:: <42 >, out( "rax" ) x) } ;
86
+ assert_eq ! ( x, 42 ) ;
87
+
88
+ let x: u64 ;
89
+ unsafe { asm ! ( "call {}" , sym const_generic:: <84 >, out( "rax" ) x) } ;
90
+ assert_eq ! ( x, 84 ) ;
74
91
}
You can’t perform that action at this time.
0 commit comments