Skip to content

Commit 4c0100a

Browse files
rootroot
authored andcommitted
add test cases
1 parent 651251f commit 4c0100a

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
395395
// stack protector
396396
to_add.extend(stackprotector_attr(cx, instance.def_id()));
397397

398-
399398
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_BUILTINS) {
400399
to_add.push(llvm::CreateAttrString(cx.llcx, "no-builtins"));
401400
}

tests/assembly/stack-protector/stack-protector-heuristics-effect-windows-64bit.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ pub fn local_large_var_moved(f: fn(Gigastruct)) {
260260
// none-NOT: __security_check_cookie
261261
// missing-NOT: __security_check_cookie
262262

263-
// TODO: How does the rust compiler handle moves of large structures?
263+
// FIXME: How does the rust compiler handle moves of large structures?
264264
// rusty-NOT: __security_check_cookie
265265
}
266266

@@ -292,7 +292,7 @@ pub fn local_large_var_cloned(f: fn(Gigastruct)) {
292292
// none-NOT: __security_check_cookie
293293
// missing-NOT: __security_check_cookie
294294

295-
// TODO: How does the rust compiler handle moves of large structures?
295+
// FIXME: How does the rust compiler handle moves of large structures?
296296
// rusty-NOT: __security_check_cookie
297297
}
298298

