[PATCH] D126270: [InstCombine] Preserve !nosanitize for newly created instructions.

Mingjie Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 23 21:58:36 PDT 2022


Enna1 created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Enna1 edited the summary of this revision.
Enna1 added reviewers: fhahn, nikic, vitalybuka, dvyukov.
Enna1 added a subscriber: MTC.
Enna1 published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

If the source instruction has !nosanitize metadata, all instructions created during combining should also have it.

The !nosanitize metadata indicates that LLVM should not insert any sanitizer instrumentation.

This https://github.com/google/sanitizers/issues/1508 false positive is caused:

1. InstCombine do not preserve !nosanitize for newly created instructions if source instruction has !nosanitize metadata and
2. ASan instruments for pointer comparison and subtraction instruction even if it has !nosanitize metadata

This patch and D126269 <https://reviews.llvm.org/D126269> together will fix the false positive.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126270

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp


Index: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -4192,7 +4192,8 @@
     // Now that we have an instruction, try combining it to simplify it.
     Builder.SetInsertPoint(I);
     Builder.CollectMetadataToCopy(
-        I, {LLVMContext::MD_dbg, LLVMContext::MD_annotation});
+        I, {LLVMContext::MD_dbg, LLVMContext::MD_annotation,
+            I->getModule()->getMDKindID("nosanitize")});
 
 #ifndef NDEBUG
     std::string OrigI;
@@ -4208,7 +4209,8 @@
                           << "    New = " << *Result << '\n');
 
         Result->copyMetadata(*I,
-                             {LLVMContext::MD_dbg, LLVMContext::MD_annotation});
+                             {LLVMContext::MD_dbg, LLVMContext::MD_annotation,
+                              I->getModule()->getMDKindID("nosanitize")});
         // Everything uses the new instruction now.
         I->replaceAllUsesWith(Result);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126270.431580.patch
Type: text/x-patch
Size: 1099 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220524/65075cfe/attachment.bin>


More information about the llvm-commits mailing list