Skip to content

Commit 1e2f981

Browse files
author
git apple-llvm automerger
committed
Merge commit '0bb30f9896d9' from llvm.org/main into next
2 parents 689bfa3 + 0bb30f9 commit 1e2f981

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ static cl::opt<bool> ClUsePageAliases("hwasan-experimental-use-page-aliases",
260260

261261
namespace {
262262

263+
template <typename T> T optOr(cl::opt<T> &Opt, T Other) {
264+
return Opt.getNumOccurrences() ? Opt : Other;
265+
}
266+
263267
bool shouldUsePageAliases(const Triple &TargetTriple) {
264268
return ClUsePageAliases && TargetTriple.getArch() == Triple::x86_64;
265269
}
@@ -269,14 +273,11 @@ bool shouldInstrumentStack(const Triple &TargetTriple) {
269273
}
270274

271275
bool shouldInstrumentWithCalls(const Triple &TargetTriple) {
272-
return ClInstrumentWithCalls.getNumOccurrences()
273-
? ClInstrumentWithCalls
274-
: TargetTriple.getArch() == Triple::x86_64;
276+
return optOr(ClInstrumentWithCalls, TargetTriple.getArch() == Triple::x86_64);
275277
}
276278

277279
bool mightUseStackSafetyAnalysis(bool DisableOptimization) {
278-
return ClUseStackSafety.getNumOccurrences() ? ClUseStackSafety
279-
: !DisableOptimization;
280+
return optOr(ClUseStackSafety, !DisableOptimization);
280281
}
281282

282283
bool shouldUseStackSafetyAnalysis(const Triple &TargetTriple,
@@ -296,10 +297,8 @@ class HWAddressSanitizer {
296297
HWAddressSanitizer(Module &M, bool CompileKernel, bool Recover,
297298
const StackSafetyGlobalInfo *SSI)
298299
: M(M), SSI(SSI) {
299-
this->Recover = ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover;
300-
this->CompileKernel = ClEnableKhwasan.getNumOccurrences() > 0
301-
? ClEnableKhwasan
302-
: CompileKernel;
300+
this->Recover = optOr(ClRecover, Recover);
301+
this->CompileKernel = optOr(ClEnableKhwasan, CompileKernel);
303302
this->Rng =
304303
ClRandomSkipRate.getNumOccurrences() ? M.createRNG("hwasan") : nullptr;
305304

@@ -625,19 +624,14 @@ void HWAddressSanitizer::initializeModule() {
625624
bool NewRuntime =
626625
!TargetTriple.isAndroid() || !TargetTriple.isAndroidVersionLT(30);
627626

628-
UseShortGranules =
629-
ClUseShortGranules.getNumOccurrences() ? ClUseShortGranules : NewRuntime;
630-
OutlinedChecks =
631-
(TargetTriple.isAArch64() || TargetTriple.isRISCV64()) &&
632-
TargetTriple.isOSBinFormatELF() &&
633-
(ClInlineAllChecks.getNumOccurrences() ? !ClInlineAllChecks : !Recover);
627+
UseShortGranules = optOr(ClUseShortGranules, NewRuntime);
628+
OutlinedChecks = (TargetTriple.isAArch64() || TargetTriple.isRISCV64()) &&
629+
TargetTriple.isOSBinFormatELF() &&
630+
!optOr(ClInlineAllChecks, Recover);
634631

635-
InlineFastPath =
636-
(ClInlineFastPathChecks.getNumOccurrences()
637-
? ClInlineFastPathChecks
638-
: !(TargetTriple.isAndroid() ||
639-
TargetTriple.isOSFuchsia())); // These platforms may prefer less
640-
// inlining to reduce binary size.
632+
// These platforms may prefer less inlining to reduce binary size.
633+
InlineFastPath = optOr(ClInlineFastPathChecks, !(TargetTriple.isAndroid() ||
634+
TargetTriple.isOSFuchsia()));
641635

642636
if (ClMatchAllTag.getNumOccurrences()) {
643637
if (ClMatchAllTag != -1) {
@@ -649,22 +643,17 @@ void HWAddressSanitizer::initializeModule() {
649643
UseMatchAllCallback = !CompileKernel && MatchAllTag.has_value();
650644

651645
// If we don't have personality function support, fall back to landing pads.
652-
InstrumentLandingPads = ClInstrumentLandingPads.getNumOccurrences()
653-
? ClInstrumentLandingPads
654-
: !NewRuntime;
646+
InstrumentLandingPads = optOr(ClInstrumentLandingPads, !NewRuntime);
655647

656648
if (!CompileKernel) {
657649
createHwasanCtorComdat();
658-
bool InstrumentGlobals =
659-
ClGlobals.getNumOccurrences() ? ClGlobals : NewRuntime;
650+
bool InstrumentGlobals = optOr(ClGlobals, NewRuntime);
660651

661652
if (InstrumentGlobals && !UsePageAliases)
662653
instrumentGlobals();
663654

664655
bool InstrumentPersonalityFunctions =
665-
ClInstrumentPersonalityFunctions.getNumOccurrences()
666-
? ClInstrumentPersonalityFunctions
667-
: NewRuntime;
656+
optOr(ClInstrumentPersonalityFunctions, NewRuntime);
668657
if (InstrumentPersonalityFunctions)
669658
instrumentPersonalityFunctions();
670659
}

0 commit comments

Comments
 (0)