From 6187eeb683d8c639282d437e6af585e9b7f9c93e Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Sun, 19 Jul 2020 17:24:57 +0100 Subject: [PATCH] [llvm-reduce] Fix incorrect indices in argument reduction pass The function extractArgumentsFromModule() was passing a one-based index to, but replaceFunctionCalls() was expecting a zero-based argument index. This resulted in assertion errors when reducing function call arguments with different types. Additionally, the Reviewed By: lebedev.ri Differential Revision: https://reviews.llvm.org/D84099 --- llvm/test/Reduce/remove-args-2.ll | 20 ++++++++++++++++++++ llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp | 7 +++---- 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 llvm/test/Reduce/remove-args-2.ll diff --git a/llvm/test/Reduce/remove-args-2.ll b/llvm/test/Reduce/remove-args-2.ll new file mode 100644 index 00000000000..fddcfc75195 --- /dev/null +++ b/llvm/test/Reduce/remove-args-2.ll @@ -0,0 +1,20 @@ +; Test that llvm-reduce can remove uninteresting function arguments from function definitions as well as their calls. +; This test checks that functions with different argument types are handled correctly +; +; RUN: llvm-reduce --test %python --test-arg %p/Inputs/remove-args.py %s -o %t +; RUN: cat %t | FileCheck -implicit-check-not=uninteresting %s + +%struct.foo = type { %struct.foo*, i32, i32, i8* } + +define dso_local void @bar() { +entry: + ; CHECK: call void @interesting(%struct.foo* null) + call void @interesting(i32 0, i8* null, %struct.foo* null, i8* null, i64 0) + ret void +} + +; CHECK: define internal void @interesting(%struct.foo* %interesting) { +define internal void @interesting(i32 %uninteresting1, i8* %uninteresting2, %struct.foo* %interesting, i8* %uninteresting3, i64 %uninteresting4) { +entry: + ret void +} diff --git a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp index a119b40018b..88c3e326ff9 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp @@ -81,10 +81,9 @@ static void extractArgumentsFromModule(std::vector ChunksToKeep, continue; std::set ArgIndexesToKeep; - int ArgI = 0; - for (auto &Arg : F->args()) - if (ArgsToKeep.count(&Arg)) - ArgIndexesToKeep.insert(++ArgI); + for (auto &Arg : enumerate(F->args())) + if (ArgsToKeep.count(&Arg.value())) + ArgIndexesToKeep.insert(Arg.index()); auto *ClonedFunc = CloneFunction(F, VMap); // In order to preserve function order, we move Clone after old Function -- 2.11.0