Skip to content

Commit c526683

Browse files
[MemProf] Simplify unittest save and restore of options (#139117)
Address post-commit review feedback for PR139092 (and fix another instance of the same code). Save and restore option values via a saved bool value, instead of invoking cl::ResetAllOptionOccurrences.
1 parent 254c13d commit c526683

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

llvm/unittests/Analysis/MemoryProfileInfoTest.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,17 @@ TEST_F(MemoryProfileInfoTest, GetAllocType) {
8888
100);
8989

9090
// Make sure the option for detecting hot allocations is set.
91+
bool OrigMemProfUseHotHints = MemProfUseHotHints;
9192
MemProfUseHotHints = true;
93+
9294
// Test Hot
9395
// More accesses per byte per sec than hot threshold is hot.
9496
EXPECT_EQ(getAllocType(HotTotalLifetimeAccessDensityThreshold + 1, AllocCount,
9597
ColdTotalLifetimeThreshold + 1),
9698
AllocationType::Hot);
97-
// Undo the manual set of the option above.
98-
cl::ResetAllOptionOccurrences();
99+
100+
// Restore original option value.
101+
MemProfUseHotHints = OrigMemProfUseHotHints;
99102

100103
// Without MemProfUseHotHints (default) we should treat simply as NotCold.
101104
EXPECT_EQ(getAllocType(HotTotalLifetimeAccessDensityThreshold + 1, AllocCount,
@@ -590,12 +593,13 @@ declare dso_local noalias noundef i8* @malloc(i64 noundef)
590593
ASSERT_NE(Call, nullptr);
591594

592595
// Specify that all non-cold contexts should be kept.
596+
bool OrigMemProfKeepAllNotColdContexts = MemProfKeepAllNotColdContexts;
593597
MemProfKeepAllNotColdContexts = true;
594598

595599
Trie.buildAndAttachMIBMetadata(Call);
596600

597-
// Undo the manual set of the MemProfKeepAllNotColdContexts above.
598-
cl::ResetAllOptionOccurrences();
601+
// Restore original option value.
602+
MemProfKeepAllNotColdContexts = OrigMemProfKeepAllNotColdContexts;
599603

600604
EXPECT_FALSE(Call->hasFnAttr("memprof"));
601605
EXPECT_TRUE(Call->hasMetadata(LLVMContext::MD_memprof));

0 commit comments

Comments
 (0)