[PATCH] D104663: [OpaquePtr] Remove checking pointee type for byval/preallocated type

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 21 12:26:10 PDT 2021


aeubanks created this revision.
aeubanks added a reviewer: dblaikie.
Herald added subscribers: dexonsmith, jdoerfert.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

These currently always require a type parameter. The bitcode reader
already upgrades old bitcode without the type parameter to use the
pointee type.

In (arguably incorrect IR) cases where the caller does not have byval
but the callee does, we need to follow CallBase::paramHasAttr() and also
look at the callee for the byval type so that
CallBase::isByValArgument() and CallBase::getParamByValType() are in
sync.

Don't worry about preallocated since it's still not really in use, and
is much more involved in setting up, making the chance of a mismatch
very small.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104663

Files:
  llvm/include/llvm/IR/InstrTypes.h
  llvm/unittests/IR/AttributesTest.cpp


Index: llvm/unittests/IR/AttributesTest.cpp
===================================================================
--- llvm/unittests/IR/AttributesTest.cpp
+++ llvm/unittests/IR/AttributesTest.cpp
@@ -7,8 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/IR/Attributes.h"
-#include "llvm/IR/LLVMContext.h"
+#include "llvm/AsmParser/Parser.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/SourceMgr.h"
 #include "gtest/gtest.h"
 using namespace llvm;
 
@@ -252,4 +256,24 @@
   }
 }
 
+TEST(Attributes, MismatchedByval) {
+  const char *IRString = R"IR(
+    declare void @f(i32* byval(i32))
+    define void @g() {
+      call void @f(i32* null)
+      ret void
+    }
+  )IR";
+
+  SMDiagnostic Err;
+  LLVMContext Context;
+  std::unique_ptr<Module> M = parseAssemblyString(IRString, Err, Context);
+  ASSERT_TRUE(M);
+
+  auto *G = M->getFunction("g");
+  ASSERT_TRUE(G);
+  auto *I = cast<CallBase>(&G->getEntryBlock().front());
+  ASSERT_TRUE(I->getParamByValType(0));
+}
+
 } // end anonymous namespace
Index: llvm/include/llvm/IR/InstrTypes.h
===================================================================
--- llvm/include/llvm/IR/InstrTypes.h
+++ llvm/include/llvm/IR/InstrTypes.h
@@ -1729,13 +1729,15 @@
   /// Extract the byval type for a call or parameter.
   Type *getParamByValType(unsigned ArgNo) const {
     Type *Ty = Attrs.getParamByValType(ArgNo);
-    return Ty ? Ty : getArgOperand(ArgNo)->getType()->getPointerElementType();
+    if (const Function *F = getCalledFunction())
+      return F->getAttributes().getParamByValType(ArgNo);
+    return Ty;
   }
 
   /// Extract the preallocated type for a call or parameter.
   Type *getParamPreallocatedType(unsigned ArgNo) const {
     Type *Ty = Attrs.getParamPreallocatedType(ArgNo);
-    return Ty ? Ty : getArgOperand(ArgNo)->getType()->getPointerElementType();
+    return Ty;
   }
 
   /// Extract the number of dereferenceable bytes for a call or


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104663.353452.patch
Type: text/x-patch
Size: 2091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210621/88dd4e5d/attachment.bin>


More information about the llvm-commits mailing list