From c1a9dd9aea498dd78d6583f29f15a690ddd5466a Mon Sep 17 00:00:00 2001 From: Sergey Dmitriev Date: Tue, 14 Apr 2020 09:12:34 -0700 Subject: [PATCH] [AbstractCallSite] Check that callback callee index is within call arguments 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 | 3 ++- llvm/test/Transforms/OpenMP/rtf_type_checking.ll | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/lib/IR/AbstractCallSite.cpp b/llvm/lib/IR/AbstractCallSite.cpp index 19b3566..e415c48 100644 --- a/llvm/lib/IR/AbstractCallSite.cpp +++ b/llvm/lib/IR/AbstractCallSite.cpp @@ -48,7 +48,8 @@ void AbstractCallSite::getCallbackUses(ImmutableCallSite ICS, auto *CBCalleeIdxAsCM = cast(OpMD->getOperand(0)); uint64_t CBCalleeIdx = cast(CBCalleeIdxAsCM->getValue())->getZExtValue(); - CBUses.push_back(ICS.arg_begin() + CBCalleeIdx); + if (CBCalleeIdx < ICS.arg_size()) + CBUses.push_back(ICS.arg_begin() + CBCalleeIdx); } } diff --git a/llvm/test/Transforms/OpenMP/rtf_type_checking.ll b/llvm/test/Transforms/OpenMP/rtf_type_checking.ll index 57c09bc..6c392e7 100644 --- a/llvm/test/Transforms/OpenMP/rtf_type_checking.ll +++ b/llvm/test/Transforms/OpenMP/rtf_type_checking.ll @@ -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" -- 2.7.4