rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.92k stars 12.53k forks source link

Unexpected nulls in debuginfo tests on windows-gnu #129662

Closed mati865 closed 2 weeks ago

mati865 commented 3 weeks ago

Since https://github.com/rust-lang/rust/pull/119229 GDB used on CI is recent enough to run the new tests. However, there are three failures that have been ignored in #119229:

tests\debuginfo\method-on-enum.rs (happened only on 32-bits) ``` ---- [debuginfo-gdb] tests\debuginfo\method-on-enum.rs stdout ---- NOTE: compiletest thinks it is using GDB version 14002000 error: gdb failed to execute status: exit code: 1 command: PATH="C:\a\rust\rust\build\i686-pc-windows-gnu\stage2\lib\rustlib\i686-pc-windows-gnu\lib;C:\a\rust\rust\build\i686-pc-windows-gnu\stage0-bootstrap-tools\i686-pc-windows-gnu\release\deps;C:\a\rust\rust\build\i686-pc-windows-gnu\stage0\bin;C:\a\_temp\msys64\mingw32\bin;C:\a\_temp\msys64\usr\local\bin;C:\a\_temp\msys64\usr\bin;C:\a\_temp\msys64\usr\bin;C:\a\rust\rust\ninja;C:\a\rust\rust\mingw32\bin;C:\a\rust\rust\sccache;C:\a\_temp\setup-msys2;C:\Program Files\MongoDB\Server\5.0\bin;C:\aliyun-cli;C:\vcpkg;C:\Program Files (x86)\NSIS;C:\tools\zstd;C:\Program Files\Mercurial;C:\hostedtoolcache\windows\stack\3.1.1\x64;C:\cabal\bin;C:\ghcup\bin;C:\mingw64\bin;C:\Program Files\dotnet;C:\Program Files\MySQL\MySQL Server 8.0\bin;C:\Program Files\R\R-4.4.1\bin\x64;C:\SeleniumWebDrivers\GeckoDriver;C:\SeleniumWebDrivers\EdgeDriver;C:\SeleniumWebDrivers\ChromeDriver;C:\Program Files (x86)\sbt\bin;C:\Program Files (x86)\GitHub CLI;C:\Program Files\Git\bin;C:\Program Files (x86)\pipx_bin;C:\npm\prefix;C:\hostedtoolcache\windows\go\1.21.13\x64\bin;C:\hostedtoolcache\windows\Python\3.9.13\x64\Scripts;C:\hostedtoolcache\windows\Python\3.9.13\x64;C:\hostedtoolcache\windows\Ruby\3.0.7\x64\bin;C:\Program Files\OpenSSL\bin;C:\tools\kotlinc\bin;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.422-5\x64\bin;C:\Program Files\ImageMagick-7.1.1-Q16-HDRI;C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin;C:\ProgramData\kind;C:\ProgramData\Chocolatey\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\PowerShell\7;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\Microsoft SQL Server\150\Tools\Binn;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\Program Files (x86)\WiX Toolset v3.14\bin;C:\Program Files\Microsoft SQL Server\130\DTS\Binn;C:\Program Files\Microsoft SQL Server\140\DTS\Binn;C:\Program Files\Microsoft SQL Server\150\DTS\Binn;C:\Program Files\Microsoft SQL Server\160\DTS\Binn;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin;C:\Program Files\CMake\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.8.7\bin;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code;C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\GitHub CLI;C:\tools\php;C:\Program Files (x86)\sbt\bin;C:\Program Files\Amazon\AWSCLIV2;C:\Program Files\Amazon\SessionManagerPlugin\bin;C:\Program Files\Amazon\AWSSAMCLI\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\LLVM\bin;C:\Users\runneradmin\.dotnet\tools;C:\Users\runneradmin\.cargo\bin;C:\Users\runneradmin\AppData\Local\Microsoft\WindowsApps;C:\a\_temp\msys64\usr\bin\site_perl;C:\a\_temp\msys64\usr\bin\vendor_perl;C:\a\_temp\msys64\usr\bin\core_perl" "C:\\a\\rust\\rust\\mingw32\\bin\\gdb" "-quiet" "-batch" "-nx" "-command=C:\\a\\rust\\rust\\build\\i686-pc-windows-gnu\\test\\debuginfo\\method-on-enum.gdb\\method-on-enum.debugger.script" --- stdout ------------------------------- GNU gdb (GDB) 14.2 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-w64-mingw32". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word". Breakpoint 1 at 0x401c85: file tests\debuginfo/method-on-enum.rs, line 117. Breakpoint 2 at 0x401cc2: file tests\debuginfo/method-on-enum.rs, line 122. Breakpoint 3 at 0x401d05: file tests\debuginfo/method-on-enum.rs, line 127. [New Thread 2968.0xc8c] [New Thread 2968.0x1500] Thread 1 "main" hit Breakpoint 1, method_on_enum::Enum::self_by_ref (self=0x5ffe24, arg1=-1, arg2=-2) at tests\debuginfo/method-on-enum.rs:117 117 zzz(); // #break $1 = method_on_enum::Enum::Variant2(117901063) $2 = -1 $3 = -2 Thread 1 "main" hit Breakpoint 2, method_on_enum::Enum::self_by_val (self=, arg1=-3, arg2=-4) at tests\debuginfo/method-on-enum.rs:122 122 zzz(); // #break ------------------------------------------ --- stderr ------------------------------- C:\a\rust\rust\build\i686-pc-windows-gnu\test\debuginfo\method-on-enum.gdb\method-on-enum.debugger.script:17: Error in sourced command file: Cannot access memory at address 0x0 ------------------------------------------ ```
tests\debuginfo\option-like-enum.rs (happened only on 32-bits) ``` ---- [debuginfo-gdb] tests\debuginfo\option-like-enum.rs stdout ---- NOTE: compiletest thinks it is using GDB version 14002000 error: check directive(s) from `C:\a\rust\rust\tests\debuginfo\option-like-enum.rs` not found in debugger output. errors: (option-like-enum.rs:26) `$6 = (*mut isize) 0x1` the following subset of check directive(s) was found successfully: (option-like-enum.rs:11) `$1 = core::option::Option<&u32>::Some(0x12345678)` (option-like-enum.rs:14) `$2 = core::option::Option<&u32>::None` (option-like-enum.rs:17) `$3 = option_like_enum::MoreFields::Full(454545, 0x87654321, 9988)` (option-like-enum.rs:20) `$4 = (*mut isize) 0x1` (option-like-enum.rs:23) `$5 = option_like_enum::NamedFields::Droid{id: 675675, range: 10000001, internals: 0x43218765}` (option-like-enum.rs:29) `$7 = option_like_enum::NestedNonZero::Yep(10.5, option_like_enum::NestedNonZeroField {a: 10, b: 20, c: 0x5ffe0c})` (option-like-enum.rs:32) `$8 = option_like_enum::NestedNonZero::Nope` status: exit code: 0 command: PATH="C:\a\rust\rust\build\i686-pc-windows-gnu\stage2\lib\rustlib\i686-pc-windows-gnu\lib;C:\a\rust\rust\build\i686-pc-windows-gnu\stage0-bootstrap-tools\i686-pc-windows-gnu\release\deps;C:\a\rust\rust\build\i686-pc-windows-gnu\stage0\bin;C:\a\_temp\msys64\mingw32\bin;C:\a\_temp\msys64\usr\local\bin;C:\a\_temp\msys64\usr\bin;C:\a\_temp\msys64\usr\bin;C:\a\rust\rust\ninja;C:\a\rust\rust\mingw32\bin;C:\a\rust\rust\sccache;C:\a\_temp\setup-msys2;C:\Program Files\MongoDB\Server\5.0\bin;C:\aliyun-cli;C:\vcpkg;C:\Program Files (x86)\NSIS;C:\tools\zstd;C:\Program Files\Mercurial;C:\hostedtoolcache\windows\stack\3.1.1\x64;C:\cabal\bin;C:\ghcup\bin;C:\mingw64\bin;C:\Program Files\dotnet;C:\Program Files\MySQL\MySQL Server 8.0\bin;C:\Program Files\R\R-4.4.1\bin\x64;C:\SeleniumWebDrivers\GeckoDriver;C:\SeleniumWebDrivers\EdgeDriver;C:\SeleniumWebDrivers\ChromeDriver;C:\Program Files (x86)\sbt\bin;C:\Program Files (x86)\GitHub CLI;C:\Program Files\Git\bin;C:\Program Files (x86)\pipx_bin;C:\npm\prefix;C:\hostedtoolcache\windows\go\1.21.13\x64\bin;C:\hostedtoolcache\windows\Python\3.9.13\x64\Scripts;C:\hostedtoolcache\windows\Python\3.9.13\x64;C:\hostedtoolcache\windows\Ruby\3.0.7\x64\bin;C:\Program Files\OpenSSL\bin;C:\tools\kotlinc\bin;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.422-5\x64\bin;C:\Program Files\ImageMagick-7.1.1-Q16-HDRI;C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin;C:\ProgramData\kind;C:\ProgramData\Chocolatey\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\PowerShell\7;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\Microsoft SQL Server\150\Tools\Binn;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\Program Files (x86)\WiX Toolset v3.14\bin;C:\Program Files\Microsoft SQL Server\130\DTS\Binn;C:\Program Files\Microsoft SQL Server\140\DTS\Binn;C:\Program Files\Microsoft SQL Server\150\DTS\Binn;C:\Program Files\Microsoft SQL Server\160\DTS\Binn;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin;C:\Program Files\CMake\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.8.7\bin;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code;C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\GitHub CLI;C:\tools\php;C:\Program Files (x86)\sbt\bin;C:\Program Files\Amazon\AWSCLIV2;C:\Program Files\Amazon\SessionManagerPlugin\bin;C:\Program Files\Amazon\AWSSAMCLI\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\LLVM\bin;C:\Users\runneradmin\.dotnet\tools;C:\Users\runneradmin\.cargo\bin;C:\Users\runneradmin\AppData\Local\Microsoft\WindowsApps;C:\a\_temp\msys64\usr\bin\site_perl;C:\a\_temp\msys64\usr\bin\vendor_perl;C:\a\_temp\msys64\usr\bin\core_perl" "C:\\a\\rust\\rust\\mingw32\\bin\\gdb" "-quiet" "-batch" "-nx" "-command=C:\\a\\rust\\rust\\build\\i686-pc-windows-gnu\\test\\debuginfo\\option-like-enum.gdb\\option-like-enum.debugger.script" --- stdout ------------------------------- GNU gdb (GDB) 14.2 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-w64-mingw32". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word". Breakpoint 1 at 0x401773: file tests\debuginfo/option-like-enum.rs, line 151. [New Thread 7244.0xd9c] [New Thread 7244.0xb8c] Thread 1 "main" hit Breakpoint 1, option_like_enum::main () at tests\debuginfo/option-like-enum.rs:151 151 zzz(); // #break $1 = core::option::Option<&u32>::Some(0x12345678) $2 = core::option::Option<&u32>::None $3 = option_like_enum::MoreFields::Full(454545, 0x87654321, 9988) $4 = (*mut isize) 0x1 $5 = option_like_enum::NamedFields::Droid{id: 675675, range: 10000001, internals: 0x43218765} $6 = (*mut isize) 0x0 $7 = option_like_enum::NestedNonZero::Yep(10.5, option_like_enum::NestedNonZeroField {a: 10, b: 20, c: 0x5ffe0c}) $8 = option_like_enum::NestedNonZero::Nope [Thread 7244.0xb8c exited with code 0] [Thread 7244.0xd9c exited with code 0] [Inferior 1 (process 7244) exited normally] ------------------------------------------ stderr: none ```
tests\debuginfo\by-value-non-immediate-argument ``` ---- [debuginfo-gdb] tests\debuginfo\by-value-non-immediate-argument.rs stdout ---- NOTE: compiletest thinks it is using GDB version 14002000 error: gdb failed to execute status: exit code: 1 command: PATH="C:\a\rust\rust\build\x86_64-pc-windows-gnu\stage2\lib\rustlib\x86_64-pc-windows-gnu\lib;C:\a\rust\rust\build\x86_64-pc-windows-gnu\stage0-bootstrap-tools\x86_64-pc-windows-gnu\release\deps;C:\a\rust\rust\build\x86_64-pc-windows-gnu\stage0\bin;C:\a\_temp\msys64\mingw64\bin;C:\a\_temp\msys64\usr\local\bin;C:\a\_temp\msys64\usr\bin;C:\a\_temp\msys64\usr\bin;C:\a\rust\rust\ninja;C:\a\rust\rust\mingw64\bin;C:\a\rust\rust\sccache;C:\a\_temp\setup-msys2;C:\Program Files\MongoDB\Server\5.0\bin;C:\aliyun-cli;C:\vcpkg;C:\Program Files (x86)\NSIS;C:\tools\zstd;C:\Program Files\Mercurial;C:\hostedtoolcache\windows\stack\3.1.1\x64;C:\cabal\bin;C:\ghcup\bin;C:\mingw64\bin;C:\Program Files\dotnet;C:\Program Files\MySQL\MySQL Server 8.0\bin;C:\Program Files\R\R-4.4.1\bin\x64;C:\SeleniumWebDrivers\GeckoDriver;C:\SeleniumWebDrivers\EdgeDriver;C:\SeleniumWebDrivers\ChromeDriver;C:\Program Files (x86)\sbt\bin;C:\Program Files (x86)\GitHub CLI;C:\Program Files\Git\bin;C:\Program Files (x86)\pipx_bin;C:\npm\prefix;C:\hostedtoolcache\windows\go\1.21.13\x64\bin;C:\hostedtoolcache\windows\Python\3.9.13\x64\Scripts;C:\hostedtoolcache\windows\Python\3.9.13\x64;C:\hostedtoolcache\windows\Ruby\3.0.7\x64\bin;C:\Program Files\OpenSSL\bin;C:\tools\kotlinc\bin;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.422-5\x64\bin;C:\Program Files\ImageMagick-7.1.1-Q16-HDRI;C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin;C:\ProgramData\kind;C:\ProgramData\Chocolatey\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\dotnet;C:\Program Files\PowerShell\7;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\Microsoft SQL Server\150\Tools\Binn;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\Program Files (x86)\WiX Toolset v3.14\bin;C:\Program Files\Microsoft SQL Server\130\DTS\Binn;C:\Program Files\Microsoft SQL Server\140\DTS\Binn;C:\Program Files\Microsoft SQL Server\150\DTS\Binn;C:\Program Files\Microsoft SQL Server\160\DTS\Binn;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin;C:\Program Files\CMake\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.8.7\bin;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code;C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\GitHub CLI;C:\tools\php;C:\Program Files (x86)\sbt\bin;C:\Program Files\Amazon\AWSCLIV2;C:\Program Files\Amazon\SessionManagerPlugin\bin;C:\Program Files\Amazon\AWSSAMCLI\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\LLVM\bin;C:\Users\runneradmin\.dotnet\tools;C:\Users\runneradmin\.cargo\bin;C:\Users\runneradmin\AppData\Local\Microsoft\WindowsApps;C:\a\_temp\msys64\usr\bin\site_perl;C:\a\_temp\msys64\usr\bin\vendor_perl;C:\a\_temp\msys64\usr\bin\core_perl" "C:\\a\\rust\\rust\\mingw64\\bin\\gdb" "-quiet" "-batch" "-nx" "-command=C:\\a\\rust\\rust\\build\\x86_64-pc-windows-gnu\\test\\debuginfo\\by-value-non-immediate-argument.gdb\\by-value-non-immediate-argument.debugger.script" --- stdout ------------------------------- GNU gdb (GDB) 14.2 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-w64-mingw32". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word". Breakpoint 1 at 0x14000159f: file tests\debuginfo/by-value-non-immediate-argument.rs, line 78. Breakpoint 2 at 0x1400015db: file tests\debuginfo/by-value-non-immediate-argument.rs, line 82. Breakpoint 3 at 0x1400015f4: file tests\debuginfo/by-value-non-immediate-argument.rs, line 86. Breakpoint 4 at 0x140001604: file tests\debuginfo/by-value-non-immediate-argument.rs, line 92. Breakpoint 5 at 0x140001614: file tests\debuginfo/by-value-non-immediate-argument.rs, line 104. [New Thread 2820.0xbd8] [New Thread 2820.0x18b8] [New Thread 2820.0x1b54] Thread 1 "main" hit Breakpoint 1, by_value_non_immediate_argument::fun (s=...) at tests\debuginfo/by-value-non-immediate-argument.rs:78 78 zzz(); // #break $1 = by_value_non_immediate_argument::Struct {a: 1, b: 2.5} Thread 1 "main" hit Breakpoint 2, by_value_non_immediate_argument::fun_fun () at tests\debuginfo/by-value-non-immediate-argument.rs:82 82 zzz(); // #break $2 = by_value_non_immediate_argument::Struct {a: 3, b: 4.5} $3 = 5 $4 = 6.5 Thread 1 "main" hit Breakpoint 3, by_value_non_immediate_argument::tup (a=...) at tests\debuginfo/by-value-non-immediate-argument.rs:86 86 zzz(); // #break $5 = Thread 1 "main" hit Breakpoint 4, by_value_non_immediate_argument::new_type (a=...) at tests\debuginfo/by-value-non-immediate-argument.rs:92 92 zzz(); // #break $6 = Thread 1 "main" hit Breakpoint 5, by_value_non_immediate_argument::by_val_enum (x=) at tests\debuginfo/by-value-non-immediate-argument.rs:104 104 zzz(); // #break ------------------------------------------ --- stderr ------------------------------- C:\a\rust\rust\build\x86_64-pc-windows-gnu\test\debuginfo\by-value-non-immediate-argument.gdb\by-value-non-immediate-argument.debugger.script:25: Error in sourced command file: Cannot access memory at address 0x0 ------------------------------------------ ```
mati865 commented 3 weeks ago

