aco/tests: don't assume constructor order

"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 <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11009
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28748>
This commit is contained in:
Rhys Perry 2024-04-15 14:59:55 +01:00 committed by Marge Bot
parent 71fdc67682
commit 13faa231c2
2 changed files with 10 additions and 5 deletions

View file

@ -22,7 +22,7 @@ struct TestDef {
void (*func)();
};
extern std::map<std::string, TestDef> tests;
extern std::map<std::string, TestDef> *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<std::string, TestDef>; \
(*tests)[#name] = (TestDef){#name, ACO_TEST_BUILD_ROOT "/" __FILE__, &struct_name}; \
} \
static void struct_name() \
{

View file

@ -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<std::string, TestDef> tests;
std::map<std::string, TestDef> *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<std::string, TestDef>;
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<std::string> variants;