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

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: Fix nit. 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 GenCrashDag) {
100 (void)UserData;
101 (void)GenCrashDag;
102
103 // Note: This code is (mostly) copied from llvm/lib/Support/ErrorHandling.cpp
104
105 // Blast the result out to stderr. We don't try hard to make sure this
106 // succeeds (e.g. handling EINTR) and we can't use errs() here because
107 // raw ostreams can call report_fatal_error.
108 llvm::SmallVector<char, 64> Buffer;
109 llvm::raw_svector_ostream OS(Buffer);
110 OS << "LLVM ERROR: " << Reason << "\n";
111 llvm::StringRef MessageStr = OS.str();
112 ssize_t written = ::write(2, MessageStr.data(), MessageStr.size());
113 (void)written; // If something went wrong, we deliberately just give up.
114
115 // If we reached here, we are failing ungracefully. Run the interrupt handlers
116 // to make sure any special cleanups get done, in particular that we remove
117 // files registered with RemoveFileOnSignal.
118 llvm::sys::RunInterruptHandlers();
119
120 exit(0);
121 }
122
96 } // end of anonymous namespace 123 } // end of anonymous namespace
97 124
98 void CLCompileServer::run() { 125 void CLCompileServer::run() {
99 if (BuildDefs::dump()) { 126 if (BuildDefs::dump()) {
100 llvm::sys::PrintStackTraceOnErrorSignal(); 127 llvm::sys::PrintStackTraceOnErrorSignal();
101 } 128 }
102 ClFlags::parseFlags(argc, argv); 129 ClFlags::parseFlags(argc, argv);
103 ClFlags Flags; 130 ClFlags Flags;
104 ClFlagsExtra ExtraFlags; 131 ClFlagsExtra ExtraFlags;
105 ClFlags::getParsedClFlags(Flags); 132 ClFlags::getParsedClFlags(Flags);
106 ClFlags::getParsedClFlagsExtra(ExtraFlags); 133 ClFlags::getParsedClFlagsExtra(ExtraFlags);
107 134
135 // Override report_fatal_error if we want to exit with 0 status.
136 if (ExtraFlags.getAlwaysExitSuccess())
137 llvm::install_fatal_error_handler(reportFatalErrorThenExitSuccess, this);
138
108 std::error_code EC; 139 std::error_code EC;
109 std::unique_ptr<Ostream> Ls = makeStream(ExtraFlags.getLogFilename(), EC); 140 std::unique_ptr<Ostream> Ls = makeStream(ExtraFlags.getLogFilename(), EC);
110 if (EC) { 141 if (EC) {
111 llvm::report_fatal_error("Unable to open log file"); 142 llvm::report_fatal_error("Unable to open log file");
112 } 143 }
113 Ls->SetUnbuffered(); 144 Ls->SetUnbuffered();
114 std::unique_ptr<Ostream> Os; 145 std::unique_ptr<Ostream> Os;
115 std::unique_ptr<ELFStreamer> ELFStr; 146 std::unique_ptr<ELFStreamer> ELFStr;
116 switch (Flags.getOutFileType()) { 147 switch (Flags.getOutFileType()) {
117 case FT_Elf: { 148 case FT_Elf: {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 }); 200 });
170 CompileThread.join(); 201 CompileThread.join();
171 } else { 202 } else {
172 getCompiler().run(ExtraFlags, *Ctx.get(), std::move(InputStream)); 203 getCompiler().run(ExtraFlags, *Ctx.get(), std::move(InputStream));
173 } 204 }
174 transferErrorCode(getReturnValue( 205 transferErrorCode(getReturnValue(
175 ExtraFlags, static_cast<ErrorCodes>(Ctx->getErrorStatus()->value()))); 206 ExtraFlags, static_cast<ErrorCodes>(Ctx->getErrorStatus()->value())));
176 } 207 }
177 208
178 } // end of namespace Ice 209 } // 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