Skip to content

Commit 2d86ed1

Browse files
committed
Make some tests bitsize independent
1 parent c99636f commit 2d86ed1

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

tests/ui/consts/dangling_raw_ptr.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Strip out raw byte dumps to make comparison platform-independent:
2+
//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
3+
//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*A(LLOC)?[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
4+
//@ normalize-stderr-test "HEX_DUMP\s*\n\s*HEX_DUMP" -> "HEX_DUMP"
5+
16
const FOO: *const u32 = { //~ ERROR it is undefined behavior
27
let x = 42;
38
&x

tests/ui/consts/dangling_raw_ptr.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/dangling_raw_ptr.rs:1:1
2+
--> $DIR/dangling_raw_ptr.rs:6:1
33
|
44
LL | const FOO: *const u32 = {
55
| ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (use-after-free)
66
|
77
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
8-
= note: the raw bytes of the constant (size: 8, align: 8) {
9-
╾ALLOC0<imm>╼ │ ╾──────╼
8+
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
9+
HEX_DUMP
1010
}
1111

1212
error[E0080]: it is undefined behavior to use this value
13-
--> $DIR/dangling_raw_ptr.rs:10:1
13+
--> $DIR/dangling_raw_ptr.rs:15:1
1414
|
1515
LL | const BAR: Union = {
1616
| ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (use-after-free)
1717
|
1818
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
19-
= note: the raw bytes of the constant (size: 8, align: 8) {
20-
╾ALLOC1<imm>╼ │ ╾──────╼
19+
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
20+
HEX_DUMP
2121
}
2222

2323
error: aborting due to 2 previous errors

tests/ui/consts/std/cell.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![feature(const_refs_to_cell)]
22

3+
// Strip out raw byte dumps to make comparison platform-independent:
4+
//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
5+
//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*A(LLOC)?[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
6+
//@ normalize-stderr-test "HEX_DUMP\s*\n\s*HEX_DUMP" -> "HEX_DUMP"
7+
38
use std::cell::*;
49

510
// not ok, because this creates a dangling pointer, just like `let x = Cell::new(42).as_ptr()` would

tests/ui/consts/std/cell.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/cell.rs:6:1
2+
--> $DIR/cell.rs:11:1
33
|
44
LL | static FOO: Wrap<*mut u32> = Wrap(Cell::new(42).as_ptr());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered a dangling reference (use-after-free)
66
|
77
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
8-
= note: the raw bytes of the constant (size: 8, align: 8) {
9-
╾ALLOC0╼ │ ╾──────╼
8+
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
9+
HEX_DUMP
1010
}
1111

1212
error[E0080]: it is undefined behavior to use this value
13-
--> $DIR/cell.rs:8:1
13+
--> $DIR/cell.rs:13:1
1414
|
1515
LL | const FOO_CONST: Wrap<*mut u32> = Wrap(Cell::new(42).as_ptr());
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered a dangling reference (use-after-free)
1717
|
1818
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
19-
= note: the raw bytes of the constant (size: 8, align: 8) {
20-
╾ALLOC1╼ │ ╾──────╼
19+
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
20+
HEX_DUMP
2121
}
2222

2323
error[E0080]: it is undefined behavior to use this value
24-
--> $DIR/cell.rs:22:1
24+
--> $DIR/cell.rs:27:1
2525
|
2626
LL | const FOO4_CONST: Wrap<*mut u32> = Wrap(FOO3_CONST.0.as_ptr());
2727
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered a dangling reference (use-after-free)
2828
|
2929
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
30-
= note: the raw bytes of the constant (size: 8, align: 8) {
31-
╾ALLOC2╼ │ ╾──────╼
30+
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
31+
HEX_DUMP
3232
}
3333

3434
error[E0080]: it is undefined behavior to use this value
35-
--> $DIR/cell.rs:27:1
35+
--> $DIR/cell.rs:32:1
3636
|
3737
LL | const FOO2: *mut u32 = Cell::new(42).as_ptr();
3838
| ^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (use-after-free)
3939
|
4040
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
41-
= note: the raw bytes of the constant (size: 8, align: 8) {
42-
╾ALLOC3╼ │ ╾──────╼
41+
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
42+
HEX_DUMP
4343
}
4444

4545
error: aborting due to 4 previous errors

0 commit comments

Comments
 (0)