aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2019-10-28 10:35:56 -0400
committerNico Weber <nicolasweber@gmx.de>2019-10-28 10:38:32 -0400
commitb911d2db5dd85b7b69b4529fc581b3e95dba488c (patch)
treee9e1a3f197f71358374d8895449de7d670d89b3e
parentf5e1b718a675a4449b71423f04d38e1e93045105 (diff)
downloadllvm-b911d2db5dd85b7b69b4529fc581b3e95dba488c.zip
llvm-b911d2db5dd85b7b69b4529fc581b3e95dba488c.tar.gz
llvm-b911d2db5dd85b7b69b4529fc581b3e95dba488c.tar.bz2
lld/COFF: Simplify getOutputPath() using sys::path functions.
Also mention "basename" and "dirname" in Path.h since I tried to find these functions by looking for these strings. It might help others find them faster if the comments contain these strings. No behavior change. Differential Revision: https://reviews.llvm.org/D69458
-rw-r--r--lld/COFF/Driver.cpp5
-rw-r--r--llvm/include/llvm/Support/Path.h4
2 files changed, 4 insertions, 5 deletions
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 30967a3..9f43d8c 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -104,10 +104,7 @@ static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
// Drop directory components and replace extension with ".exe" or ".dll".
static std::string getOutputPath(StringRef path) {
- auto p = path.find_last_of("\\/");
- StringRef s = (p == StringRef::npos) ? path : path.substr(p + 1);
- const char* e = config->dll ? ".dll" : ".exe";
- return (s.substr(0, s.rfind('.')) + e).str();
+ return (sys::path::stem(path) + (config->dll ? ".dll" : ".exe")).str();
}
// Returns true if S matches /crtend.?\.o$/.
diff --git a/llvm/include/llvm/Support/Path.h b/llvm/include/llvm/Support/Path.h
index 5c0bee5..4514761 100644
--- a/llvm/include/llvm/Support/Path.h
+++ b/llvm/include/llvm/Support/Path.h
@@ -121,6 +121,8 @@ reverse_iterator rend(StringRef path);
/// Remove the last component from \a path unless it is the root dir.
///
+/// Similar to the POSIX "dirname" utility.
+///
/// @code
/// directory/filename.cpp => directory/
/// directory/ => directory
@@ -295,7 +297,7 @@ StringRef parent_path(StringRef path, Style style = Style::native);
///
/// @param path Input path.
/// @result The filename part of \a path. This is defined as the last component
-/// of \a path.
+/// of \a path. Similar to the POSIX "basename" utility.
StringRef filename(StringRef path, Style style = Style::native);
/// Get stem.