[cfe-commits] r134728 - in /cfe/trunk: lib/Frontend/DependencyFile.cpp lib/Lex/HeaderSearch.cpp test/Frontend/dependency-gen.c

Eli Friedman eli.friedman at gmail.com
Fri Jul 8 13:17:28 PDT 2011


Author: efriedma
Date: Fri Jul  8 15:17:28 2011
New Revision: 134728

URL: http://llvm.org/viewvc/llvm-project?rev=134728&view=rev
Log:
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


Modified:
    cfe/trunk/lib/Frontend/DependencyFile.cpp
    cfe/trunk/lib/Lex/HeaderSearch.cpp
    cfe/trunk/test/Frontend/dependency-gen.c

Modified: cfe/trunk/lib/Frontend/DependencyFile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DependencyFile.cpp?rev=134728&r1=134727&r2=134728&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/DependencyFile.cpp (original)
+++ cfe/trunk/lib/Frontend/DependencyFile.cpp Fri Jul  8 15:17:28 2011
@@ -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 @@
     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);

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=134728&r1=134727&r2=134728&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Fri Jul  8 15:17:28 2011
@@ -123,10 +123,8 @@
   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();

Modified: cfe/trunk/test/Frontend/dependency-gen.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/dependency-gen.c?rev=134728&r1=134727&r2=134728&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/dependency-gen.c (original)
+++ cfe/trunk/test/Frontend/dependency-gen.c Fri Jul  8 15:17:28 2011
@@ -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





More information about the cfe-commits mailing list