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
This commit is contained in:
Eli Friedman 2011-07-08 20:17:28 +00:00
Родитель 82007c3a3f
Коммит a6e023c449
3 изменённых файлов: 34 добавлений и 22 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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();

Просмотреть файл

@ -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 <x.h>
#endif