[AbstractCallSite] Check that callback callee index is within call arguments
authorSergey Dmitriev <serguei.n.dmitriev@intel.com>
Tue, 14 Apr 2020 16:12:34 +0000 (09:12 -0700)
committerSergey Dmitriev <serguei.n.dmitriev@intel.com>
Tue, 14 Apr 2020 16:24:00 +0000 (09:24 -0700)
Summary:
AbstractCallSite::getCallbackUses() does not check that callback callee index from
the callback metadata does not exceed the total number of call arguments. This patch
add such validation check.

Reviewers: jdoerfert, sstefan1

Reviewed By: jdoerfert

Subscribers: hiraditya, arphaman, llvm-commits

Tags: #llvm

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

llvm/lib/IR/AbstractCallSite.cpp
llvm/test/Transforms/OpenMP/rtf_type_checking.ll

index 19b3566..e415c48 100644 (file)
@@ -48,7 +48,8 @@ void AbstractCallSite::getCallbackUses(ImmutableCallSite ICS,
     auto *CBCalleeIdxAsCM = cast<ConstantAsMetadata>(OpMD->getOperand(0));
     uint64_t CBCalleeIdx =
         cast<ConstantInt>(CBCalleeIdxAsCM->getValue())->getZExtValue();
-    CBUses.push_back(ICS.arg_begin() + CBCalleeIdx);
+    if (CBCalleeIdx < ICS.arg_size())
+      CBUses.push_back(ICS.arg_begin() + CBCalleeIdx);
   }
 }
 
index 57c09bc..6c392e7 100644 (file)
@@ -1,4 +1,5 @@
 ; RUN: opt -S -openmpopt -stats < %s 2>&1 | FileCheck %s
+; RUN: opt -S -attributor -attributor-disable=false -openmpopt -stats < %s 2>&1 | FileCheck %s
 ; REQUIRES: asserts
 
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"