From 76d12299b5333d71bfc079614031f97c97aa5148 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 18 Apr 2002 19:55:25 +0000 Subject: [PATCH] Make sure that there is no case where a signal can occur leaving a partially written output file. This is important because crashing testcases often write part of a file out, and the testing harness decides the file is up-to-date next time the test is run. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2303 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/as/as.cpp | 4 ++++ tools/dis/dis.cpp | 5 +++++ tools/gccas/gccas.cpp | 4 ++++ tools/gccld/gccld.cpp | 4 ++++ tools/link/link.cpp | 5 +++++ tools/llc/llc.cpp | 8 ++++++++ tools/llvm-as/as.cpp | 4 ++++ tools/llvm-as/llvm-as.cpp | 4 ++++ tools/llvm-dis/dis.cpp | 5 +++++ tools/llvm-dis/llvm-dis.cpp | 5 +++++ tools/llvm-link/llvm-link.cpp | 5 +++++ tools/opt/opt.cpp | 5 +++++ 12 files changed, 58 insertions(+) diff --git a/tools/as/as.cpp b/tools/as/as.cpp index 7bea711826e..3e8a9eaf31a 100644 --- a/tools/as/as.cpp +++ b/tools/as/as.cpp @@ -13,6 +13,7 @@ #include "llvm/Assembly/Parser.h" #include "llvm/Bytecode/Writer.h" #include "Support/CommandLine.h" +#include "Support/Signals.h" #include #include #include @@ -70,6 +71,9 @@ int main(int argc, char **argv) { } Out = new std::ofstream(OutputFilename.c_str()); + // Make sure that the Out file gets unlink'd from the disk if we get a + // SIGINT + RemoveFileOnSignal(OutputFilename); } } diff --git a/tools/dis/dis.cpp b/tools/dis/dis.cpp index a317cb316d5..e14dcdc9a79 100644 --- a/tools/dis/dis.cpp +++ b/tools/dis/dis.cpp @@ -23,6 +23,7 @@ #include "Support/DepthFirstIterator.h" #include "Support/PostOrderIterator.h" #include "Support/CommandLine.h" +#include "Support/Signals.h" #include #include using std::cerr; @@ -85,6 +86,10 @@ int main(int argc, char **argv) { << "': File exists! Sending to standard output.\n"; } else { Out = new std::ofstream(OutputFilename.c_str()); + + // Make sure that the Out file gets unlink'd from the disk if we get a + // SIGINT + RemoveFileOnSignal(OutputFilename); } } } diff --git a/tools/gccas/gccas.cpp b/tools/gccas/gccas.cpp index 1bf1e8c0b7b..02d7cfe827f 100644 --- a/tools/gccas/gccas.cpp +++ b/tools/gccas/gccas.cpp @@ -20,6 +20,7 @@ #include "llvm/Transforms/Scalar/PromoteMemoryToRegister.h" #include "llvm/Bytecode/WriteBytecodePass.h" #include "Support/CommandLine.h" +#include "Support/Signals.h" #include #include #include @@ -64,6 +65,9 @@ int main(int argc, char **argv) { return 1; } + // Make sure that the Out file gets unlink'd from the disk if we get a SIGINT + RemoveFileOnSignal(OutputFilename); + // In addition to just parsing the input from GCC, we also want to spiff it up // a little bit. Do this now. // diff --git a/tools/gccld/gccld.cpp b/tools/gccld/gccld.cpp index 11595f7d22c..1e16aa10063 100644 --- a/tools/gccld/gccld.cpp +++ b/tools/gccld/gccld.cpp @@ -24,6 +24,7 @@ #include "llvm/Transforms/ConstantMerge.h" #include "llvm/Transforms/IPO/GlobalDCE.h" #include "Support/CommandLine.h" +#include "Support/Signals.h" #include #include #include @@ -161,6 +162,9 @@ int main(int argc, char **argv) { } Passes.add(new WriteBytecodePass(&Out)); // Write bytecode to file... + // Make sure that the Out file gets unlink'd from the disk if we get a SIGINT + RemoveFileOnSignal(OutputFilename+".bc"); + // Run our queue of passes all at once now, efficiently. Passes.run(Composite.get()); Out.close(); diff --git a/tools/link/link.cpp b/tools/link/link.cpp index c4be6715cff..6cb30a2bd4e 100644 --- a/tools/link/link.cpp +++ b/tools/link/link.cpp @@ -14,6 +14,7 @@ #include "llvm/Bytecode/Writer.h" #include "llvm/Module.h" #include "Support/CommandLine.h" +#include "Support/Signals.h" #include #include #include // For FileExists @@ -126,6 +127,10 @@ int main(int argc, char **argv) { cerr << "Error opening '" << OutputFilename << "'!\n"; return 1; } + + // Make sure that the Out file gets unlink'd from the disk if we get a + // SIGINT + RemoveFileOnSignal(OutputFilename); } if (Verbose) cerr << "Writing bytecode...\n"; diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 32a06dd291e..b365c3900d8 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -18,6 +18,7 @@ #include "llvm/Function.h" #include "llvm/PassManager.h" #include "Support/CommandLine.h" +#include "Support/Signals.h" #include #include #include @@ -141,6 +142,10 @@ int main(int argc, char **argv) { return 1; } Out = new std::ofstream(OutputFilename.c_str()); + + // Make sure that the Out file gets unlink'd from the disk if we get a + // SIGINT + RemoveFileOnSignal(OutputFilename); } else { if (InputFilename == "-") { OutputFilename = "-"; @@ -162,6 +167,9 @@ int main(int argc, char **argv) { delete Out; return 1; } + // Make sure that the Out file gets unlink'd from the disk if we get a + // SIGINT + RemoveFileOnSignal(OutputFilename); } } diff --git a/tools/llvm-as/as.cpp b/tools/llvm-as/as.cpp index 7bea711826e..3e8a9eaf31a 100644 --- a/tools/llvm-as/as.cpp +++ b/tools/llvm-as/as.cpp @@ -13,6 +13,7 @@ #include "llvm/Assembly/Parser.h" #include "llvm/Bytecode/Writer.h" #include "Support/CommandLine.h" +#include "Support/Signals.h" #include #include #include @@ -70,6 +71,9 @@ int main(int argc, char **argv) { } Out = new std::ofstream(OutputFilename.c_str()); + // Make sure that the Out file gets unlink'd from the disk if we get a + // SIGINT + RemoveFileOnSignal(OutputFilename); } } diff --git a/tools/llvm-as/llvm-as.cpp b/tools/llvm-as/llvm-as.cpp index 7bea711826e..3e8a9eaf31a 100644 --- a/tools/llvm-as/llvm-as.cpp +++ b/tools/llvm-as/llvm-as.cpp @@ -13,6 +13,7 @@ #include "llvm/Assembly/Parser.h" #include "llvm/Bytecode/Writer.h" #include "Support/CommandLine.h" +#include "Support/Signals.h" #include #include #include @@ -70,6 +71,9 @@ int main(int argc, char **argv) { } Out = new std::ofstream(OutputFilename.c_str()); + // Make sure that the Out file gets unlink'd from the disk if we get a + // SIGINT + RemoveFileOnSignal(OutputFilename); } } diff --git a/tools/llvm-dis/dis.cpp b/tools/llvm-dis/dis.cpp index a317cb316d5..e14dcdc9a79 100644 --- a/tools/llvm-dis/dis.cpp +++ b/tools/llvm-dis/dis.cpp @@ -23,6 +23,7 @@ #include "Support/DepthFirstIterator.h" #include "Support/PostOrderIterator.h" #include "Support/CommandLine.h" +#include "Support/Signals.h" #include #include using std::cerr; @@ -85,6 +86,10 @@ int main(int argc, char **argv) { << "': File exists! Sending to standard output.\n"; } else { Out = new std::ofstream(OutputFilename.c_str()); + + // Make sure that the Out file gets unlink'd from the disk if we get a + // SIGINT + RemoveFileOnSignal(OutputFilename); } } } diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp index a317cb316d5..e14dcdc9a79 100644 --- a/tools/llvm-dis/llvm-dis.cpp +++ b/tools/llvm-dis/llvm-dis.cpp @@ -23,6 +23,7 @@ #include "Support/DepthFirstIterator.h" #include "Support/PostOrderIterator.h" #include "Support/CommandLine.h" +#include "Support/Signals.h" #include #include using std::cerr; @@ -85,6 +86,10 @@ int main(int argc, char **argv) { << "': File exists! Sending to standard output.\n"; } else { Out = new std::ofstream(OutputFilename.c_str()); + + // Make sure that the Out file gets unlink'd from the disk if we get a + // SIGINT + RemoveFileOnSignal(OutputFilename); } } } diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index c4be6715cff..6cb30a2bd4e 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -14,6 +14,7 @@ #include "llvm/Bytecode/Writer.h" #include "llvm/Module.h" #include "Support/CommandLine.h" +#include "Support/Signals.h" #include #include #include // For FileExists @@ -126,6 +127,10 @@ int main(int argc, char **argv) { cerr << "Error opening '" << OutputFilename << "'!\n"; return 1; } + + // Make sure that the Out file gets unlink'd from the disk if we get a + // SIGINT + RemoveFileOnSignal(OutputFilename); } if (Verbose) cerr << "Writing bytecode...\n"; diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index f922dd82ccb..f08567a6b89 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -31,6 +31,7 @@ #include "llvm/Transforms/Instrumentation/TraceValues.h" #include "llvm/Transforms/Instrumentation/ProfilePaths.h" #include "Support/CommandLine.h" +#include "Support/Signals.h" #include #include @@ -174,6 +175,10 @@ int main(int argc, char **argv) { cerr << "Error opening " << OutputFilename << "!\n"; return 1; } + + // Make sure that the Output file gets unlink'd from the disk if we get a + // SIGINT + RemoveFileOnSignal(OutputFilename); } // Create a PassManager to hold and optimize the collection of passes we are -- 2.34.1