/src/test/incremental/hashes/inline_asm.rs

https://gitlab.com/rust-lang/rust · Rust · 222 lines · 176 code · 25 blank · 21 comment · 0 complexity · 39a778a780dab56560bc1471a0ecf60b MD5 · raw file

  1. // This test case tests the incremental compilation hash (ICH) implementation
  2. // for inline asm.
  3. // The general pattern followed here is: Change one thing between rev1 and rev2
  4. // and make sure that the hash has changed, then change nothing between rev2 and
  5. // rev3 and make sure that the hash has not changed.
  6. // build-pass (FIXME(62277): could be check-pass?)
  7. // revisions: cfail1 cfail2 cfail3 cfail4 cfail5 cfail6
  8. // compile-flags: -Z query-dep-graph -O
  9. // needs-asm-support
  10. // [cfail1]compile-flags: -Zincremental-ignore-spans
  11. // [cfail2]compile-flags: -Zincremental-ignore-spans
  12. // [cfail3]compile-flags: -Zincremental-ignore-spans
  13. // [cfail4]compile-flags: -Zincremental-relative-spans
  14. // [cfail5]compile-flags: -Zincremental-relative-spans
  15. // [cfail6]compile-flags: -Zincremental-relative-spans
  16. #![allow(warnings)]
  17. #![feature(rustc_attrs)]
  18. #![crate_type="rlib"]
  19. use std::arch::asm;
  20. // Change template
  21. #[cfg(any(cfail1,cfail4))]
  22. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  23. pub fn change_template(_a: i32) -> i32 {
  24. let c: i32;
  25. unsafe {
  26. asm!("mov {0}, 1",
  27. out(reg) c
  28. );
  29. }
  30. c
  31. }
  32. #[cfg(not(any(cfail1,cfail4)))]
  33. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")]
  34. #[rustc_clean(cfg="cfail3")]
  35. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
  36. #[rustc_clean(cfg="cfail6")]
  37. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  38. pub fn change_template(_a: i32) -> i32 {
  39. let c: i32;
  40. unsafe {
  41. asm!("mov {0}, 2",
  42. out(reg) c
  43. );
  44. }
  45. c
  46. }
  47. // Change output
  48. #[cfg(any(cfail1,cfail4))]
  49. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  50. pub fn change_output(a: i32) -> i32 {
  51. let mut _out1: i32 = 0;
  52. let mut _out2: i32 = 0;
  53. unsafe {
  54. asm!("mov {0}, {1}",
  55. out(reg) _out1,
  56. in(reg) a
  57. );
  58. }
  59. _out1
  60. }
  61. #[cfg(not(any(cfail1,cfail4)))]
  62. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")]
  63. #[rustc_clean(cfg="cfail3")]
  64. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
  65. #[rustc_clean(cfg="cfail6")]
  66. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  67. pub fn change_output(a: i32) -> i32 {
  68. let mut _out1: i32 = 0;
  69. let mut _out2: i32 = 0;
  70. unsafe {
  71. asm!("mov {0}, {1}",
  72. out(reg) _out2,
  73. in(reg) a
  74. );
  75. }
  76. _out1
  77. }
  78. // Change input
  79. #[cfg(any(cfail1,cfail4))]
  80. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  81. pub fn change_input(_a: i32, _b: i32) -> i32 {
  82. let _out;
  83. unsafe {
  84. asm!("mov {0}, {1}",
  85. out(reg) _out,
  86. in(reg) _a
  87. );
  88. }
  89. _out
  90. }
  91. #[cfg(not(any(cfail1,cfail4)))]
  92. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")]
  93. #[rustc_clean(cfg="cfail3")]
  94. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
  95. #[rustc_clean(cfg="cfail6")]
  96. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  97. pub fn change_input(_a: i32, _b: i32) -> i32 {
  98. let _out;
  99. unsafe {
  100. asm!("mov {0}, {1}",
  101. out(reg) _out,
  102. in(reg) _b
  103. );
  104. }
  105. _out
  106. }
  107. // Change input constraint
  108. #[cfg(any(cfail1,cfail4))]
  109. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  110. pub fn change_input_constraint(_a: i32, _b: i32) -> i32 {
  111. let _out;
  112. unsafe {
  113. asm!("mov {0}, {1}",
  114. out(reg) _out,
  115. in(reg) _a,
  116. in("eax") _b);
  117. }
  118. _out
  119. }
  120. #[cfg(not(any(cfail1,cfail4)))]
  121. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")]
  122. #[rustc_clean(cfg="cfail3")]
  123. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
  124. #[rustc_clean(cfg="cfail6")]
  125. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  126. pub fn change_input_constraint(_a: i32, _b: i32) -> i32 {
  127. let _out;
  128. unsafe {
  129. asm!("mov {0}, {1}",
  130. out(reg) _out,
  131. in(reg) _a,
  132. in("ecx") _b);
  133. }
  134. _out
  135. }
  136. // Change clobber
  137. #[cfg(any(cfail1,cfail4))]
  138. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  139. pub fn change_clobber(_a: i32) -> i32 {
  140. let _out;
  141. unsafe {
  142. asm!("mov {0}, {1}",
  143. out(reg) _out,
  144. in(reg) _a,
  145. lateout("ecx") _
  146. );
  147. }
  148. _out
  149. }
  150. #[cfg(not(any(cfail1,cfail4)))]
  151. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")]
  152. #[rustc_clean(cfg="cfail3")]
  153. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
  154. #[rustc_clean(cfg="cfail6")]
  155. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  156. pub fn change_clobber(_a: i32) -> i32 {
  157. let _out;
  158. unsafe {
  159. asm!("mov {0}, {1}",
  160. out(reg) _out,
  161. in(reg) _a,
  162. lateout("edx") _
  163. );
  164. }
  165. _out
  166. }
  167. // Change options
  168. #[cfg(any(cfail1,cfail4))]
  169. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  170. pub fn change_options(_a: i32) -> i32 {
  171. let _out;
  172. unsafe {
  173. asm!("mov {0}, {1}",
  174. out(reg) _out,
  175. in(reg) _a,
  176. options(readonly),
  177. );
  178. }
  179. _out
  180. }
  181. #[cfg(not(any(cfail1,cfail4)))]
  182. #[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")]
  183. #[rustc_clean(cfg="cfail3")]
  184. #[rustc_clean(cfg="cfail5", except="hir_owner_nodes, optimized_mir")]
  185. #[rustc_clean(cfg="cfail6")]
  186. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  187. pub fn change_options(_a: i32) -> i32 {
  188. let _out;
  189. unsafe {
  190. asm!("mov {0}, {1}",
  191. out(reg) _out,
  192. in(reg) _a,
  193. options(nomem ),
  194. );
  195. }
  196. _out
  197. }