[llvm] r318361 - Convert a use of createUniqueFile to TempFile::create.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 22 11:17:50 PST 2017
Sorry about that, I am taking a look.
Michael Kruse <llvm-commits at meinersbur.de> writes:
> Hi,
>
> this seems to break bugpoint on at least Windows. When 'opt' crashes,
> bugpoint crashes as well.
>
> Unhandled exception at 0x0FB5CAB6 (ucrtbased.dll) in bugpoint.exe: An
> invalid parameter was passed to a function that considers invalid
> parameters fatal.
>
> Stack trace:
>
> ucrtbased.dll!_close(int fh) Line 49
> bugpoint.exe!llvm::sys::fs::TempFile::discard() Line 782
> bugpoint.exe!llvm::DiscardTemp::~DiscardTemp() Line 41
> bugpoint.exe!llvm::BugDriver::runPasses(llvm::Module * Program,
> const std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>>,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>> > > & Passes,
> std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
> OutputFilename, bool DeleteOutput, bool Quiet, unsigned int
> NumExtraArgs, const char * const * ExtraArgs) Line 274
> bugpoint.exe!llvm::BugDriver::runPasses(llvm::Module * M, const
> std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>>,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char>
>> > > & PassesToRun) Line 257
> bugpoint.exe!llvm::BugDriver::run() Line 175
> bugpoint.exe!main(int argc, char * * argv) Line 215
> bugpoint.exe!invoke_main() Line 78
>
> The line crashing Path.cpp:782 is
>
> if (FD != -1 && close(FD) == -1) {
>
> Due to Windows LLVM not support the -load mechanism, the unit testing
> for bugpoint are not active on windows.
>
> I assume this is due OptimizationDriver.cpp:256
>
> // Remove the temporary input file as well
> consumeError(Temp->discard());
>
> with DiscardTemp, the temp file therefore is discarded twice. It works
> for me if I comment-out one of them. Apparently, the MS (debug-)CRT
> has in-built assertions that fast-fails (int 3 breakpoint; which ends
> the program if no debugger is attached) if close() is called on the
> same file descriptor multiple times.
>
> Michael
>
>
>
> 2017-11-16 2:06 GMT+01:00 Rafael Espindola via llvm-commits
> <llvm-commits at lists.llvm.org>:
>> Author: rafael
>> Date: Wed Nov 15 17:06:36 2017
>> New Revision: 318361
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=318361&view=rev
>> Log:
>> Convert a use of createUniqueFile to TempFile::create.
>>
>> Modified:
>> llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
>>
>> Modified: llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/OptimizerDriver.cpp?rev=318361&r1=318360&r2=318361&view=diff
>> ==============================================================================
>> --- llvm/trunk/tools/bugpoint/OptimizerDriver.cpp (original)
>> +++ llvm/trunk/tools/bugpoint/OptimizerDriver.cpp Wed Nov 15 17:06:36 2017
>> @@ -118,6 +118,11 @@ static cl::list<std::string> OptArgs("op
>> cl::desc("<opt arguments>..."),
>> cl::ZeroOrMore, cl::PositionalEatsArgs);
>>
>> +struct DiscardTemp {
>> + sys::fs::TempFile &File;
>> + ~DiscardTemp() { consumeError(File.discard()); }
>> +};
>> +
>> /// runPasses - Run the specified passes on Program, outputting a bitcode file
>> /// and writing the filename into OutputFile if successful. If the
>> /// optimizations fail for some reason (optimizer crashes), return true,
>> @@ -144,23 +149,22 @@ bool BugDriver::runPasses(Module *Progra
>> OutputFilename = UniqueFilename.str();
>>
>> // set up the input file name
>> - SmallString<128> InputFilename;
>> - int InputFD;
>> - EC = sys::fs::createUniqueFile(OutputPrefix + "-input-%%%%%%%.bc", InputFD,
>> - InputFilename);
>> - if (EC) {
>> + Expected<sys::fs::TempFile> Temp =
>> + sys::fs::TempFile::create(OutputPrefix + "-input-%%%%%%%.bc");
>> + if (!Temp) {
>> errs() << getToolName()
>> - << ": Error making unique filename: " << EC.message() << "\n";
>> + << ": Error making unique filename: " << toString(Temp.takeError())
>> + << "\n";
>> return 1;
>> }
>> + DiscardTemp Discard{*Temp};
>> + raw_fd_ostream OS(Temp->FD, /*shouldClose*/ false);
>>
>> - ToolOutputFile InFile(InputFilename, InputFD);
>> -
>> - WriteBitcodeToFile(Program, InFile.os(), PreserveBitcodeUseListOrder);
>> - InFile.os().close();
>> - if (InFile.os().has_error()) {
>> - errs() << "Error writing bitcode file: " << InputFilename << "\n";
>> - InFile.os().clear_error();
>> + WriteBitcodeToFile(Program, OS, PreserveBitcodeUseListOrder);
>> + OS.flush();
>> + if (OS.has_error()) {
>> + errs() << "Error writing bitcode file: " << Temp->TmpName << "\n";
>> + OS.clear_error();
>> return 1;
>> }
>>
>> @@ -189,9 +193,6 @@ bool BugDriver::runPasses(Module *Progra
>> return 1;
>> }
>>
>> - // Ok, everything that could go wrong before running opt is done.
>> - InFile.keep();
>> -
>> // setup the child process' arguments
>> SmallVector<const char *, 8> Args;
>> if (UseValgrind) {
>> @@ -220,7 +221,7 @@ bool BugDriver::runPasses(Module *Progra
>> E = pass_args.end();
>> I != E; ++I)
>> Args.push_back(I->c_str());
>> - Args.push_back(InputFilename.c_str());
>> + Args.push_back(Temp->TmpName.c_str());
>> for (unsigned i = 0; i < NumExtraArgs; ++i)
>> Args.push_back(*ExtraArgs);
>> Args.push_back(nullptr);
>> @@ -247,7 +248,7 @@ bool BugDriver::runPasses(Module *Progra
>> sys::fs::remove(OutputFilename);
>>
>> // Remove the temporary input file as well
>> - sys::fs::remove(InputFilename.c_str());
>> + consumeError(Temp->discard());
>>
>> if (!Quiet) {
>> if (result == 0)
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list