[llvm] 3d5275f - Handle indirect calls in preallocated verification

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 30 14:39:16 PDT 2020


Author: Arthur Eubanks
Date: 2020-04-30T14:39:03-07:00
New Revision: 3d5275fc05d54a8f951e034bcb7bcd48b0e46eb8

URL: https://github.com/llvm/llvm-project/commit/3d5275fc05d54a8f951e034bcb7bcd48b0e46eb8
DIFF: https://github.com/llvm/llvm-project/commit/3d5275fc05d54a8f951e034bcb7bcd48b0e46eb8.diff

LOG: Handle indirect calls in preallocated verification

Summary: getCalledFunction() returns null for indirect function invocations.

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79203

Added: 
    

Modified: 
    llvm/lib/IR/Verifier.cpp
    llvm/test/Verifier/preallocated-valid.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 77e005418dfa..df6b2bdc66c4 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -4485,7 +4485,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
       Assert(UseCall != nullptr,
              "Uses of llvm.call.preallocated.setup must be calls");
       const Function *Fn = UseCall->getCalledFunction();
-      if (Fn->getIntrinsicID() == Intrinsic::call_preallocated_arg) {
+      if (Fn && Fn->getIntrinsicID() == Intrinsic::call_preallocated_arg) {
         auto *AllocArgIndex = dyn_cast<ConstantInt>(UseCall->getArgOperand(1));
         Assert(AllocArgIndex != nullptr,
                "llvm.call.preallocated.alloc arg index must be a constant");
@@ -4500,8 +4500,8 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
                            "llvm.call.preallocated.setup");
         FoundCall = true;
         size_t NumPreallocatedArgs = 0;
-        for (auto &Arg : Fn->args()) {
-          if (Arg.hasAttribute(Attribute::Preallocated)) {
+        for (unsigned i = 0; i < UseCall->getNumArgOperands(); i++) {
+          if (UseCall->paramHasAttr(i, Attribute::Preallocated)) {
             ++NumPreallocatedArgs;
           }
         }

diff  --git a/llvm/test/Verifier/preallocated-valid.ll b/llvm/test/Verifier/preallocated-valid.ll
index a296acdef864..07f748ca8678 100644
--- a/llvm/test/Verifier/preallocated-valid.ll
+++ b/llvm/test/Verifier/preallocated-valid.ll
@@ -14,6 +14,14 @@ define void @preallocated() {
     ret void
 }
 
+define void @preallocated_indirect(void (i32*)* %f) {
+    %cs = call token @llvm.call.preallocated.setup(i32 1)
+    %x = call i8* @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32)
+    %y = bitcast i8* %x to i32*
+    call void %f(i32* preallocated(i32) %y) ["preallocated"(token %cs)]
+    ret void
+}
+
 define void @preallocated_setup_without_call() {
     %cs = call token @llvm.call.preallocated.setup(i32 1)
     %a0 = call i8* @llvm.call.preallocated.arg(token %cs, i32 0) preallocated(i32)


        


More information about the llvm-commits mailing list