From 13faa231c20da8b93b3ee40a93deefd4d9f4274c Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Mon, 15 Apr 2024 14:59:55 +0100 Subject: [PATCH] aco/tests: don't assume constructor order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "tests" might not be initialized when this constructor is called. Just use a pointer instead. Fixes aco_tests with LTO enabled. Signed-off-by: Rhys Perry Reviewed-by: Timur Kristóf Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11009 Part-of: --- src/amd/compiler/tests/framework.h | 6 ++++-- src/amd/compiler/tests/main.cpp | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/amd/compiler/tests/framework.h b/src/amd/compiler/tests/framework.h index fd239e0045d..33180c4f775 100644 --- a/src/amd/compiler/tests/framework.h +++ b/src/amd/compiler/tests/framework.h @@ -22,7 +22,7 @@ struct TestDef { void (*func)(); }; -extern std::map tests; +extern std::map *tests; extern FILE* output; bool set_variant(const char* name); @@ -46,7 +46,9 @@ void skip_test(const char* fmt, ...); static void struct_name(); \ static __attribute__((constructor)) void CONCAT2(add_test_, __COUNTER__)() \ { \ - tests[#name] = (TestDef){#name, ACO_TEST_BUILD_ROOT "/" __FILE__, &struct_name}; \ + if (!tests) \ + tests = new std::map; \ + (*tests)[#name] = (TestDef){#name, ACO_TEST_BUILD_ROOT "/" __FILE__, &struct_name}; \ } \ static void struct_name() \ { diff --git a/src/amd/compiler/tests/main.cpp b/src/amd/compiler/tests/main.cpp index 29afa166181..5685bfb7ef3 100644 --- a/src/amd/compiler/tests/main.cpp +++ b/src/amd/compiler/tests/main.cpp @@ -33,7 +33,7 @@ static const char* help_message = " -l --list List unit tests.\n" " --no-check Print test output instead of checking it.\n"; -std::map tests; +std::map *tests = NULL; FILE* output = NULL; static TestDef current_test; @@ -225,8 +225,11 @@ main(int argc, char** argv) return 99; } + if (!tests) + tests = new std::map; + if (do_list) { - for (auto test : tests) + for (auto test : *tests) printf("%s\n", test.first.c_str()); return 99; } @@ -253,7 +256,7 @@ main(int argc, char** argv) aco::init(); - for (auto pair : tests) { + for (auto pair : *tests) { bool found = names.empty(); bool all_variants = names.empty(); std::set variants;