Index: test/BugPoint/func-attrs.ll =================================================================== --- test/BugPoint/func-attrs.ll +++ 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 Index: tools/bugpoint/CrashDebugger.cpp =================================================================== --- tools/bugpoint/CrashDebugger.cpp +++ tools/bugpoint/CrashDebugger.cpp @@ -43,6 +43,10 @@ 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"), @@ -1115,36 +1119,38 @@ 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