Skip to content

Commit f361777

Browse files
committed
[NFC] use Optional instead of separate bool
1 parent 854c10f commit f361777

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
1515
#include "llvm/ADT/MapVector.h"
16+
#include "llvm/ADT/Optional.h"
1617
#include "llvm/ADT/STLExtras.h"
1718
#include "llvm/ADT/SmallVector.h"
1819
#include "llvm/ADT/StringExtras.h"
@@ -387,8 +388,7 @@ class HWAddressSanitizer {
387388
bool DetectUseAfterScope;
388389
bool UsePageAliases;
389390

390-
bool HasMatchAllTag = false;
391-
uint8_t MatchAllTag = 0;
391+
llvm::Optional<uint8_t> MatchAllTag;
392392

393393
unsigned PointerTagShift;
394394
uint64_t TagMaskByte;
@@ -589,11 +589,9 @@ void HWAddressSanitizer::initializeModule() {
589589

590590
if (ClMatchAllTag.getNumOccurrences()) {
591591
if (ClMatchAllTag != -1) {
592-
HasMatchAllTag = true;
593592
MatchAllTag = ClMatchAllTag & 0xFF;
594593
}
595594
} else if (CompileKernel) {
596-
HasMatchAllTag = true;
597595
MatchAllTag = 0xFF;
598596
}
599597

@@ -819,8 +817,8 @@ Value *HWAddressSanitizer::memToShadow(Value *Mem, IRBuilder<> &IRB) {
819817
int64_t HWAddressSanitizer::getAccessInfo(bool IsWrite,
820818
unsigned AccessSizeIndex) {
821819
return (CompileKernel << HWASanAccessInfo::CompileKernelShift) |
822-
(HasMatchAllTag << HWASanAccessInfo::HasMatchAllShift) |
823-
(MatchAllTag << HWASanAccessInfo::MatchAllShift) |
820+
(MatchAllTag.has_value() << HWASanAccessInfo::HasMatchAllShift) |
821+
(MatchAllTag.value_or(0) << HWASanAccessInfo::MatchAllShift) |
824822
(Recover << HWASanAccessInfo::RecoverShift) |
825823
(IsWrite << HWASanAccessInfo::IsWriteShift) |
826824
(AccessSizeIndex << HWASanAccessInfo::AccessSizeShift);
@@ -856,9 +854,9 @@ void HWAddressSanitizer::instrumentMemAccessInline(Value *Ptr, bool IsWrite,
856854
Value *MemTag = IRB.CreateLoad(Int8Ty, Shadow);
857855
Value *TagMismatch = IRB.CreateICmpNE(PtrTag, MemTag);
858856

859-
if (HasMatchAllTag) {
857+
if (MatchAllTag.has_value()) {
860858
Value *TagNotIgnored = IRB.CreateICmpNE(
861-
PtrTag, ConstantInt::get(PtrTag->getType(), MatchAllTag));
859+
PtrTag, ConstantInt::get(PtrTag->getType(), *MatchAllTag));
862860
TagMismatch = IRB.CreateAnd(TagMismatch, TagNotIgnored);
863861
}
864862

0 commit comments

Comments
 (0)