@@ -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
ClRandomSkipRate.getNumOccurrences () ? M.createRNG (" hwasan" ) : nullptr ;
305
304
@@ -625,19 +624,14 @@ void HWAddressSanitizer::initializeModule() {
625
624
bool NewRuntime =
626
625
!TargetTriple.isAndroid () || !TargetTriple.isAndroidVersionLT (30 );
627
626
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);
634
631
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 ()));
641
635
642
636
if (ClMatchAllTag.getNumOccurrences ()) {
643
637
if (ClMatchAllTag != -1 ) {
@@ -649,22 +643,17 @@ void HWAddressSanitizer::initializeModule() {
649
643
UseMatchAllCallback = !CompileKernel && MatchAllTag.has_value ();
650
644
651
645
// 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);
655
647
656
648
if (!CompileKernel) {
657
649
createHwasanCtorComdat ();
658
- bool InstrumentGlobals =
659
- ClGlobals.getNumOccurrences () ? ClGlobals : NewRuntime;
650
+ bool InstrumentGlobals = optOr (ClGlobals, NewRuntime);
660
651
661
652
if (InstrumentGlobals && !UsePageAliases)
662
653
instrumentGlobals ();
663
654
664
655
bool InstrumentPersonalityFunctions =
665
- ClInstrumentPersonalityFunctions.getNumOccurrences ()
666
- ? ClInstrumentPersonalityFunctions
667
- : NewRuntime;
656
+ optOr (ClInstrumentPersonalityFunctions, NewRuntime);
668
657
if (InstrumentPersonalityFunctions)
669
658
instrumentPersonalityFunctions ();
670
659
}
0 commit comments