blob: bc2c59fe4aa99641de7bbfd45b9a7251d74f140d [file] [log] [blame]
Ben Kimocka5614842024-08-10 02:33:401//@ min-lldb-version: 1800
sh8281.kim4e548282013-11-04 06:53:012
许杰友 Jieyou Xu (Joe)6e48b962024-02-22 12:10:293//@ compile-flags:-g
Michael Woeristerc7f45a92014-07-09 12:46:094
5// === GDB TESTS ===================================================================================
6
Michael Woerister55a8bd52014-04-24 09:35:487// gdb-command:set print union on
Michael Woerister55a8bd52014-04-24 09:35:488// gdb-command:run
Michael Woerister70e5c082013-07-11 08:17:319
Michael Woerister55a8bd52014-04-24 09:35:4810// gdb-command:print case1
Ben Kimockfa0e8582024-08-17 21:31:4911// gdb-check:$1 = struct_in_enum::Regular::Case1(0, struct_in_enum::Struct {x: 2088533116, y: 2088533116, z: 31868})
Michael Woerister70e5c082013-07-11 08:17:3112
Michael Woerister55a8bd52014-04-24 09:35:4813// gdb-command:print case2
Ben Kimockfa0e8582024-08-17 21:31:4914// gdb-check:$2 = struct_in_enum::Regular::Case2(0, 1229782938247303441, 4369)
Michael Woerister70e5c082013-07-11 08:17:3115
Michael Woerister55a8bd52014-04-24 09:35:4816// gdb-command:print univariant
Ben Kimockfa0e8582024-08-17 21:31:4917// gdb-check:$3 = struct_in_enum::Univariant::TheOnlyCase(struct_in_enum::Struct {x: 123, y: 456, z: 789})
Michael Woerister70e5c082013-07-11 08:17:3118
Michael Woeristerc7f45a92014-07-09 12:46:0919
20// === LLDB TESTS ==================================================================================
21
22// lldb-command:run
23
Markus Reiter96431e42024-03-15 14:05:5724// lldb-command:v case1
Markus Reiter75fba9d2024-03-10 13:55:5825// lldb-check:[...] Case1(0, Struct { x: 2088533116, y: 2088533116, z: 31868 })
Markus Reiter96431e42024-03-15 14:05:5726// lldb-command:v case2
Markus Reiter75fba9d2024-03-10 13:55:5827// lldb-check:[...] Case2(0, 1229782938247303441, 4369)
Michael Woeristerc7f45a92014-07-09 12:46:0928
Markus Reiter96431e42024-03-15 14:05:5729// lldb-command:v univariant
Markus Reiter75fba9d2024-03-10 13:55:5830// lldb-check:[...] TheOnlyCase(Struct { x: 123, y: 456, z: 789 })
Michael Woeristerc7f45a92014-07-09 12:46:0931
Aaron Turone0ad0fc2014-10-27 22:37:0732#![allow(unused_variables)]
Andrew Paseltiner6fa0ff22015-09-19 20:33:4733#![feature(omit_gdb_pretty_printer_section)]
Michael Woerister91a0e182014-12-03 22:48:1834#![omit_gdb_pretty_printer_section]
Erick Tryzelaarad5c6762013-08-17 15:37:4235
Steven Fackler3dcd2152014-11-06 08:05:5336use self::Regular::{Case1, Case2};
37use self::Univariant::TheOnlyCase;
38
Michael Woerister70e5c082013-07-11 08:17:3139struct Struct {
Derek Guenther730bdb62014-02-05 22:33:1040 x: u32,
41 y: i32,
42 z: i16
Michael Woerister70e5c082013-07-11 08:17:3143}
44
45// The first element is to ensure proper alignment, irrespective of the machines word size. Since
46// the size of the discriminant value is machine dependent, this has be taken into account when
47// datatype layout should be predictable as in this case.
48enum Regular {
49 Case1(u64, Struct),
50 Case2(u64, u64, i16)
51}
52
53enum Univariant {
Derek Guenther730bdb62014-02-05 22:33:1054 TheOnlyCase(Struct)
Michael Woerister70e5c082013-07-11 08:17:3155}
56
57fn main() {
58
Vadim Petrochenkov1accaa92015-03-28 15:09:5159 // In order to avoid endianness trouble all of the following test values consist of a single
Michael Woerister70e5c082013-07-11 08:17:3160 // repeated byte. This way each interpretation of the union should look the same, no matter if
61 // this is a big or little endian machine.
62
63 // 0b0111110001111100011111000111110001111100011111000111110001111100 = 8970181431921507452
64 // 0b01111100011111000111110001111100 = 2088533116
65 // 0b0111110001111100 = 31868
66 // 0b01111100 = 124
67 let case1 = Case1(0, Struct { x: 2088533116, y: 2088533116, z: 31868 });
68
69 // 0b0001000100010001000100010001000100010001000100010001000100010001 = 1229782938247303441
70 // 0b00010001000100010001000100010001 = 286331153
71 // 0b0001000100010001 = 4369
72 // 0b00010001 = 17
73 let case2 = Case2(0, 1229782938247303441, 4369);
74
75 let univariant = TheOnlyCase(Struct { x: 123, y: 456, z: 789 });
76
Michael Woeristerc7f45a92014-07-09 12:46:0977 zzz(); // #break
Michael Woerister70e5c082013-07-11 08:17:3178}
79
80fn zzz() {()}