diff --git a/llvm/test/Reduce/remove-args-2.ll b/llvm/test/Reduce/remove-args-2.ll new file mode 100644 --- /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 --- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp @@ -81,10 +81,9 @@ 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