aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Analysis
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2025-05-08 10:57:20 -0700
committerGitHub <noreply@github.com>2025-05-08 10:57:20 -0700
commitc526683c7f2cf94c9e3a55cc810a0bb90e68c646 (patch)
tree87de8ab37ff47d88618300866d303d27d0ef7875 /llvm/unittests/Analysis
parent254c13d872ea378f9e5569060e24c134d37a0ecb (diff)
downloadllvm-c526683c7f2cf94c9e3a55cc810a0bb90e68c646.zip
llvm-c526683c7f2cf94c9e3a55cc810a0bb90e68c646.tar.gz
llvm-c526683c7f2cf94c9e3a55cc810a0bb90e68c646.tar.bz2
[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.
Diffstat (limited to 'llvm/unittests/Analysis')
-rw-r--r--llvm/unittests/Analysis/MemoryProfileInfoTest.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/llvm/unittests/Analysis/MemoryProfileInfoTest.cpp b/llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
index 2943631..170dca0 100644
--- a/llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
+++ b/llvm/unittests/Analysis/MemoryProfileInfoTest.cpp
@@ -88,14 +88,17 @@ TEST_F(MemoryProfileInfoTest, GetAllocType) {
100);
// Make sure the option for detecting hot allocations is set.
+ bool OrigMemProfUseHotHints = MemProfUseHotHints;
MemProfUseHotHints = true;
+
// Test Hot
// More accesses per byte per sec than hot threshold is hot.
EXPECT_EQ(getAllocType(HotTotalLifetimeAccessDensityThreshold + 1, AllocCount,
ColdTotalLifetimeThreshold + 1),
AllocationType::Hot);
- // Undo the manual set of the option above.
- cl::ResetAllOptionOccurrences();
+
+ // Restore original option value.
+ MemProfUseHotHints = OrigMemProfUseHotHints;
// Without MemProfUseHotHints (default) we should treat simply as NotCold.
EXPECT_EQ(getAllocType(HotTotalLifetimeAccessDensityThreshold + 1, AllocCount,
@@ -590,12 +593,13 @@ declare dso_local noalias noundef i8* @malloc(i64 noundef)
ASSERT_NE(Call, nullptr);
// Specify that all non-cold contexts should be kept.
+ bool OrigMemProfKeepAllNotColdContexts = MemProfKeepAllNotColdContexts;
MemProfKeepAllNotColdContexts = true;
Trie.buildAndAttachMIBMetadata(Call);
- // Undo the manual set of the MemProfKeepAllNotColdContexts above.
- cl::ResetAllOptionOccurrences();
+ // Restore original option value.
+ MemProfKeepAllNotColdContexts = OrigMemProfKeepAllNotColdContexts;
EXPECT_FALSE(Call->hasFnAttr("memprof"));
EXPECT_TRUE(Call->hasMetadata(LLVMContext::MD_memprof));