[llvm] [MemorySanitizer] Use getelementptr instead of ptrtoint+add+inttoptr (PR #161392)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 1 01:18:05 PDT 2025


================
@@ -1923,20 +1923,20 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
   ///
   /// Shadow = ParamTLS+ArgOffset.
   Value *getShadowPtrForArgument(IRBuilder<> &IRB, int ArgOffset) {
-    Value *Base = IRB.CreatePointerCast(MS.ParamTLS, MS.IntptrTy);
-    if (ArgOffset)
-      Base = IRB.CreateAdd(Base, ConstantInt::get(MS.IntptrTy, ArgOffset));
-    return IRB.CreateIntToPtr(Base, IRB.getPtrTy(0), "_msarg");
+    if (ArgOffset == 0)
+      return MS.ParamTLS;
+    return IRB.CreatePtrAdd(MS.ParamTLS,
+                            ConstantInt::get(MS.IntptrTy, ArgOffset));
   }
 
   /// Compute the origin address for a given function argument.
   Value *getOriginPtrForArgument(IRBuilder<> &IRB, int ArgOffset) {
     if (!MS.TrackOrigins)
       return nullptr;
-    Value *Base = IRB.CreatePointerCast(MS.ParamOriginTLS, MS.IntptrTy);
-    if (ArgOffset)
-      Base = IRB.CreateAdd(Base, ConstantInt::get(MS.IntptrTy, ArgOffset));
-    return IRB.CreateIntToPtr(Base, IRB.getPtrTy(0), "_msarg_o");
+    if (ArgOffset == 0)
+      return MS.ParamOriginTLS;
+    return IRB.CreatePtrAdd(MS.ParamOriginTLS,
+                            ConstantInt::get(MS.IntptrTy, ArgOffset));
----------------
nikic wrote:

I've dropped it. It's not entirely redundant in that for kmsan the result here is not a constant expression and thus the gep 0 will not be immediately folded. This was also the case in the previous implementation though, and only affects a small number of tests, so the check is not really worthwhile.

https://github.com/llvm/llvm-project/pull/161392


More information about the llvm-commits mailing list