Skip to content

Commit 1dec27b

Browse files
debuginfo: Fixed option-like-enum test case so it does not rely on undefined behavior.
1 parent 680eb71 commit 1dec27b

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/test/debug-info/option-like-enum.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
// xfail-win32 Broken because of LLVM bug: http://llvm.org/bugs/show_bug.cgi?id=16249
12-
// xfail-test broken in newrt?
1312

1413
// compile-flags:-Z extra-debug-info
1514
// debugger:break zzz
@@ -25,31 +24,47 @@
2524
// debugger:print full
2625
// check:$3 = {454545, 0x87654321, 9988}
2726

28-
// debugger:print empty
29-
// check:$4 = {0, 0x0, 0}
27+
// debugger:print empty->discr
28+
// check:$4 = (int *) 0x0
3029

3130
// debugger:print droid
3231
// check:$5 = {id = 675675, range = 10000001, internals = 0x43218765}
3332

34-
// debugger:print void_droid
35-
// check:$6 = {id = 0, range = 0, internals = 0x0}
33+
// debugger:print void_droid->internals
34+
// check:$6 = (int *) 0x0
3635

36+
// debugger:continue
3737

3838
// If a struct has exactly two variants, one of them is empty, and the other one
3939
// contains a non-nullable pointer, then this value is used as the discriminator.
4040
// The test cases in this file make sure that something readable is generated for
4141
// this kind of types.
42+
// Unfortunately (for these test cases) the content of the non-discriminant fields
43+
// in the null-case is not defined. So we just read the discriminator field in
44+
// this case (by casting the value to a memory-equivalent struct).
4245

4346
enum MoreFields<'self> {
4447
Full(u32, &'self int, i16),
4548
Empty
4649
}
4750

51+
struct MoreFieldsRepr<'self> {
52+
a: u32,
53+
discr: &'self int,
54+
b: i16
55+
}
56+
4857
enum NamedFields<'self> {
4958
Droid { id: i32, range: i64, internals: &'self int },
5059
Void
5160
}
5261

62+
struct NamedFieldsRepr<'self> {
63+
id: i32,
64+
range: i64,
65+
internals: &'self int
66+
}
67+
5368
fn main() {
5469

5570
let some: Option<&u32> = Some(unsafe { std::cast::transmute(0x12345678) });
@@ -58,15 +73,17 @@ fn main() {
5873
let full = Full(454545, unsafe { std::cast::transmute(0x87654321) }, 9988);
5974

6075
let int_val = 0;
61-
let mut empty = Full(0, &int_val, 0);
62-
empty = Empty;
76+
let empty: &MoreFieldsRepr = unsafe { std::cast::transmute(&Empty) };
6377

64-
let droid = Droid { id: 675675, range: 10000001, internals: unsafe { std::cast::transmute(0x43218765) } };
78+
let droid = Droid {
79+
id: 675675,
80+
range: 10000001,
81+
internals: unsafe { std::cast::transmute(0x43218765) }
82+
};
6583

66-
let mut void_droid = Droid { id: 0, range: 0, internals: &int_val };
67-
void_droid = Void;
84+
let void_droid: &NamedFieldsRepr = unsafe { std::cast::transmute(&Void) };
6885

6986
zzz();
7087
}
7188

72-
fn zzz() {()}
89+
fn zzz() {()}

0 commit comments

Comments
 (0)