From a6e023c4491a8a8116c11783f4e81c7bd172f88d Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 8 Jul 2011 20:17:28 +0000 Subject: [PATCH] Fix up dependency file name printing to more closely match that of gcc, including fixing a nasty recent regression that could make us print "/foo.h" with a command-line including "-I ./". rdar://problem/9734352 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134728 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/DependencyFile.cpp | 16 +++++++++++----- lib/Lex/HeaderSearch.cpp | 6 ++---- test/Frontend/dependency-gen.c | 34 ++++++++++++++++++++------------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/lib/Frontend/DependencyFile.cpp b/lib/Frontend/DependencyFile.cpp index 5c3a23128a..dde3454aba 100644 --- a/lib/Frontend/DependencyFile.cpp +++ b/lib/Frontend/DependencyFile.cpp @@ -20,6 +20,7 @@ #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/StringSet.h" +#include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" using namespace clang; @@ -103,13 +104,18 @@ void DependencyFileCallback::FileChanged(SourceLocation Loc, SM.getFileEntryForID(SM.getFileID(SM.getInstantiationLoc(Loc))); if (FE == 0) return; - const char *Filename = FE->getName(); - if (!FileMatchesDepCriteria(Filename, FileType)) + llvm::StringRef Filename = FE->getName(); + if (!FileMatchesDepCriteria(Filename.data(), FileType)) return; - // Remove leading "./" - if (Filename[0] == '.' && Filename[1] == '/') - Filename = &Filename[2]; + // Remove leading "./" (or ".//" or "././" etc.) + while (Filename.size() > 2 && Filename[0] == '.' && + llvm::sys::path::is_separator(Filename[1])) { + Filename = Filename.substr(1); + while (llvm::sys::path::is_separator(Filename[0])) + Filename = Filename.substr(1); + } + if (FilesSet.insert(Filename)) Files.push_back(Filename); diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index bb4388195a..86ab9564a2 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -123,10 +123,8 @@ const FileEntry *DirectoryLookup::LookupFile( llvm::SmallString<1024> TmpDir; if (isNormalDir()) { // Concatenate the requested file onto the directory. - // FIXME: Portability. Filename concatenation should be in sys::Path. - TmpDir += getDir()->getName(); - TmpDir.push_back('/'); - TmpDir.append(Filename.begin(), Filename.end()); + TmpDir = getDir()->getName(); + llvm::sys::path::append(TmpDir, Filename); if (SearchPath != NULL) { llvm::StringRef SearchPathRef(getDir()->getName()); SearchPath->clear(); diff --git a/test/Frontend/dependency-gen.c b/test/Frontend/dependency-gen.c index 0f8adabc85..49d3f28614 100644 --- a/test/Frontend/dependency-gen.c +++ b/test/Frontend/dependency-gen.c @@ -1,19 +1,27 @@ -// rdar://6533411 -// RUN: %clang -MD -MF %t.d -S -x c -o %t.o %s -// RUN: grep '.*dependency-gen.*:' %t.d -// RUN: grep 'dependency-gen.c' %t.d - -// RUN: %clang -S -M -x c %s -o %t.d -// RUN: grep '.*dependency-gen.*:' %t.d -// RUN: grep 'dependency-gen.c' %t.d - -// PR8974 // REQUIRES: shell -// "cd %t.dir" requires shell. +// Basic test // RUN: rm -rf %t.dir // RUN: mkdir -p %t.dir/a/b // RUN: echo > %t.dir/a/b/x.h // RUN: cd %t.dir -// RUN: %clang -include a/b/x.h -MD -MF %t.d -S -x c -o %t.o %s -// RUN: grep ' a/b/x\.h' %t.d +// RUN: %clang -MD -MF - %s -fsyntax-only -I a/b | FileCheck -check-prefix=CHECK-ONE %s +// CHECK-ONE: {{ }}a/b/x.h + +// PR8974 (-include flag) +// RUN: %clang -MD -MF - %s -fsyntax-only -include a/b/x.h -DINCLUDE_FLAG_TEST | FileCheck -check-prefix=CHECK-TWO %s +// CHECK-TWO: {{ }}a/b/x.h + +// rdar://problem/9734352 (paths involving ".") +// RUN: %clang -MD -MF - %s -fsyntax-only -I ./a/b | FileCheck -check-prefix=CHECK-THREE %s +// CHECK-THREE: {{ }}a/b/x.h +// RUN: %clang -MD -MF - %s -fsyntax-only -I .//./a/b/ | FileCheck -check-prefix=CHECK-FOUR %s +// CHECK-FOUR: {{ }}a/b/x.h +// RUN: %clang -MD -MF - %s -fsyntax-only -I a/b/. | FileCheck -check-prefix=CHECK-FIVE %s +// CHECK-FIVE: {{ }}a/b/./x.h +// RUN: cd a/b +// RUN: %clang -MD -MF - %s -fsyntax-only -I ./ | FileCheck -check-prefix=CHECK-SIX %s +// CHECK-SIX: {{ }}x.h +#ifndef INCLUDE_FLAG_TEST +#include +#endif -- 2.40.0