Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: src/IceCompileServer.cpp

Issue 1382653002: Fix pnacl-sz to return with staus 0 in report_fatal_error. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceCompileServer.cpp - Compile server ------------------===// 1 //===- subzero/src/IceCompileServer.cpp - Compile server ------------------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 new llvm::raw_fd_ostream(Filename, EC, llvm::sys::fs::F_None)); 86 new llvm::raw_fd_ostream(Filename, EC, llvm::sys::fs::F_None));
87 } 87 }
88 } 88 }
89 89
90 ErrorCodes getReturnValue(const Ice::ClFlagsExtra &Flags, ErrorCodes Val) { 90 ErrorCodes getReturnValue(const Ice::ClFlagsExtra &Flags, ErrorCodes Val) {
91 if (Flags.getAlwaysExitSuccess()) 91 if (Flags.getAlwaysExitSuccess())
92 return EC_None; 92 return EC_None;
93 return Val; 93 return Val;
94 } 94 }
95 95
96 // Reports fatal error message, and then exits with success status 0.
97 void reportFatalErrorThenExitSuccess(void *UserData,
98 const std::string &Reason,
99 bool gen_crash_diag) {
Jim Stichnoth 2015/09/30 21:32:13 Should probably be GenCrashDiag or something. But
Karl 2015/09/30 22:02:21 Marking UserData and gen_crash_dag as unused. Surp
100 // Note: This code is (mostly) copied from llvm/lib/Support/ErrorHandling.cpp
101
102 // Blast the result out to stderr. We don't try hard to make sure this
103 // succeeds (e.g. handling EINTR) and we can't use errs() here because
104 // raw ostreams can call report_fatal_error.
105 llvm::SmallVector<char, 64> Buffer;
106 llvm::raw_svector_ostream OS(Buffer);
107 OS << "LLVM ERROR: " << Reason << "\n";
108 llvm::StringRef MessageStr = OS.str();
109 ssize_t written = ::write(2, MessageStr.data(), MessageStr.size());
110 (void)written; // If something went wrong, we deliberately just give up.
111
112 // If we reached here, we are failing ungracefully. Run the interrupt handlers
113 // to make sure any special cleanups get done, in particular that we remove
114 // files registered with RemoveFileOnSignal.
115 llvm::sys::RunInterruptHandlers();
116
117 exit(0);
118 }
119
96 } // end of anonymous namespace 120 } // end of anonymous namespace
97 121
98 void CLCompileServer::run() { 122 void CLCompileServer::run() {
99 if (BuildDefs::dump()) { 123 if (BuildDefs::dump()) {
100 llvm::sys::PrintStackTraceOnErrorSignal(); 124 llvm::sys::PrintStackTraceOnErrorSignal();
101 } 125 }
102 ClFlags::parseFlags(argc, argv); 126 ClFlags::parseFlags(argc, argv);
103 ClFlags Flags; 127 ClFlags Flags;
104 ClFlagsExtra ExtraFlags; 128 ClFlagsExtra ExtraFlags;
105 ClFlags::getParsedClFlags(Flags); 129 ClFlags::getParsedClFlags(Flags);
106 ClFlags::getParsedClFlagsExtra(ExtraFlags); 130 ClFlags::getParsedClFlagsExtra(ExtraFlags);
107 131
132 // Override report_fatal_error if we want to exit with 0 status.
133 if (ExtraFlags.getAlwaysExitSuccess())
134 llvm::install_fatal_error_handler(reportFatalErrorThenExitSuccess, this);
135
108 std::error_code EC; 136 std::error_code EC;
109 std::unique_ptr<Ostream> Ls = makeStream(ExtraFlags.getLogFilename(), EC); 137 std::unique_ptr<Ostream> Ls = makeStream(ExtraFlags.getLogFilename(), EC);
110 if (EC) { 138 if (EC) {
111 llvm::report_fatal_error("Unable to open log file"); 139 llvm::report_fatal_error("Unable to open log file");
112 } 140 }
113 Ls->SetUnbuffered(); 141 Ls->SetUnbuffered();
114 std::unique_ptr<Ostream> Os; 142 std::unique_ptr<Ostream> Os;
115 std::unique_ptr<ELFStreamer> ELFStr; 143 std::unique_ptr<ELFStreamer> ELFStr;
116 switch (Flags.getOutFileType()) { 144 switch (Flags.getOutFileType()) {
117 case FT_Elf: { 145 case FT_Elf: {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 }); 197 });
170 CompileThread.join(); 198 CompileThread.join();
171 } else { 199 } else {
172 getCompiler().run(ExtraFlags, *Ctx.get(), std::move(InputStream)); 200 getCompiler().run(ExtraFlags, *Ctx.get(), std::move(InputStream));
173 } 201 }
174 transferErrorCode(getReturnValue( 202 transferErrorCode(getReturnValue(
175 ExtraFlags, static_cast<ErrorCodes>(Ctx->getErrorStatus()->value()))); 203 ExtraFlags, static_cast<ErrorCodes>(Ctx->getErrorStatus()->value())));
176 } 204 }
177 205
178 } // end of namespace Ice 206 } // end of namespace Ice
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698