From 295fe03eefd80aee46d77462f192e8d20b103aff Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 12 Jan 2024 14:47:10 +0100 Subject: [PATCH] unittests/ThunkLibs: Add simple struct repacking tests These just ensure that two specific but common patterns continue to compile. --- unittests/ThunkLibs/generator.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/unittests/ThunkLibs/generator.cpp b/unittests/ThunkLibs/generator.cpp index 1d6c7391f..bbbc9d3ca 100644 --- a/unittests/ThunkLibs/generator.cpp +++ b/unittests/ThunkLibs/generator.cpp @@ -713,6 +713,11 @@ TEST_CASE_METHOD(Fixture, "StructRepacking") { } } + SECTION("Pointer to struct with pointer member of consistent data layout") { + std::string type = GENERATE("char", "short", "int", "float"); + REQUIRE_NOTHROW(run_thunkgen_host("struct A { " + type + "* a; };\n", code, guest_abi)); + } + SECTION("Pointer to struct with pointer member of opaque type") { const auto prelude = "struct B;\n" @@ -720,6 +725,10 @@ TEST_CASE_METHOD(Fixture, "StructRepacking") { // Unannotated REQUIRE_THROWS_WITH(run_thunkgen_host(prelude, code, guest_abi), Catch::Contains("incomplete type")); + + // Annotated as opaque_type + CHECK_NOTHROW(run_thunkgen_host(prelude, + code + "template<> struct fex_gen_type : fexgen::opaque_type {};\n", guest_abi)); } }