@@ -42,11 +42,7 @@ struct Nest {
4242 second : Pair ,
4343}
4444
45- // #[repr(C)]
46- // struct A {
47- // data: [u8; 2],
48- // }
49-
45+ // test1: array of [16 x i8]
5046// CHECK-LABEL: test1{{:|\[}}
5147#[ no_mangle]
5248pub fn test1 ( a : * const u8 ) {
@@ -63,9 +59,7 @@ pub fn test1(a: *const u8) {
6359 // missing-NOT: __security_check_cookie
6460}
6561
66- // Note: test2
67- // struct -> flat aggregate -> array
68-
62+ // test3: array [4 x i8]
6963// CHECK-LABEL: test3{{:|\[}}
7064#[ no_mangle]
7165pub fn test3 ( a : * const u8 ) {
@@ -82,9 +76,7 @@ pub fn test3(a: *const u8) {
8276 // missing-NOT: __security_check_cookie
8377}
8478
85- // Note: test4
86- // struct -> flat aggregate -> array
87-
79+ // test5: no arrays / no nested arrays
8880// CHECK-LABEL: test5{{:|\[}}
8981#[ no_mangle]
9082pub fn test5 ( a : * const u8 ) {
@@ -98,6 +90,7 @@ pub fn test5(a: *const u8) {
9890 // missing-NOT: __security_check_cookie
9991}
10092
93+ // test6: Address-of local taken (j = &a)
10194// CHECK-LABEL: test6{{:|\[}}
10295#[ no_mangle]
10396pub unsafe extern "C" fn test6 ( ) {
@@ -117,6 +110,7 @@ pub unsafe extern "C" fn test6() {
117110 // missing-NOT: __security_check_cookie
118111}
119112
113+ // test7: PtrToInt Cast
120114// CHECK-LABEL: test7{{:|\[}}
121115#[ no_mangle]
122116pub fn test7 ( a : i32 ) {
@@ -132,6 +126,7 @@ pub fn test7(a: i32) {
132126 // missing-NOT: __security_check_cookie
133127}
134128
129+ // test8: Passing addr-of to function call
135130// CHECK-LABEL: test8{{:|\[}}
136131#[ no_mangle]
137132pub fn test8 ( mut b : i32 ) {
@@ -145,6 +140,7 @@ pub fn test8(mut b: i32) {
145140 // missing-NOT: __security_check_cookie
146141}
147142
143+ // test9: Addr-of in select instruction
148144// CHECK-LABEL: test9{{:|\[}}
149145#[ no_mangle]
150146pub fn test9 ( ) {
@@ -165,6 +161,7 @@ pub fn test9() {
165161 // missing-NOT: __security_check_cookie
166162}
167163
164+ // test10: Addr-of in phi instruction
168165// CHECK-LABEL: test10{{:|\[}}
169166#[ no_mangle]
170167pub fn test10 ( ) {
@@ -197,6 +194,7 @@ pub fn test10() {
197194 // missing-NOT: __security_check_cookie
198195}
199196
197+ // test11: Addr-of struct element(GEP followed by store)
200198// CHECK-LABEL: test11{{:|\[}}
201199#[ no_mangle]
202200pub fn test11 ( ) {
@@ -217,6 +215,7 @@ pub fn test11() {
217215 // missing-NOT: __security_check_cookie
218216}
219217
218+ // test12: Addr-of struct element, GEP followed by ptrtoint
220219// CHECK-LABEL: test12{{:|\[}}
221220#[ no_mangle]
222221pub fn test12 ( ) {
@@ -236,6 +235,7 @@ pub fn test12() {
236235 // missing-NOT: __security_check_cookie
237236}
238237
238+ // test13: Addr-of struct element, GEP followed by callinst
239239// CHECK-LABEL: test13{{:|\[}}
240240#[ no_mangle]
241241pub fn test13 ( ) {
@@ -253,6 +253,7 @@ pub fn test13() {
253253 // missing-NOT: __security_check_cookie
254254}
255255
256+ // test14: Addr-of a local, optimized into a GEP (e.g., &a - 12)
256257// CHECK-LABEL: test14{{:|\[}}
257258#[ no_mangle]
258259pub fn test14 ( ) {
@@ -270,6 +271,8 @@ pub fn test14() {
270271 // missing-NOT: __security_check_cookie
271272}
272273
274+ // test15: Addr-of a local cast to a ptr of a different type
275+ // (e.g., int a; ... ; ptr b = &a;)
273276// CHECK-LABEL: test15{{:|\[}}
274277#[ no_mangle]
275278pub fn test15 ( ) {
@@ -290,6 +293,8 @@ pub fn test15() {
290293 // missing-NOT: __security_check_cookie
291294}
292295
296+ // test16: Addr-of a local cast to a ptr of a different type (optimized)
297+ // (e.g., int a; ... ; ptr b = &a;)
293298// CHECK-LABEL: test16{{:|\[}}
294299#[ no_mangle]
295300pub fn test16 ( ) {
@@ -304,10 +309,7 @@ pub fn test16() {
304309 // missing-NOT: __security_check_cookie
305310}
306311
307- // Note: test17
308- // Addr-of a vector nested in a struct:
309- // There is no such type in rustc corresbonding to '%struct.vec = type { <4 x i32> }' in LLVM.
310-
312+ // test18: Addr-of a variable passed into an invoke instruction
311313// CHECK-LABEL: test18{{:|\[}}
312314#[ no_mangle]
313315pub unsafe extern "C" fn test18 ( ) -> i32 {
@@ -325,6 +327,8 @@ pub unsafe extern "C" fn test18() -> i32 {
325327 // missing-NOT: __security_check_cookie
326328}
327329
330+ // test19: Addr-of a struct element passed into an invoke instruction
331+ // (GEP followed by an invoke)
328332// CHECK-LABEL: test19{{:|\[}}
329333#[ no_mangle]
330334pub unsafe extern "C" fn test19 ( ) -> i32 {
@@ -342,6 +346,7 @@ pub unsafe extern "C" fn test19() -> i32 {
342346 // missing-NOT: __security_check_cookie
343347}
344348
349+ // test20: Addr-of a pointer
345350// CHECK-LABEL: test20{{:|\[}}
346351#[ no_mangle]
347352pub unsafe extern "C" fn test20 ( ) {
@@ -361,6 +366,7 @@ pub unsafe extern "C" fn test20() {
361366 // missing-NOT: __security_check_cookie
362367}
363368
369+ // test21: Addr-of a casted pointer
364370// CHECK-LABEL: test21{{:|\[}}
365371#[ no_mangle]
366372pub unsafe extern "C" fn test21 ( ) {
@@ -380,16 +386,7 @@ pub unsafe extern "C" fn test21() {
380386 // missing-NOT: __security_check_cookie
381387}
382388
383- // Note: test22
384- // [2 x i8] in struct will be automatically optimized to i16
385- // and will not trigger the sspstrong
386-
387- // Note: test23
388- // [2 x i8] nested in several layers of structs and unions: same as test22
389-
390- // Note: test24
391- // Variable sized alloca(VLA): see https://github.com/rust-lang/rfcs/pull/1909
392-
389+ // test25: array of [4 x i32]
393390// CHECK-LABEL: test25{{:|\[}}
394391#[ no_mangle]
395392pub unsafe extern "C" fn test25 ( ) -> i32 {
@@ -405,6 +402,9 @@ pub unsafe extern "C" fn test25() -> i32 {
405402 // missing-NOT: __security_check_cookie
406403}
407404
405+ // test26: Nested structure, no arrays, no address-of expressions
406+ // Verify that the resulting gep-of-gep does not incorrectly trigger
407+ // a stack protector
408408// CHECK-LABEL: test26{{:|\[}}
409409#[ no_mangle]
410410pub unsafe extern "C" fn test26 ( ) {
@@ -419,6 +419,11 @@ pub unsafe extern "C" fn test26() {
419419 // strong-NOT: __security_check_cookie
420420}
421421
422+ // test27: Address-of a structure taken in a function with a loop where
423+ // the alloca is an incoming value to a PHI node and a use of that PHI
424+ // node is also an incoming value
425+ // Verify that the address-of analysis does not get stuck in infinite
426+ // recursion when chasing the alloca through the PHI nodes
422427// CHECK-LABEL: test27{{:|\[}}
423428#[ no_mangle]
424429pub unsafe extern "C" fn test27 ( ) -> i32 {
0 commit comments