@@ -335,7 +335,7 @@ pub fn alloca_small_compile_time_constant_arg(f: fn(*mut ())) {
335335
// none-NOT: __security_check_cookie
336336
// missing-NOT: __security_check_cookie
337337

338-
// TODO: Rusty thinks a function that returns a mutable raw pointer may
338+
// FIXME: Rusty thinks a function that returns a mutable raw pointer may
339339
// be a stack memory allocation function, so it performs stack smash protection.
340340
// Is it possible to optimize the heuristics?
341341
// rusty: __security_check_cookie
@@ -352,9 +352,6 @@ pub fn alloca_large_compile_time_constant_arg(f: fn(*mut ())) {
352352
// none-NOT: __security_check_cookie
353353
// missing-NOT: __security_check_cookie
354354

355-
// TODO: Rusty thinks a function that returns a mutable raw pointer may
356-
// be a stack memory allocation function, so it performs stack smash protection.
357-
// Is it possible to optimize the heuristics?
358355
// rusty: __security_check_cookie
359356
}
360357

@@ -369,9 +366,6 @@ pub fn alloca_dynamic_arg(f: fn(*mut ()), n: usize) {
369366
// none-NOT: __security_check_cookie
370367
// missing-NOT: __security_check_cookie
371368

372-
// TODO: Rusty thinks a function that returns a mutable raw pointer may
373-
// be a stack memory allocation function, so it performs stack smash protection.
374-
// Is it possible to optimize the heuristics?
375369
// rusty: __security_check_cookie
376370
}
377371

tests/assembly/stack-protector/stack-protector-heuristics-effect.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
//@ revisions: all strong basic none missing
1+
//@ revisions: all strong basic none missing rusty
22
//@ assembly-output: emit-asm
33
//@ ignore-apple slightly different policy on stack protection of arrays
44
//@ ignore-msvc stack check code uses different function names
55
//@ ignore-nvptx64 stack protector is not supported
66
//@ ignore-wasm32-bare
77
//@ [all] compile-flags: -Z stack-protector=all
8+
//@ [rusty] compile-flags: -Z stack-protector=rusty
89
//@ [strong] compile-flags: -Z stack-protector=strong
910
//@ [basic] compile-flags: -Z stack-protector=basic
1011
//@ [none] compile-flags: -Z stack-protector=none
@@ -27,6 +28,8 @@ pub fn emptyfn() {
2728
// basic-NOT: __stack_chk_fail
2829
// none-NOT: __stack_chk_fail
2930
// missing-NOT: __stack_chk_fail
31+
32+
// rusty-NOT: __stack_chk_fail
3033
}
3134

3235
// CHECK-LABEL: array_char
@@ -45,6 +48,8 @@ pub fn array_char(f: fn(*const char)) {
4548
// basic: __stack_chk_fail
4649
// none-NOT: __stack_chk_fail
4750
// missing-NOT: __stack_chk_fail
51+
52+
// rusty: __stack_chk_fail
4853
}
4954

5055
// CHECK-LABEL: array_u8_1
@@ -61,6 +66,8 @@ pub fn array_u8_1(f: fn(*const u8)) {
6166
// basic-NOT: __stack_chk_fail
6267
// none-NOT: __stack_chk_fail
6368
// missing-NOT: __stack_chk_fail
69+
70+
// rusty: __stack_chk_fail
6471
}
6572

6673
// CHECK-LABEL: array_u8_small:
@@ -78,6 +85,8 @@ pub fn array_u8_small(f: fn(*const u8)) {
7885
// basic-NOT: __stack_chk_fail
7986
// none-NOT: __stack_chk_fail
8087
// missing-NOT: __stack_chk_fail
88+
89+
// rusty: __stack_chk_fail
8190
}
8291

8392
// CHECK-LABEL: array_u8_large:
@@ -94,6 +103,8 @@ pub fn array_u8_large(f: fn(*const u8)) {
94103
// basic: __stack_chk_fail
95104
// none-NOT: __stack_chk_fail
96105
// missing-NOT: __stack_chk_fail
106+
107+
// rusty: __stack_chk_fail
97108
}
98109

99110
#[derive(Copy, Clone)]
@@ -113,6 +124,8 @@ pub fn array_bytesizednewtype_9(f: fn(*const ByteSizedNewtype)) {
113124
// basic: __stack_chk_fail
114125
// none-NOT: __stack_chk_fail
115126
// missing-NOT: __stack_chk_fail
127+
128+
// rusty: __stack_chk_fail
116129
}
117130

118131
// CHECK-LABEL: local_var_addr_used_indirectly
@@ -140,6 +153,8 @@ pub fn local_var_addr_used_indirectly(f: fn(bool)) {
140153
// basic-NOT: __stack_chk_fail
141154
// none-NOT: __stack_chk_fail
142155
// missing-NOT: __stack_chk_fail
156+
157+
// rusty: __stack_chk_fail
143158
}
144159

145160
// CHECK-LABEL: local_string_addr_taken
@@ -156,6 +171,8 @@ pub fn local_string_addr_taken(f: fn(&String)) {
156171
// basic: __stack_chk_fail
157172
// none-NOT: __stack_chk_fail
158173
// missing-NOT: __stack_chk_fail
174+
175+
// rusty: __stack_chk_fail
159176
}
160177

161178
pub trait SelfByRef {
@@ -185,6 +202,9 @@ pub fn local_var_addr_taken_used_locally_only(factory: fn() -> i32, sink: fn(i32
185202
// basic-NOT: __stack_chk_fail
186203
// none-NOT: __stack_chk_fail
187204
// missing-NOT: __stack_chk_fail
205+
206+
// FIXME: rusty stack smash protection needs to support inline scenario detection
207+
// rusty: __stack_chk_fail
188208
}
189209

190210
pub struct Gigastruct {
@@ -222,6 +242,9 @@ pub fn local_large_var_moved(f: fn(Gigastruct)) {
222242
// basic: __stack_chk_fail
223243
// none-NOT: __stack_chk_fail
224244
// missing-NOT: __stack_chk_fail
245+
246+
// FIXME: How does the rust compiler handle moves of large structures?
247+
// rusty-NOT: __stack_chk_fail
225248
}
226249

227250
// CHECK-LABEL: local_large_var_cloned
@@ -251,6 +274,9 @@ pub fn local_large_var_cloned(f: fn(Gigastruct)) {
251274
// basic: __stack_chk_fail
252275
// none-NOT: __stack_chk_fail
253276
// missing-NOT: __stack_chk_fail
277+
278+
// FIXME: How does the rust compiler handle moves of large structures?
279+
// rusty-NOT: __stack_chk_fail
254280
}
255281

256282
extern "C" {
@@ -291,6 +317,11 @@ pub fn alloca_small_compile_time_constant_arg(f: fn(*mut ())) {
291317
// basic-NOT: __stack_chk_fail
292318
// none-NOT: __stack_chk_fail
293319
// missing-NOT: __stack_chk_fail
320+
321+
// FIXME: Rusty thinks a function that returns a mutable raw pointer may
322+
// be a stack memory allocation function, so it performs stack smash protection.
323+
// Is it possible to optimize the heuristics?
324+
// rusty: __stack_chk_fail
294325
}
295326

296327
// CHECK-LABEL: alloca_large_compile_time_constant_arg
@@ -303,6 +334,8 @@ pub fn alloca_large_compile_time_constant_arg(f: fn(*mut ())) {
303334
// basic-NOT: __stack_chk_fail
304335
// none-NOT: __stack_chk_fail
305336
// missing-NOT: __stack_chk_fail
337+
338+
// rusty: __stack_chk_fail
306339
}
307340

308341
// CHECK-LABEL: alloca_dynamic_arg
@@ -315,6 +348,8 @@ pub fn alloca_dynamic_arg(f: fn(*mut ()), n: usize) {
315348
// basic-NOT: __stack_chk_fail
316349
// none-NOT: __stack_chk_fail
317350
// missing-NOT: __stack_chk_fail
351+
352+
// rusty: __stack_chk_fail
318353
}
319354

320355
// The question then is: in what ways can Rust code generate array-`alloca`
@@ -342,6 +377,9 @@ pub fn unsized_fn_param(s: [u8], l: bool, f: fn([u8])) {
342377
// basic-NOT: __stack_chk_fail
343378
// none-NOT: __stack_chk_fail
344379
// missing-NOT: __stack_chk_fail
380+
381+
// FIXME: Does Rusty need to handle this type of optimization?
382+
// rusty: __stack_chk_fail
345383
}
346384

347385
// CHECK-LABEL: unsized_local
@@ -361,4 +399,6 @@ pub fn unsized_local(s: &[u8], l: bool, f: fn(&mut [u8])) {
361399
// basic: __stack_chk_fail
362400
// none-NOT: __stack_chk_fail
363401
// missing-NOT: __stack_chk_fail
402+
403+
// rusty: __stack_chk_fail
364404
}

0 commit comments

Comments
 (0)