This revision was automatically updated to reflect the committed changes. Closed by commit rGe4e6c6510b18: [IR] Adds Instruction::setNoSanitizeMetadata() (authored by Enna1).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D150632/new/ https://reviews.llvm.org/D150632 Files: clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/CodeGen/SanitizerMetadata.cpp clang/lib/CodeGen/SanitizerMetadata.h llvm/include/llvm/IR/Instruction.h llvm/lib/IR/Metadata.cpp llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -248,10 +248,6 @@ std::pair<Value *, Value *> CreateSecStartEnd(Module &M, const char *Section, Type *Ty); - void SetNoSanitizeMetadata(Instruction *I) { - I->setMetadata(LLVMContext::MD_nosanitize, MDNode::get(*C, std::nullopt)); - } - std::string getSectionName(const std::string &Section) const; std::string getSectionStart(const std::string &Section) const; std::string getSectionEnd(const std::string &Section) const; @@ -992,8 +988,8 @@ auto Load = IRB.CreateLoad(Int8Ty, CounterPtr); auto Inc = IRB.CreateAdd(Load, ConstantInt::get(Int8Ty, 1)); auto Store = IRB.CreateStore(Inc, CounterPtr); - SetNoSanitizeMetadata(Load); - SetNoSanitizeMetadata(Store); + Load->setNoSanitizeMetadata(); + Store->setNoSanitizeMetadata(); } if (Options.InlineBoolFlag) { auto FlagPtr = IRB.CreateGEP( @@ -1004,8 +1000,8 @@ SplitBlockAndInsertIfThen(IRB.CreateIsNull(Load), &*IP, false); IRBuilder<> ThenIRB(ThenTerm); auto Store = ThenIRB.CreateStore(ConstantInt::getTrue(Int1Ty), FlagPtr); - SetNoSanitizeMetadata(Load); - SetNoSanitizeMetadata(Store); + Load->setNoSanitizeMetadata(); + Store->setNoSanitizeMetadata(); } if (Options.StackDepth && IsEntryBB && !IsLeafFunc) { // Check stack depth. If it's the deepest so far, record it. @@ -1021,8 +1017,8 @@ auto ThenTerm = SplitBlockAndInsertIfThen(IsStackLower, &*IP, false); IRBuilder<> ThenIRB(ThenTerm); auto Store = ThenIRB.CreateStore(FrameAddrInt, SanCovLowestStack); - SetNoSanitizeMetadata(LowestStack); - SetNoSanitizeMetadata(Store); + LowestStack->setNoSanitizeMetadata(); + Store->setNoSanitizeMetadata(); } } Index: llvm/lib/IR/Metadata.cpp =================================================================== --- llvm/lib/IR/Metadata.cpp +++ llvm/lib/IR/Metadata.cpp @@ -1612,6 +1612,11 @@ setMetadata(LLVMContext::MD_noalias, N.NoAlias); } +void Instruction::setNoSanitizeMetadata() { + setMetadata(llvm::LLVMContext::MD_nosanitize, + llvm::MDNode::get(getContext(), std::nullopt)); +} + MDNode *Instruction::getMetadataImpl(unsigned KindID) const { // Handle 'dbg' as a special case since it is not stored in the hash table. if (KindID == LLVMContext::MD_dbg) Index: llvm/include/llvm/IR/Instruction.h =================================================================== --- llvm/include/llvm/IR/Instruction.h +++ llvm/include/llvm/IR/Instruction.h @@ -350,6 +350,9 @@ /// Sets the AA metadata on this instruction from the AAMDNodes structure. void setAAMetadata(const AAMDNodes &N); + /// Sets the nosanitize metadata on this instruction. + void setNoSanitizeMetadata(); + /// Retrieve total raw weight values of a branch. /// Returns true on success with profile total weights filled in. /// Returns false if no metadata was found. Index: clang/lib/CodeGen/SanitizerMetadata.h =================================================================== --- clang/lib/CodeGen/SanitizerMetadata.h +++ clang/lib/CodeGen/SanitizerMetadata.h @@ -44,7 +44,6 @@ SanitizerMask NoSanitizeAttrMask = {}, bool IsDynInit = false); void disableSanitizerForGlobal(llvm::GlobalVariable *GV); - void disableSanitizerForInstruction(llvm::Instruction *I); }; } // end namespace CodeGen } // end namespace clang Index: clang/lib/CodeGen/SanitizerMetadata.cpp =================================================================== --- clang/lib/CodeGen/SanitizerMetadata.cpp +++ clang/lib/CodeGen/SanitizerMetadata.cpp @@ -101,8 +101,3 @@ void SanitizerMetadata::disableSanitizerForGlobal(llvm::GlobalVariable *GV) { reportGlobal(GV, SourceLocation(), "", QualType(), SanitizerKind::All); } - -void SanitizerMetadata::disableSanitizerForInstruction(llvm::Instruction *I) { - I->setMetadata(llvm::LLVMContext::MD_nosanitize, - llvm::MDNode::get(CGM.getLLVMContext(), std::nullopt)); -} Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -2189,7 +2189,7 @@ (expr->getOperatorNew()->isReplaceableGlobalAllocationFunction() || CGM.getCodeGenOpts().SanitizeAddressPoisonCustomArrayCookie)) { // The store to the CookiePtr does not need to be instrumented. - CGM.getSanitizerMetadata()->disableSanitizerForInstruction(SI); + SI->setNoSanitizeMetadata(); llvm::FunctionType *FTy = llvm::FunctionType::get(CGM.VoidTy, NumElementsPtr.getType(), false); llvm::FunctionCallee F = Index: clang/lib/CodeGen/CodeGenFunction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenFunction.cpp +++ clang/lib/CodeGen/CodeGenFunction.cpp @@ -2541,7 +2541,7 @@ llvm::BasicBlock::iterator InsertPt) const { LoopStack.InsertHelper(I); if (IsSanitizerScope) - CGM.getSanitizerMetadata()->disableSanitizerForInstruction(I); + I->setNoSanitizeMetadata(); } void CGBuilderInserter::InsertHelper(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits