@@ -260,6 +260,10 @@ static cl::opt<bool> ClUsePageAliases("hwasan-experimental-use-page-aliases",
260
260
261
261
namespace {
262
262
263
+ template <typename T> T optOr (cl::opt<T> &Opt, T Other) {
264
+ return Opt.getNumOccurrences () ? Opt : Other;
265
+ }
266
+
263
267
bool shouldUsePageAliases (const Triple &TargetTriple) {
264
268
return ClUsePageAliases && TargetTriple.getArch () == Triple::x86_64;
265
269
}
@@ -269,14 +273,11 @@ bool shouldInstrumentStack(const Triple &TargetTriple) {
269
273
}
270
274
271
275
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);
275
277
}
276
278
277
279
bool mightUseStackSafetyAnalysis (bool DisableOptimization) {
278
- return ClUseStackSafety.getNumOccurrences () ? ClUseStackSafety
279
- : !DisableOptimization;
280
+ return optOr (ClUseStackSafety, !DisableOptimization);
280
281
}
281
282
282
283
bool shouldUseStackSafetyAnalysis (const Triple &TargetTriple,
@@ -296,10 +297,8 @@ class HWAddressSanitizer {
296
297
HWAddressSanitizer (Module &M, bool CompileKernel, bool Recover,
297
298
const StackSafetyGlobalInfo *SSI)
298
299
: 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);
303
302
this ->Rng =
304
303
RandomSkipRate.getNumOccurrences () ? M.createRNG (" hwasan" ) : nullptr ;
305
304
@@ -624,19 +623,14 @@ void HWAddressSanitizer::initializeModule() {
624
623
bool NewRuntime =
625
624
!TargetTriple.isAndroid () || !TargetTriple.isAndroidVersionLT (30 );
626
625
627
- UseShortGranules =
628
- ClUseShortGranules.getNumOccurrences () ? ClUseShortGranules : NewRuntime;
629
- OutlinedChecks =
630
- (TargetTriple.isAArch64 () || TargetTriple.isRISCV64 ()) &&
631
- TargetTriple.isOSBinFormatELF () &&
632
- (ClInlineAllChecks.getNumOccurrences () ? !ClInlineAllChecks : !Recover);
626
+ UseShortGranules = optOr (ClUseShortGranules, NewRuntime);
627
+ OutlinedChecks = (TargetTriple.isAArch64 () || TargetTriple.isRISCV64 ()) &&
628
+ TargetTriple.isOSBinFormatELF () &&
629
+ !optOr (ClInlineAllChecks, Recover);
633
630
634
- InlineFastPath =
635
- (ClInlineFastPathChecks.getNumOccurrences ()
636
- ? ClInlineFastPathChecks
637
- : !(TargetTriple.isAndroid () ||
638
- TargetTriple.isOSFuchsia ())); // These platforms may prefer less
639
- // inlining to reduce binary size.
631
+ // These platforms may prefer less inlining to reduce binary size.
632
+ InlineFastPath = optOr (ClInlineFastPathChecks, !(TargetTriple.isAndroid () ||
633
+ TargetTriple.isOSFuchsia ()));
640
634
641
635
if (ClMatchAllTag.getNumOccurrences ()) {
642
636
if (ClMatchAllTag != -1 ) {
@@ -648,22 +642,17 @@ void HWAddressSanitizer::initializeModule() {
648
642
UseMatchAllCallback = !CompileKernel && MatchAllTag.has_value ();
649
643
650
644
// If we don't have personality function support, fall back to landing pads.
651
- InstrumentLandingPads = ClInstrumentLandingPads.getNumOccurrences ()
652
- ? ClInstrumentLandingPads
653
- : !NewRuntime;
645
+ InstrumentLandingPads = optOr (ClInstrumentLandingPads, !NewRuntime);
654
646
655
647
if (!CompileKernel) {
656
648
createHwasanCtorComdat ();
657
- bool InstrumentGlobals =
658
- ClGlobals.getNumOccurrences () ? ClGlobals : NewRuntime;
649
+ bool InstrumentGlobals = optOr (ClGlobals, NewRuntime);
659
650
660
651
if (InstrumentGlobals && !UsePageAliases)
661
652
instrumentGlobals ();
662
653
663
654
bool InstrumentPersonalityFunctions =
664
- ClInstrumentPersonalityFunctions.getNumOccurrences ()
665
- ? ClInstrumentPersonalityFunctions
666
- : NewRuntime;
655
+ optOr (ClInstrumentPersonalityFunctions, NewRuntime);
667
656
if (InstrumentPersonalityFunctions)
668
657
instrumentPersonalityFunctions ();
669
658
}
0 commit comments