@@ -111,7 +111,7 @@ pub fn spin_loop() {
111
111
#[ inline]
112
112
#[ unstable( feature = "test" , issue = "50297" ) ]
113
113
#[ allow( unreachable_code) ] // this makes #[cfg] a bit easier below.
114
- pub fn black_box < T > ( dummy : T ) -> T {
114
+ pub fn black_box < T > ( mut dummy : T ) -> T {
115
115
// We need to "use" the argument in some way LLVM can't introspect, and on
116
116
// targets that support it we can typically leverage inline assembly to do
117
117
// this. LLVM's interpretation of inline assembly is that it's, well, a black
@@ -121,7 +121,31 @@ pub fn black_box<T>(dummy: T) -> T {
121
121
#[ cfg( not( miri) ) ] // This is just a hint, so it is fine to skip in Miri.
122
122
// SAFETY: the inline assembly is a no-op.
123
123
unsafe {
124
- llvm_asm ! ( "" : : "r" ( & dummy) ) ;
124
+ #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
125
+ {
126
+ asm ! (
127
+ "/* {0} */" ,
128
+ in( reg) & mut dummy,
129
+ // FIXME: We are using ATT syntax to support LLVM 8 and LLVM 9.
130
+ options( att_syntax, nostack, preserves_flags) ,
131
+ ) ;
132
+ }
133
+ #[ cfg( target_arch = "nvptx64" ) ]
134
+ {
135
+ asm ! (
136
+ "/* {0} */" ,
137
+ in( reg64) & mut dummy,
138
+ options( nostack, preserves_flags) ,
139
+ ) ;
140
+ }
141
+ #[ cfg( not( any( target_arch = "x86" , target_arch = "x86_64" , target_arch = "nvptx64" ) ) ) ]
142
+ {
143
+ asm ! (
144
+ "/* {0} */" ,
145
+ in( reg) & mut dummy,
146
+ options( nostack, preserves_flags) ,
147
+ ) ;
148
+ }
125
149
}
126
150
127
151
dummy
0 commit comments