Skip to content

Commit b55bab2

Browse files
authored
[lldb] Fix plugin manager test failure on windows (#134173)
This is an attempt to fix a test failure from #133794 when running on windows builds. I suspect we are running into a case where the [ICF](https://learn.microsoft.com/en-us/cpp/build/reference/opt-optimizations?view=msvc-170) optimization kicks in and combines the CreateSystemRuntimePlugin* functions into a single address. This means that we cannot uniquely unregister the plugin based on its create function address. The fix is have each create function return a different (bogus) value.
1 parent 7559c64 commit b55bab2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lldb/unittests/Core/PluginManagerTest.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@ using namespace lldb;
77
using namespace lldb_private;
88

99
// Mock system runtime plugin create functions.
10-
SystemRuntime *CreateSystemRuntimePluginA(Process *process) { return nullptr; }
10+
// Make them all return different values to avoid the ICF optimization
11+
// from combining them into the same function. The values returned
12+
// are not valid SystemRuntime pointers, but they are unique and
13+
// sufficient for testing.
14+
SystemRuntime *CreateSystemRuntimePluginA(Process *process) {
15+
return (SystemRuntime *)0x1;
16+
}
1117

12-
SystemRuntime *CreateSystemRuntimePluginB(Process *process) { return nullptr; }
18+
SystemRuntime *CreateSystemRuntimePluginB(Process *process) {
19+
return (SystemRuntime *)0x2;
20+
}
1321

14-
SystemRuntime *CreateSystemRuntimePluginC(Process *process) { return nullptr; }
22+
SystemRuntime *CreateSystemRuntimePluginC(Process *process) {
23+
return (SystemRuntime *)0x3;
24+
}
1525

1626
// Test class for testing the PluginManager.
1727
// The PluginManager modifies global state when registering new plugins. This
@@ -24,6 +34,10 @@ class PluginManagerTest : public testing::Test {
2434

2535
// Add mock system runtime plugins for testing.
2636
void RegisterMockSystemRuntimePlugins() {
37+
// Make sure the create functions all have different addresses.
38+
ASSERT_NE(CreateSystemRuntimePluginA, CreateSystemRuntimePluginB);
39+
ASSERT_NE(CreateSystemRuntimePluginB, CreateSystemRuntimePluginC);
40+
2741
ASSERT_TRUE(PluginManager::RegisterPlugin("a", "test instance A",
2842
CreateSystemRuntimePluginA));
2943
ASSERT_TRUE(PluginManager::RegisterPlugin("b", "test instance B",

0 commit comments

Comments
 (0)