Skip to content

Commit d89ca59

Browse files
authored
[libclc] Several little QOL improvements to libclc-remangler (#13073)
----- [libclc] Update deprecated method use in remangler llvm::StringRef::startswith -> llvm::StringRef::starts_with ----- [libclc] Fix up improper use of ExitOnError ExitOnError takes a llvm::Expected, but we were passing it the result of llvm::parseIR - std::unique_ptr<llvm::Module> - which, even when null, is not an error condition. Thus invalid IR input was silently being accepted until it would segfault on accessing the module. ----- [libclc] Open remangler file system at PWD, not root I don't think there's any reason to open it at root. Opening it at the current working directory is more intuitive for developers using relative paths for input/output files. Previously "--input-ir foo.ll" would try and open "/foo.ll", which depending on the system is likely a permissions error, or a missing file, or even an unintended file. -----
1 parent 2b0ec33 commit d89ca59

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

libclc/utils/libclc-remangler/LibclcRemangler.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -777,12 +777,17 @@ class LibCLCRemangler : public ASTConsumer {
777777

778778
void Initialize(ASTContext &C) override {
779779
ASTCtx = &C;
780-
SMDiagnostic Err;
781780
std::unique_ptr<MemoryBuffer> const Buff = ExitOnErr(
782781
errorOrToExpected(MemoryBuffer::getFileOrSTDIN(InputIRFilename)));
782+
783+
SMDiagnostic Err;
783784
std::unique_ptr<llvm::Module> const M =
784-
ExitOnErr(Expected<std::unique_ptr<llvm::Module>>(
785-
parseIR(Buff.get()->getMemBufferRef(), Err, LLVMCtx)));
785+
parseIR(Buff.get()->getMemBufferRef(), Err, LLVMCtx);
786+
787+
if (!M) {
788+
Err.print("libclc-remangler", errs());
789+
exit(1);
790+
}
786791

787792
handleModule(M.get());
788793
}
@@ -840,7 +845,7 @@ class LibCLCRemangler : public ASTConsumer {
840845
}
841846

842847
bool remangleFunction(Function &Func, llvm::Module *M) {
843-
if (!Func.getName().startswith("_Z"))
848+
if (!Func.getName().starts_with("_Z"))
844849
return true;
845850

846851
std::string const MangledName = Func.getName().str();
@@ -958,7 +963,7 @@ int main(int argc, const char **argv) {
958963

959964
// Use a default Compilation DB instead of the build one, as it might contain
960965
// toolchain specific options, not compatible with clang.
961-
FixedCompilationDatabase Compilations("/", std::vector<std::string>());
966+
FixedCompilationDatabase Compilations(".", std::vector<std::string>());
962967
ClangTool Tool(Compilations, ExpectedParser->getSourcePathList());
963968

964969
LibCLCRemanglerActionFactory LRAF{};

0 commit comments

Comments
 (0)