@@ -111,7 +111,7 @@ pub fn spin_loop() {
111111#[ inline]
112112#[ unstable( feature = "test" , issue = "50297" ) ]
113113#[ 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 {
115115 // We need to "use" the argument in some way LLVM can't introspect, and on
116116 // targets that support it we can typically leverage inline assembly to do
117117 // 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 {
121121 #[ cfg( not( miri) ) ] // This is just a hint, so it is fine to skip in Miri.
122122 // SAFETY: the inline assembly is a no-op.
123123 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+ }
125149 }
126150
127151 dummy
0 commit comments