@rustbot modify labels: +O-windows-gnu +A-debuginfo

saethlin commented 3 weeks ago

The by-value-non-immediate-argument is https://github.com/rust-lang/rust/issues/128973

Upon further inspection, I am now confident that the enums test failures are actually a change in layout with targets. Such nonsense is typical of the debuginfo tests.

Take this example program, using the enum extracted from the test:

enum NamedFields<'a> {
    #[allow(dead_code)]
    Droid { id: i32, range: i64, internals: &'a isize },
    Void
}

fn main() {
    let e = NamedFields::Void;
    unsafe {
        #[cfg(target_pointer_width = "32")]
        {
            let words = std::mem::transmute::<NamedFields, [std::mem::MaybeUninit<u8>; 16]>(e);
            println!("{:?}", words[12].assume_init());
        }
        #[cfg(target_pointer_width = "64")]
        {
            let words = std::mem::transmute::<NamedFields, [std::mem::MaybeUninit<u8>; 24]>(e);
            println!("{:?}", words[0].assume_init());
        }
    }
}

Which we can run on any target that can print using Miri

x86_64-pc-windows-msvc, x86-64-pc-windows-gnu, and x86_64-unknonw-linux-gnu all print 1. s390x-unknown-linux-gnu and i686-pc-windows-gnu print 0 i686-unknown-linux-gnu reports UB, didn't bother figuring out where its discriminant is at but uh that's sus

So I think the debuggers in the tests are correctly reporting that the discriminant value for NamedFields change between platforms.

saethlin commented 3 weeks ago

Oh I see! option-like-enum says this:

// Unfortunately (for these test cases) the content of the non-discriminant fields // in the null-case is not defined. So we just read the discriminator field in // this case (by casting the value to a memory-equivalent struct).

As far as I can tell, this test has been broken since it was written. You can't rely on field order like this, and indeed as I demonstrated above, fields get reordered differently across targets. The structs and enums also have different field ordering on a single target.