diff --git a/llvm/test/BugPoint/func-attrs.ll b/llvm/test/BugPoint/func-attrs.ll index 8f742ee93d5f5..e471ff2ae14ca 100644 --- a/llvm/test/BugPoint/func-attrs.ll +++ b/llvm/test/BugPoint/func-attrs.ll @@ -1,11 +1,15 @@ ; RUN: bugpoint -load %llvmshlibdir/BugpointPasses%shlibext %s -output-prefix %t -bugpoint-crashfuncattr -silence-passes -; RUN: llvm-dis %t-reduced-simplified.bc -o - | FileCheck %s +; RUN: llvm-dis %t-reduced-simplified.bc -o - | FileCheck -check-prefixes=ALL,ENABLED %s +; RUN: bugpoint -disable-attribute-remove -load %llvmshlibdir/BugpointPasses%shlibext %s -output-prefix %t -bugpoint-crashfuncattr -silence-passes +; RUN: llvm-dis %t-reduced-simplified.bc -o - | FileCheck -check-prefixes=ALL,DISABLED %s + ; REQUIRES: plugins -; CHECK: f() #[[ATTRS:[0-9]+]] +; ALL: f() #[[ATTRS:[0-9]+]] define void @f() #0 { ret void } -; CHECK: attributes #[[ATTRS]] = { "bugpoint-crash" } -attributes #0 = { noinline "bugpoint-crash" "no-frame-pointer-elim-non-leaf" } +; ENABLED: attributes #[[ATTRS]] = { "bugpoint-crash" } +; DISABLED: attributes #[[ATTRS]] = { noinline "bugpoint-crash" "no-frame-pointer-elim-non-leaf" } +attributes #0 = { noinline "bugpoint-crash" "no-frame-pointer-elim-non-leaf" } \ No newline at end of file diff --git a/llvm/tools/bugpoint/CrashDebugger.cpp b/llvm/tools/bugpoint/CrashDebugger.cpp index 6e9563044365f..167b6a2ffc0f6 100644 --- a/llvm/tools/bugpoint/CrashDebugger.cpp +++ b/llvm/tools/bugpoint/CrashDebugger.cpp @@ -44,6 +44,10 @@ cl::opt NoGlobalRM("disable-global-remove", cl::desc("Do not remove global variables"), cl::init(false)); +cl::opt NoAttributeRM("disable-attribute-remove", + cl::desc("Do not remove function attributes"), + cl::init(false)); + cl::opt ReplaceFuncsWithNull( "replace-funcs-with-null", cl::desc("When stubbing functions, replace all uses will null"), @@ -1203,36 +1207,38 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { BD.EmitProgressBitcode(BD.getProgram(), "reduced-function"); } - // For each remaining function, try to reduce that function's attributes. - std::vector FunctionNames; - for (Function &F : BD.getProgram()) - FunctionNames.push_back(F.getName()); + if (!NoAttributeRM) { + // For each remaining function, try to reduce that function's attributes. + std::vector FunctionNames; + for (Function &F : BD.getProgram()) + FunctionNames.push_back(F.getName()); - if (!FunctionNames.empty() && !BugpointIsInterrupted) { - outs() << "\n*** Attempting to reduce the number of function attributes in " - "the testcase\n"; + if (!FunctionNames.empty() && !BugpointIsInterrupted) { + outs() << "\n*** Attempting to reduce the number of function attributes" + " in the testcase\n"; - unsigned OldSize = 0; - unsigned NewSize = 0; - for (std::string &Name : FunctionNames) { - Function *Fn = BD.getProgram().getFunction(Name); - assert(Fn && "Could not find funcion?"); + unsigned OldSize = 0; + unsigned NewSize = 0; + for (std::string &Name : FunctionNames) { + Function *Fn = BD.getProgram().getFunction(Name); + assert(Fn && "Could not find funcion?"); - std::vector Attrs; - for (Attribute A : Fn->getAttributes().getFnAttributes()) - Attrs.push_back(A); + std::vector Attrs; + for (Attribute A : Fn->getAttributes().getFnAttributes()) + Attrs.push_back(A); - OldSize += Attrs.size(); - Expected Result = + OldSize += Attrs.size(); + Expected Result = ReduceCrashingFunctionAttributes(BD, Name, TestFn).reduceList(Attrs); - if (Error E = Result.takeError()) - return E; + if (Error E = Result.takeError()) + return E; - NewSize += Attrs.size(); - } + NewSize += Attrs.size(); + } - if (OldSize < NewSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-function-attributes"); + if (OldSize < NewSize) + BD.EmitProgressBitcode(BD.getProgram(), "reduced-function-attributes"); + } } // Attempt to change conditional branches into unconditional branches to