Index: clang/lib/CodeGen/SanitizerMetadata.cpp =================================================================== --- clang/lib/CodeGen/SanitizerMetadata.cpp +++ clang/lib/CodeGen/SanitizerMetadata.cpp @@ -87,7 +87,7 @@ } void SanitizerMetadata::disableSanitizerForInstruction(llvm::Instruction *I) { - I->setMetadata(CGM.getModule().getMDKindID("nosanitize"), + I->setMetadata(llvm::LLVMContext::MD_nosanitize, llvm::MDNode::get(CGM.getLLVMContext(), None)); } Index: llvm/include/llvm/IR/FixedMetadataKinds.def =================================================================== --- llvm/include/llvm/IR/FixedMetadataKinds.def +++ llvm/include/llvm/IR/FixedMetadataKinds.def @@ -42,3 +42,4 @@ LLVM_FIXED_MD_KIND(MD_vcall_visibility, "vcall_visibility", 28) LLVM_FIXED_MD_KIND(MD_noundef, "noundef", 29) LLVM_FIXED_MD_KIND(MD_annotation, "annotation", 30) +LLVM_FIXED_MD_KIND(MD_nosanitize, "nosanitize", 31) Index: llvm/lib/Transforms/IPO/HotColdSplitting.cpp =================================================================== --- llvm/lib/Transforms/IPO/HotColdSplitting.cpp +++ llvm/lib/Transforms/IPO/HotColdSplitting.cpp @@ -113,7 +113,8 @@ // mark sanitizer traps as cold. for (Instruction &I : BB) if (auto *CB = dyn_cast(&I)) - if (CB->hasFnAttr(Attribute::Cold) && !CB->getMetadata("nosanitize")) + if (CB->hasFnAttr(Attribute::Cold) && + !CB->getMetadata(LLVMContext::MD_nosanitize)) return true; // The block is cold if it has an unreachable terminator, unless it's Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1331,7 +1331,7 @@ void AddressSanitizer::getInterestingMemoryOperands( Instruction *I, SmallVectorImpl &Interesting) { // Skip memory accesses inserted by another instrumentation. - if (I->hasMetadata("nosanitize")) + if (I->hasMetadata(LLVMContext::MD_nosanitize)) return; // Do not instrument the load fetching the dynamic shadow address. @@ -2771,7 +2771,8 @@ if (auto *CB = dyn_cast(&Inst)) { // A call inside BB. TempsToInstrument.clear(); - if (CB->doesNotReturn() && !CB->hasMetadata("nosanitize")) + if (CB->doesNotReturn() && + !CB->hasMetadata(LLVMContext::MD_nosanitize)) NoReturnCalls.push_back(CB); } if (CallInst *CI = dyn_cast(&Inst)) Index: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -715,7 +715,7 @@ void HWAddressSanitizer::getInterestingMemoryOperands( Instruction *I, SmallVectorImpl &Interesting) { // Skip memory accesses inserted by another instrumentation. - if (I->hasMetadata("nosanitize")) + if (I->hasMetadata(LLVMContext::MD_nosanitize)) return; // Do not instrument the load fetching the dynamic shadow address. Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1620,7 +1620,7 @@ /// or extracts if from ParamTLS (for function arguments). Value *getShadow(Value *V) { if (Instruction *I = dyn_cast(V)) { - if (!PropagateShadow || I->getMetadata("nosanitize")) + if (!PropagateShadow || I->getMetadata(LLVMContext::MD_nosanitize)) return getCleanShadow(V); // For instructions the shadow is already stored in the map. Value *Shadow = ShadowMap[V]; @@ -1739,7 +1739,7 @@ assert((isa(V) || isa(V)) && "Unexpected value type in getOrigin()"); if (Instruction *I = dyn_cast(V)) { - if (I->getMetadata("nosanitize")) + if (I->getMetadata(LLVMContext::MD_nosanitize)) return getCleanOrigin(); } Value *Origin = OriginMap[V]; @@ -1862,7 +1862,7 @@ // ------------------- Visitors. using InstVisitor::visit; void visit(Instruction &I) { - if (I.getMetadata("nosanitize")) + if (I.getMetadata(LLVMContext::MD_nosanitize)) return; // Don't want to visit if we're in the prologue if (isInPrologue(I)) @@ -1876,7 +1876,7 @@ /// Optionally, checks that the load address is fully defined. void visitLoadInst(LoadInst &I) { assert(I.getType()->isSized() && "Load type must have size"); - assert(!I.getMetadata("nosanitize")); + assert(!I.getMetadata(LLVMContext::MD_nosanitize)); IRBuilder<> IRB(I.getNextNode()); Type *ShadowTy = getShadowTy(&I); Value *Addr = I.getPointerOperand(); @@ -3591,7 +3591,7 @@ } void visitCallBase(CallBase &CB) { - assert(!CB.getMetadata("nosanitize")); + assert(!CB.getMetadata(LLVMContext::MD_nosanitize)); if (CB.isInlineAsm()) { // For inline asm (either a call to asm function, or callbr instruction), // do the usual thing: check argument shadow and mark all outputs as Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -241,8 +241,7 @@ Type *Ty); void SetNoSanitizeMetadata(Instruction *I) { - I->setMetadata(I->getModule()->getMDKindID("nosanitize"), - MDNode::get(*C, None)); + I->setMetadata(LLVMContext::MD_nosanitize, MDNode::get(*C, None)); } std::string getSectionName(const std::string &Section) const;