diff options
author | Hamza Sood <hamza_sood@me.com> | 2018-09-09 12:06:35 +0000 |
---|---|---|
committer | Hamza Sood <hamza_sood@me.com> | 2018-09-09 12:06:35 +0000 |
commit | e05bf60631631a0badfa9d41d946ec09d7255e45 (patch) | |
tree | 81fb487038bd82eb077994f95a8613da0c9710f4 /clang/unittests/Tooling/CompilationDatabaseTest.cpp | |
parent | 4f5450742e97c7f98409be5a148edb9c862f1252 (diff) | |
download | llvm-e05bf60631631a0badfa9d41d946ec09d7255e45.zip llvm-e05bf60631631a0badfa9d41d946ec09d7255e45.tar.gz llvm-e05bf60631631a0badfa9d41d946ec09d7255e45.tar.bz2 |
[Tooling] Improve handling of CL-style options
This patch fixes the handling of clang-cl options in InterpolatingCompilationDatabase.
They were previously ignored completely, which led to a lot of bugs:
Additional options were being added with the wrong syntax. E.g. a file was
specified as C++ by adding -x c++, which causes an error in CL mode.
The args were parsed and then rendered, which means that the aliasing information
was lost. E.g. /W4 was rendered to -Wall, which in CL mode means -Weverything.
CL options were ignored when checking things like -std=, so a lot of logic was
being bypassed.
Differential Revision: https://reviews.llvm.org/D51321
llvm-svn: 341760
Diffstat (limited to 'clang/unittests/Tooling/CompilationDatabaseTest.cpp')
-rw-r--r-- | clang/unittests/Tooling/CompilationDatabaseTest.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp b/clang/unittests/Tooling/CompilationDatabaseTest.cpp index cbe4d28..125ba48 100644 --- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp +++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp @@ -648,14 +648,17 @@ class InterpolateTest : public ::testing::Test { protected: // Adds an entry to the underlying compilation database. // A flag is injected: -D <File>, so the command used can be identified. - void add(llvm::StringRef File, llvm::StringRef Flags = "") { - llvm::SmallVector<StringRef, 8> Argv = {"clang", File, "-D", File}; + void add(StringRef File, StringRef Clang, StringRef Flags) { + SmallVector<StringRef, 8> Argv = {Clang, File, "-D", File}; llvm::SplitString(Flags, Argv); - llvm::SmallString<32> Dir; + + SmallString<32> Dir; llvm::sys::path::system_temp_directory(false, Dir); + Entries[path(File)].push_back( {Dir, path(File), {Argv.begin(), Argv.end()}, "foo.o"}); } + void add(StringRef File, StringRef Flags = "") { add(File, "clang", Flags); } // Turn a unix path fragment (foo/bar.h) into a native path (C:\tmp\foo\bar.h) std::string path(llvm::SmallString<32> File) { @@ -739,6 +742,30 @@ TEST_F(InterpolateTest, Case) { EXPECT_EQ(getCommand("foo/bar/baz/shout.C"), "clang -D FOO/BAR/BAZ/SHOUT.cc"); } +TEST_F(InterpolateTest, Aliasing) { + add("foo.cpp", "-faligned-new"); + + // The interpolated command should keep the given flag as written, even though + // the flag is internally represented as an alias. + EXPECT_EQ(getCommand("foo.hpp"), "clang -D foo.cpp -faligned-new"); +} + +TEST_F(InterpolateTest, ClangCL) { + add("foo.cpp", "clang-cl", "/W4"); + + // Language flags should be added with CL syntax. + EXPECT_EQ(getCommand("foo.h"), "clang-cl -D foo.cpp /W4 /TP"); +} + +TEST_F(InterpolateTest, DriverModes) { + add("foo.cpp", "clang-cl", "--driver-mode=gcc"); + add("bar.cpp", "clang", "--driver-mode=cl"); + + // --driver-mode overrides should be respected. + EXPECT_EQ(getCommand("foo.h"), "clang-cl -D foo.cpp --driver-mode=gcc -x c++-header"); + EXPECT_EQ(getCommand("bar.h"), "clang -D bar.cpp --driver-mode=cl /TP"); +} + TEST(CompileCommandTest, EqualityOperator) { CompileCommand CCRef("/foo/bar", "hello.c", {"a", "b"}, "hello.o"); CompileCommand CCTest = CCRef; |