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

https://gitlab.com/jianglu/rust · Rust · 238 lines · 186 code · 29 blank · 23 comment · 0 complexity · 4cae79cfc33923c9e5c56e32494842ac MD5 · raw file

  1. // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
  2. // file at the top-level directory of this distribution and at
  3. // http://rust-lang.org/COPYRIGHT.
  4. //
  5. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8. // option. This file may not be copied, modified, or distributed
  9. // except according to those terms.
  10. // This test case tests the incremental compilation hash (ICH) implementation
  11. // for inline asm.
  12. // The general pattern followed here is: Change one thing between rev1 and rev2
  13. // and make sure that the hash has changed, then change nothing between rev2 and
  14. // rev3 and make sure that the hash has not changed.
  15. // compile-pass
  16. // revisions: cfail1 cfail2 cfail3
  17. // compile-flags: -Z query-dep-graph -Zincremental-ignore-spans
  18. #![allow(warnings)]
  19. #![feature(rustc_attrs)]
  20. #![feature(asm)]
  21. #![crate_type="rlib"]
  22. // Change template -------------------------------------------------------------
  23. #[cfg(cfail1)]
  24. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  25. pub fn change_template(a: i32) -> i32 {
  26. let c: i32;
  27. unsafe {
  28. asm!("add 1, $0"
  29. : "=r"(c)
  30. : "0"(a)
  31. :
  32. :
  33. );
  34. }
  35. c
  36. }
  37. #[cfg(not(cfail1))]
  38. #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized")]
  39. #[rustc_clean(cfg="cfail3")]
  40. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  41. pub fn change_template(a: i32) -> i32 {
  42. let c: i32;
  43. unsafe {
  44. asm!("add 2, $0"
  45. : "=r"(c)
  46. : "0"(a)
  47. :
  48. :
  49. );
  50. }
  51. c
  52. }
  53. // Change output -------------------------------------------------------------
  54. #[cfg(cfail1)]
  55. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  56. pub fn change_output(a: i32) -> i32 {
  57. let mut _out1: i32 = 0;
  58. let mut _out2: i32 = 0;
  59. unsafe {
  60. asm!("add 1, $0"
  61. : "=r"(_out1)
  62. : "0"(a)
  63. :
  64. :
  65. );
  66. }
  67. _out1
  68. }
  69. #[cfg(not(cfail1))]
  70. #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized")]
  71. #[rustc_clean(cfg="cfail3")]
  72. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  73. pub fn change_output(a: i32) -> i32 {
  74. let mut _out1: i32 = 0;
  75. let mut _out2: i32 = 0;
  76. unsafe {
  77. asm!("add 1, $0"
  78. : "=r"(_out2)
  79. : "0"(a)
  80. :
  81. :
  82. );
  83. }
  84. _out1
  85. }
  86. // Change input -------------------------------------------------------------
  87. #[cfg(cfail1)]
  88. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  89. pub fn change_input(_a: i32, _b: i32) -> i32 {
  90. let _out;
  91. unsafe {
  92. asm!("add 1, $0"
  93. : "=r"(_out)
  94. : "0"(_a)
  95. :
  96. :
  97. );
  98. }
  99. _out
  100. }
  101. #[cfg(not(cfail1))]
  102. #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized")]
  103. #[rustc_clean(cfg="cfail3")]
  104. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  105. pub fn change_input(_a: i32, _b: i32) -> i32 {
  106. let _out;
  107. unsafe {
  108. asm!("add 1, $0"
  109. : "=r"(_out)
  110. : "0"(_b)
  111. :
  112. :
  113. );
  114. }
  115. _out
  116. }
  117. // Change input constraint -----------------------------------------------------
  118. #[cfg(cfail1)]
  119. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  120. pub fn change_input_constraint(_a: i32, _b: i32) -> i32 {
  121. let _out;
  122. unsafe {
  123. asm!("add 1, $0"
  124. : "=r"(_out)
  125. : "0"(_a), "r"(_b)
  126. :
  127. :
  128. );
  129. }
  130. _out
  131. }
  132. #[cfg(not(cfail1))]
  133. #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized")]
  134. #[rustc_clean(cfg="cfail3")]
  135. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  136. pub fn change_input_constraint(_a: i32, _b: i32) -> i32 {
  137. let _out;
  138. unsafe {
  139. asm!("add 1, $0"
  140. : "=r"(_out)
  141. : "r"(_a), "0"(_b)
  142. :
  143. :
  144. );
  145. }
  146. _out
  147. }
  148. // Change clobber --------------------------------------------------------------
  149. #[cfg(cfail1)]
  150. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  151. pub fn change_clobber(_a: i32) -> i32 {
  152. let _out;
  153. unsafe {
  154. asm!("add 1, $0"
  155. : "=r"(_out)
  156. : "0"(_a)
  157. :
  158. :
  159. );
  160. }
  161. _out
  162. }
  163. #[cfg(not(cfail1))]
  164. #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized")]
  165. #[rustc_clean(cfg="cfail3")]
  166. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  167. pub fn change_clobber(_a: i32) -> i32 {
  168. let _out;
  169. unsafe {
  170. asm!("add 1, $0"
  171. : "=r"(_out)
  172. : "0"(_a)
  173. : "eax"
  174. :
  175. );
  176. }
  177. _out
  178. }
  179. // Change options --------------------------------------------------------------
  180. #[cfg(cfail1)]
  181. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  182. pub fn change_options(_a: i32) -> i32 {
  183. let _out;
  184. unsafe {
  185. asm!("add 1, $0"
  186. : "=r"(_out)
  187. : "0"(_a)
  188. :
  189. :
  190. );
  191. }
  192. _out
  193. }
  194. #[cfg(not(cfail1))]
  195. #[rustc_clean(cfg="cfail2", except="HirBody, MirValidated, MirOptimized")]
  196. #[rustc_clean(cfg="cfail3")]
  197. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
  198. pub fn change_options(_a: i32) -> i32 {
  199. let _out;
  200. unsafe {
  201. asm!("add 1, $0"
  202. : "=r"(_out)
  203. : "0"(_a)
  204. :
  205. : "volatile"
  206. );
  207. }
  208. _out
  209. }