hans created this revision.
hans added reviewers: thakis, rsmith.
hans added a subscriber: cfe-commits.
It turns out several Chromium developers rely on this on Windows.
I'm not sure about the internal flag name. And do we want to expose this in
non-cl mode too?
https://reviews.llvm.org/D23816
Files:
include/clang/Basic/FileSystemOptions.h
include/clang/Driver/CC1Options.td
include/clang/Driver/CLCompatOptions.td
lib/Basic/FileManager.cpp
lib/Driver/Tools.cpp
lib/Frontend/CompilerInvocation.cpp
test/Driver/cl-options.c
test/Frontend/Inputs/absolute-paths.h
test/Frontend/absolute-paths.c
Index: test/Frontend/absolute-paths.c
===================================================================
--- /dev/null
+++ test/Frontend/absolute-paths.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | FileCheck -check-prefix=NORMAL -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fabsolute-paths %s 2>&1 | FileCheck -check-prefix=ABSOLUTE -check-prefix=CHECK %s
+
+#include "absolute-paths.h"
+
+// Check whether the diagnostic from the header above includes the dummy
+// directory in the path.
+
+// NORMAL: SystemHeaderPrefix
+// ABSOLUTE-NOT: SystemHeaderPrefix
+
+// CHECK: warning: control reaches end of non-void function
Index: test/Frontend/Inputs/absolute-paths.h
===================================================================
--- /dev/null
+++ test/Frontend/Inputs/absolute-paths.h
@@ -0,0 +1,3 @@
+int f() {
+ // Oops, no return.
+}
Index: test/Driver/cl-options.c
===================================================================
--- test/Driver/cl-options.c
+++ test/Driver/cl-options.c
@@ -32,6 +32,9 @@
// EP: "-P"
// EP: "-o" "-"
+// RUN: %clang_cl /FC -### -- %s 2>&1 | FileCheck -check-prefix=FC %s
+// FC: "-fabsolute-paths"
+
// RUN: %clang_cl /fp:fast /fp:except -### -- %s 2>&1 | FileCheck -check-prefix=fpexcept %s
// fpexcept-NOT: -menable-unsafe-fp-math
@@ -280,7 +283,6 @@
// RUN: /d2FastFail \
// RUN: /d2Zi+ \
// RUN: /errorReport:foo \
-// RUN: /FC \
// RUN: /Fdfoo \
// RUN: /FS \
// RUN: /Gd \
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1047,6 +1047,7 @@
static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args) {
Opts.WorkingDir = Args.getLastArgValue(OPT_working_directory);
+ Opts.AbsolutePaths = Args.hasArg(OPT_fabsolute_paths);
}
/// Parse the argument to the -ftest-module-file-extension
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6013,6 +6013,8 @@
A->claim();
}
+ Args.AddAllArgs(CmdArgs, options::OPT_fabsolute_paths);
+
// Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
// parser.
Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
Index: lib/Basic/FileManager.cpp
===================================================================
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -216,6 +216,14 @@
bool CacheFailure) {
++NumFileLookups;
+ SmallVector<char, 128> AbsoluteFilename(Filename.begin(), Filename.end());
+ if (FileSystemOpts.AbsolutePaths) {
+ makeAbsolutePath(AbsoluteFilename);
+ llvm::sys::path::remove_dots(AbsoluteFilename, true);
+ llvm::sys::path::native(AbsoluteFilename);
+ Filename = StringRef(AbsoluteFilename.data(), AbsoluteFilename.size());
+ }
+
// See if there is already an entry in the map.
auto &NamedFileEnt =
*SeenFileEntries.insert(std::make_pair(Filename, nullptr)).first;
Index: include/clang/Driver/CLCompatOptions.td
===================================================================
--- include/clang/Driver/CLCompatOptions.td
+++ include/clang/Driver/CLCompatOptions.td
@@ -64,6 +64,9 @@
def _SLASH_D : CLJoinedOrSeparate<"D">, HelpText<"Define macro">,
MetaVarName<"<macro[=value]>">, Alias<D>;
def _SLASH_E : CLFlag<"E">, HelpText<"Preprocess to stdout">, Alias<E>;
+def _SLASH_FC : CLFlag<"FC">,
+ HelpText<"Use absolute paths in diagnostics and __FILE__">,
+ Alias<fabsolute_paths>;
def _SLASH_fp_except : CLFlag<"fp:except">, HelpText<"">, Alias<ftrapping_math>;
def _SLASH_fp_except_ : CLFlag<"fp:except-">,
HelpText<"">, Alias<fno_trapping_math>;
@@ -292,7 +295,6 @@
def _SLASH_d2Zi_PLUS : CLIgnoredFlag<"d2Zi+">;
def _SLASH_errorReport : CLIgnoredJoined<"errorReport">;
def _SLASH_Fd : CLIgnoredJoined<"Fd">;
-def _SLASH_FC : CLIgnoredFlag<"FC">;
def _SLASH_FS : CLIgnoredFlag<"FS">, HelpText<"Force synchronous PDB writes">;
def _SLASH_GF : CLIgnoredFlag<"GF">;
def _SLASH_kernel_ : CLIgnoredFlag<"kernel-">;
Index: include/clang/Driver/CC1Options.td
===================================================================
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -653,6 +653,8 @@
"implicit extern \"C\" semantics; these are assumed to not be "
"user-provided and are used to model system and standard headers' "
"paths.">;
+def fabsolute_paths : Flag<["-"], "fabsolute-paths">,
+ HelpText<"Use absolute paths in diagnostics and __FILE__">;
//===----------------------------------------------------------------------===//
// Preprocessor Options
Index: include/clang/Basic/FileSystemOptions.h
===================================================================
--- include/clang/Basic/FileSystemOptions.h
+++ include/clang/Basic/FileSystemOptions.h
@@ -25,6 +25,9 @@
/// \brief If set, paths are resolved as if the working directory was
/// set to the value of WorkingDir.
std::string WorkingDir;
+
+ /// If set, store the absolute path to files.
+ bool AbsolutePaths = false;
};
} // end namespace clang
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits