@@ -43,11 +43,7 @@ struct Nest {
4343 second : Pair ,
4444}
4545
46- // #[repr(C)]
47- // struct A {
48- // data: [u8; 2],
49- // }
50-
46+ // test1: array of [16 x i8]
5147// CHECK-LABEL: test1{{:|\[}}
5248#[ no_mangle]
5349pub fn test1 ( a : * const u8 ) {
@@ -64,9 +60,7 @@ pub fn test1(a: *const u8) {
6460 // missing-NOT: __stack_chk_fail
6561}
6662
67- // Note: test2
68- // struct -> flat aggregate -> array
69-
63+ // test3: array [4 x i8]
7064// CHECK-LABEL: test3{{:|\[}}
7165#[ no_mangle]
7266pub fn test3 ( a : * const u8 ) {
@@ -83,9 +77,7 @@ pub fn test3(a: *const u8) {
8377 // missing-NOT: __stack_chk_fail
8478}
8579
86- // Note: test4
87- // struct -> flat aggregate -> array
88-
80+ // test5: no arrays / no nested arrays
8981// CHECK-LABEL: test5{{:|\[}}
9082#[ no_mangle]
9183pub fn test5 ( a : * const u8 ) {
@@ -99,6 +91,7 @@ pub fn test5(a: *const u8) {
9991 // missing-NOT: __stack_chk_fail
10092}
10193
94+ // test6: Address-of local taken (j = &a)
10295// CHECK-LABEL: test6{{:|\[}}
10396#[ no_mangle]
10497pub unsafe extern "C" fn test6 ( ) {
@@ -118,6 +111,7 @@ pub unsafe extern "C" fn test6() {
118111 // missing-NOT: __stack_chk_fail
119112}
120113
114+ // test7: PtrToInt Cast
121115// CHECK-LABEL: test7{{:|\[}}
122116#[ no_mangle]
123117pub fn test7 ( a : i32 ) {
@@ -133,6 +127,7 @@ pub fn test7(a: i32) {
133127 // missing-NOT: __stack_chk_fail
134128}
135129
130+ // test8: Passing addr-of to function call
136131// CHECK-LABEL: test8{{:|\[}}
137132#[ no_mangle]
138133pub fn test8 ( mut b : i32 ) {
@@ -146,6 +141,7 @@ pub fn test8(mut b: i32) {
146141 // missing-NOT: __stack_chk_fail
147142}
148143
144+ // test9: Addr-of in select instruction
149145// CHECK-LABEL: test9{{:|\[}}
150146#[ no_mangle]
151147pub fn test9 ( ) {
@@ -166,6 +162,7 @@ pub fn test9() {
166162 // missing-NOT: __stack_chk_fail
167163}
168164
165+ // test10: Addr-of in phi instruction
169166// CHECK-LABEL: test10{{:|\[}}
170167#[ no_mangle]
171168pub fn test10 ( ) {
@@ -198,6 +195,7 @@ pub fn test10() {
198195 // missing-NOT: __stack_chk_fail
199196}
200197
198+ // test11: Addr-of struct element(GEP followed by store)
201199// CHECK-LABEL: test11{{:|\[}}
202200#[ no_mangle]
203201pub fn test11 ( ) {
@@ -218,6 +216,7 @@ pub fn test11() {
218216 // missing-NOT: __stack_chk_fail
219217}
220218
219+ // test12: Addr-of struct element, GEP followed by ptrtoint
221220// CHECK-LABEL: test12{{:|\[}}
222221#[ no_mangle]
223222pub fn test12 ( ) {
@@ -237,6 +236,7 @@ pub fn test12() {
237236 // missing-NOT: __stack_chk_fail
238237}
239238
239+ // test13: Addr-of struct element, GEP followed by callinst
240240// CHECK-LABEL: test13{{:|\[}}
241241#[ no_mangle]
242242pub fn test13 ( ) {
@@ -254,6 +254,7 @@ pub fn test13() {
254254 // missing-NOT: __stack_chk_fail
255255}
256256
257+ // test14: Addr-of a local, optimized into a GEP (e.g., &a - 12)
257258// CHECK-LABEL: test14{{:|\[}}
258259#[ no_mangle]
259260pub fn test14 ( ) {
@@ -271,6 +272,8 @@ pub fn test14() {
271272 // missing-NOT: __stack_chk_fail
272273}
273274
275+ // test15: Addr-of a local cast to a ptr of a different type
276+ // (e.g., int a; ... ; ptr b = &a;)
274277// CHECK-LABEL: test15{{:|\[}}
275278#[ no_mangle]
276279pub fn test15 ( ) {
@@ -291,6 +294,8 @@ pub fn test15() {
291294 // missing-NOT: __stack_chk_fail
292295}
293296
297+ // test16: Addr-of a local cast to a ptr of a different type (optimized)
298+ // (e.g., int a; ... ; ptr b = &a;)
294299// CHECK-LABEL: test16{{:|\[}}
295300#[ no_mangle]
296301pub fn test16 ( ) {
@@ -305,10 +310,7 @@ pub fn test16() {
305310 // missing-NOT: __stack_chk_fail
306311}
307312
308- // Note: test17
309- // Addr-of a vector nested in a struct:
310- // There is no such type in rustc corresbonding to '%struct.vec = type { <4 x i32> }' in LLVM.
311-
313+ // test18: Addr-of a variable passed into an invoke instruction
312314// CHECK-LABEL: test18{{:|\[}}
313315#[ no_mangle]
314316pub unsafe extern "C" fn test18 ( ) -> i32 {
@@ -324,6 +326,8 @@ pub unsafe extern "C" fn test18() -> i32 {
324326 // missing-NOT: __stack_chk_fail
325327}
326328
329+ // test19: Addr-of a struct element passed into an invoke instruction
330+ // (GEP followed by an invoke)
327331// CHECK-LABEL: test19{{:|\[}}
328332#[ no_mangle]
329333pub unsafe extern "C" fn test19 ( ) -> i32 {
@@ -339,6 +343,7 @@ pub unsafe extern "C" fn test19() -> i32 {
339343 // missing-NOT: __stack_chk_fail
340344}
341345
346+ // test20: Addr-of a pointer
342347// CHECK-LABEL: test20{{:|\[}}
343348#[ no_mangle]
344349pub unsafe extern "C" fn test20 ( ) {
@@ -358,6 +363,7 @@ pub unsafe extern "C" fn test20() {
358363 // missing-NOT: __stack_chk_fail
359364}
360365
366+ // test21: Addr-of a casted pointer
361367// CHECK-LABEL: test21{{:|\[}}
362368#[ no_mangle]
363369pub unsafe extern "C" fn test21 ( ) {
@@ -377,16 +383,7 @@ pub unsafe extern "C" fn test21() {
377383 // missing-NOT: __stack_chk_fail
378384}
379385
380- // Note: test22
381- // [2 x i8] in struct will be automatically optimized to i16
382- // and will not trigger the sspstrong
383-
384- // Note: test23
385- // [2 x i8] nested in several layers of structs and unions: same as test22
386-
387- // Note: test24
388- // Variable sized alloca(VLA): see https://github.com/rust-lang/rfcs/pull/1909
389-
386+ // test25: array of [4 x i32]
390387// CHECK-LABEL: test25{{:|\[}}
391388#[ no_mangle]
392389pub unsafe extern "C" fn test25 ( ) -> i32 {
@@ -402,6 +399,9 @@ pub unsafe extern "C" fn test25() -> i32 {
402399 // missing-NOT: __stack_chk_fail
403400}
404401
402+ // test26: Nested structure, no arrays, no address-of expressions
403+ // Verify that the resulting gep-of-gep does not incorrectly trigger
404+ // a stack protector
405405// CHECK-LABEL: test26{{:|\[}}
406406#[ no_mangle]
407407pub unsafe extern "C" fn test26 ( ) {
@@ -416,6 +416,11 @@ pub unsafe extern "C" fn test26() {
416416 // strong-NOT: __stack_chk_fail
417417}
418418
419+ // test27: Address-of a structure taken in a function with a loop where
420+ // the alloca is an incoming value to a PHI node and a use of that PHI
421+ // node is also an incoming value
422+ // Verify that the address-of analysis does not get stuck in infinite
423+ // recursion when chasing the alloca through the PHI nodes
419424// CHECK-LABEL: test27{{:|\[}}
420425#[ no_mangle]
421426pub unsafe extern "C" fn test27 ( ) -> i32 {
0 commit comments