[llvm] af22478 - [NFC] [MTE] [HWASan] simply code.

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 8 16:36:27 PST 2022


Author: Florian Mayer
Date: 2022-03-08T16:36:10-08:00
New Revision: af2247893320ac601d807a71aef41c09d7d85b9a

URL: https://github.com/llvm/llvm-project/commit/af2247893320ac601d807a71aef41c09d7d85b9a
DIFF: https://github.com/llvm/llvm-project/commit/af2247893320ac601d807a71aef41c09d7d85b9a.diff

LOG: [NFC] [MTE] [HWASan] simply code.

Added: 
    

Modified: 
    llvm/lib/Target/AArch64/AArch64StackTagging.cpp
    llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
index 4cb1db3ad75a7..854300853de71 100644
--- a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
+++ b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
@@ -552,13 +552,13 @@ bool AArch64StackTagging::runOnFunction(Function &Fn) {
     bool StandardLifetime =
         SInfo.UnrecognizedLifetimes.empty() &&
         memtag::isStandardLifetime(Info.LifetimeStart, Info.LifetimeEnd, DT,
-                                   ClMaxLifetimes);
+                                   ClMaxLifetimes) &&
+        !SInfo.CallsReturnTwice;
     // Calls to functions that may return twice (e.g. setjmp) confuse the
     // postdominator analysis, and will leave us to keep memory tagged after
     // function return. Work around this by always untagging at every return
     // statement if return_twice functions are called.
-    if (SInfo.UnrecognizedLifetimes.empty() && StandardLifetime &&
-        !SInfo.CallsReturnTwice) {
+    if (StandardLifetime) {
       IntrinsicInst *Start = Info.LifetimeStart[0];
       uint64_t Size =
           cast<ConstantInt>(Start->getArgOperand(0))->getZExtValue();

diff  --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 2b9e8655e4c93..26167e0ba8c58 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -295,8 +295,7 @@ class HWAddressSanitizer {
   void tagAlloca(IRBuilder<> &IRB, AllocaInst *AI, Value *Tag, size_t Size);
   Value *tagPointer(IRBuilder<> &IRB, Type *Ty, Value *PtrLong, Value *Tag);
   Value *untagPointer(IRBuilder<> &IRB, Value *PtrLong);
-  bool instrumentStack(bool ShouldDetectUseAfterScope, memtag::StackInfo &Info,
-                       Value *StackTag,
+  bool instrumentStack(memtag::StackInfo &Info, Value *StackTag,
                        llvm::function_ref<const DominatorTree &()> GetDT,
                        llvm::function_ref<const PostDominatorTree &()> GetPDT);
   Value *readRegister(IRBuilder<> &IRB, StringRef Name);
@@ -1307,7 +1306,7 @@ bool HWAddressSanitizer::instrumentLandingPads(
 }
 
 bool HWAddressSanitizer::instrumentStack(
-    bool ShouldDetectUseAfterScope, memtag::StackInfo &SInfo, Value *StackTag,
+    memtag::StackInfo &SInfo, Value *StackTag,
     llvm::function_ref<const DominatorTree &()> GetDT,
     llvm::function_ref<const PostDominatorTree &()> GetPDT) {
   // Ideally, we want to calculate tagged stack base pointer, and rewrite all
@@ -1356,8 +1355,9 @@ bool HWAddressSanitizer::instrumentStack(
     bool StandardLifetime =
         SInfo.UnrecognizedLifetimes.empty() &&
         memtag::isStandardLifetime(Info.LifetimeStart, Info.LifetimeEnd,
-                                   &GetDT(), ClMaxLifetimes);
-    if (ShouldDetectUseAfterScope && StandardLifetime) {
+                                   &GetDT(), ClMaxLifetimes) &&
+        !SInfo.CallsReturnTwice;
+    if (DetectUseAfterScope && StandardLifetime) {
       IntrinsicInst *Start = Info.LifetimeStart[0];
       IRB.SetInsertPoint(Start->getNextNode());
       tagAlloca(IRB, AI, Tag, Size);
@@ -1472,8 +1472,7 @@ bool HWAddressSanitizer::sanitizeFunction(
     // postdominator analysis, and will leave us to keep memory tagged after
     // function return. Work around this by always untagging at every return
     // statement if return_twice functions are called.
-    instrumentStack(DetectUseAfterScope && !SInfo.CallsReturnTwice, SIB.get(),
-                    StackTag, GetDT, GetPDT);
+    instrumentStack(SInfo, StackTag, GetDT, GetPDT);
   }
 
   // If we split the entry block, move any allocas that were originally in the


        


More information about the llvm-commits mailing list