Skip to content

Commit e08da9b

Browse files
Copilotdamyanp
andcommitted
Replace exit() calls with exceptions in shared library code
In lib/Support/ErrorHandling.cpp, remove the #ifndef LLVM_ON_WIN32 guard so that report_fatal_error() and llvm_unreachable_internal() throw hlsl::Exception on all platforms instead of calling exit(1)/abort() on non-Windows. In lib/Support/CommandLine.cpp, replace exit() calls with report_fatal_error() which now throws an exception on all platforms. Co-authored-by: damyanp <[email protected]>
1 parent 300421e commit e08da9b

2 files changed

Lines changed: 6 additions & 32 deletions

File tree

lib/Support/CommandLine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ void CommandLineParser::ParseCommandLineOptions(int argc,
11111111

11121112
// If we had an error processing our arguments, don't let the program execute
11131113
if (ErrorParsing)
1114-
exit(1);
1114+
report_fatal_error("Error in command-line option processing"); // HLSL Change - don't exit() in shared library
11151115
}
11161116

11171117
//===----------------------------------------------------------------------===//
@@ -1547,7 +1547,7 @@ class HelpPrinter {
15471547
GlobalParser->MoreHelp.clear();
15481548

15491549
// Halt the program since help information was printed
1550-
exit(0);
1550+
report_fatal_error("Help information was printed"); // HLSL Change - don't exit() in shared library
15511551
}
15521552
};
15531553

@@ -1798,7 +1798,7 @@ class VersionPrinter {
17981798

17991799
if (OverrideVersionPrinter != nullptr) {
18001800
(*OverrideVersionPrinter)();
1801-
exit(0);
1801+
report_fatal_error("Version information was printed"); // HLSL Change - don't exit() in shared library
18021802
}
18031803
print();
18041804

@@ -1812,7 +1812,7 @@ class VersionPrinter {
18121812
(*I)();
18131813
}
18141814

1815-
exit(0);
1815+
report_fatal_error("Version information was printed"); // HLSL Change - don't exit() in shared library
18161816
}
18171817
};
18181818
} // End anonymous namespace

lib/Support/ErrorHandling.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,12 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) {
8888
handlerData = ErrorHandlerUserData;
8989
}
9090

91-
#ifndef LLVM_ON_WIN32 // HLSL Change - unwind if necessary, but don't terminate the process
92-
if (handler) {
93-
handler(handlerData, Reason.str(), GenCrashDiag);
94-
} else {
95-
// Blast the result out to stderr. We don't try hard to make sure this
96-
// succeeds (e.g. handling EINTR) and we can't use errs() here because
97-
// raw ostreams can call report_fatal_error.
98-
SmallVector<char, 64> Buffer;
99-
raw_svector_ostream OS(Buffer);
100-
OS << "LLVM ERROR: " << Reason << "\n";
101-
StringRef MessageStr = OS.str();
102-
ssize_t written = ::write(2, MessageStr.data(), MessageStr.size());
103-
(void)written; // If something went wrong, we deliberately just give up.
104-
}
105-
106-
// If we reached here, we are failing ungracefully. Run the interrupt handlers
107-
// to make sure any special cleanups get done, in particular that we remove
108-
// files registered with RemoveFileOnSignal.
109-
sys::RunInterruptHandlers();
110-
111-
exit(1);
112-
#else
91+
// HLSL Change - unwind if necessary, but don't terminate the process
11392
if (handler) {
11493
handler(handlerData, Reason.str(), GenCrashDiag);
11594
}
11695

11796
throw hlsl::Exception(DXC_E_LLVM_FATAL_ERROR, std::string("LLVM ERROR: ") + Reason.str() + "\n");
118-
#endif
11997
}
12098

12199
void llvm::llvm_unreachable_internal(const char *msg, const char *file,
@@ -132,12 +110,8 @@ void llvm::llvm_unreachable_internal(const char *msg, const char *file,
132110
if (file)
133111
OS << " at " << file << ":" << line;
134112
OS << "!\n";
135-
#ifndef LLVM_ON_WIN32 // HLSL Change - unwind if necessary, but don't terminate the process
136-
dbgs() << OS.str();
137-
abort();
138-
#else
113+
// HLSL Change - unwind if necessary, but don't terminate the process
139114
throw hlsl::Exception(DXC_E_LLVM_UNREACHABLE, OS.str());
140-
#endif
141115
}
142116

143117
void llvm::llvm_cast_assert_internal(const char *func) {

0 commit comments

Comments
 (0)