From 32986cdb1c2db32f7d26057e99097c50e5678de6 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Wed, 12 Feb 2014 11:42:02 +0000 Subject: [PATCH] clang/lib/Driver/Multilib.cpp: Rewrite normalizePathSegment() to be tolerant dosish pathsep. FIXME: It could be more simple... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201227 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Multilib.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/Driver/Multilib.cpp b/lib/Driver/Multilib.cpp index 746d01bfb2..6681e7f364 100644 --- a/lib/Driver/Multilib.cpp +++ b/lib/Driver/Multilib.cpp @@ -29,15 +29,30 @@ using namespace clang::driver; using namespace clang; using namespace llvm::opt; +using namespace llvm::sys; +/// normalize Segment to "/foo/bar" or "". static void normalizePathSegment(std::string &Segment) { - if (Segment.empty() || Segment == "/." || Segment == "/" || Segment == ".") { + StringRef seg = Segment; + + // Prune trailing "/" or "./" + while (1) { + StringRef last = *--path::end(seg); + if (last != ".") + break; + seg = path::parent_path(seg); + } + + if (seg.empty() || seg == "/") { Segment = ""; + return; + } + + // Add leading '/' + if (seg.front() != '/') { + Segment = "/" + seg.str(); } else { - if (StringRef(Segment).back() == '/') - Segment.erase(Segment.begin() + Segment.size() - 1); - if (StringRef(Segment).front() != '/') - Segment = "/" + Segment; + Segment = seg; } } -- 2.40.0