|
13 | 13 |
|
14 | 14 | #include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
|
15 | 15 | #include "llvm/ADT/MapVector.h"
|
| 16 | +#include "llvm/ADT/Optional.h" |
16 | 17 | #include "llvm/ADT/STLExtras.h"
|
17 | 18 | #include "llvm/ADT/SmallVector.h"
|
18 | 19 | #include "llvm/ADT/StringExtras.h"
|
@@ -387,8 +388,7 @@ class HWAddressSanitizer {
|
387 | 388 | bool DetectUseAfterScope;
|
388 | 389 | bool UsePageAliases;
|
389 | 390 |
|
390 |
| - bool HasMatchAllTag = false; |
391 |
| - uint8_t MatchAllTag = 0; |
| 391 | + llvm::Optional<uint8_t> MatchAllTag; |
392 | 392 |
|
393 | 393 | unsigned PointerTagShift;
|
394 | 394 | uint64_t TagMaskByte;
|
@@ -589,11 +589,9 @@ void HWAddressSanitizer::initializeModule() {
|
589 | 589 |
|
590 | 590 | if (ClMatchAllTag.getNumOccurrences()) {
|
591 | 591 | if (ClMatchAllTag != -1) {
|
592 |
| - HasMatchAllTag = true; |
593 | 592 | MatchAllTag = ClMatchAllTag & 0xFF;
|
594 | 593 | }
|
595 | 594 | } else if (CompileKernel) {
|
596 |
| - HasMatchAllTag = true; |
597 | 595 | MatchAllTag = 0xFF;
|
598 | 596 | }
|
599 | 597 |
|
@@ -819,8 +817,8 @@ Value *HWAddressSanitizer::memToShadow(Value *Mem, IRBuilder<> &IRB) {
|
819 | 817 | int64_t HWAddressSanitizer::getAccessInfo(bool IsWrite,
|
820 | 818 | unsigned AccessSizeIndex) {
|
821 | 819 | 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) | |
824 | 822 | (Recover << HWASanAccessInfo::RecoverShift) |
|
825 | 823 | (IsWrite << HWASanAccessInfo::IsWriteShift) |
|
826 | 824 | (AccessSizeIndex << HWASanAccessInfo::AccessSizeShift);
|
@@ -856,9 +854,9 @@ void HWAddressSanitizer::instrumentMemAccessInline(Value *Ptr, bool IsWrite,
|
856 | 854 | Value *MemTag = IRB.CreateLoad(Int8Ty, Shadow);
|
857 | 855 | Value *TagMismatch = IRB.CreateICmpNE(PtrTag, MemTag);
|
858 | 856 |
|
859 |
| - if (HasMatchAllTag) { |
| 857 | + if (MatchAllTag.has_value()) { |
860 | 858 | Value *TagNotIgnored = IRB.CreateICmpNE(
|
861 |
| - PtrTag, ConstantInt::get(PtrTag->getType(), MatchAllTag)); |
| 859 | + PtrTag, ConstantInt::get(PtrTag->getType(), *MatchAllTag)); |
862 | 860 | TagMismatch = IRB.CreateAnd(TagMismatch, TagNotIgnored);
|
863 | 861 | }
|
864 | 862 |
|
|
0 commit comments