Add support for MSVC cl-compatible command-line switches.

Patch from Paul Redmond with test by me.
This commit is contained in:
Kim Gräsman 2014-12-14 21:36:35 +00:00
parent c86f0685b0
commit 4d4f24d451
3 changed files with 38 additions and 1 deletions

View File

@ -179,7 +179,12 @@ CompilerInstance* CreateCompilerInstance(int argc, const char **argv) {
// FIXME: This is a hack to try to force the driver to do something we can
// recognize. We need to extend the driver library to support this use model
// (basically, exactly one input, and the operation mode is hard wired).
args.push_back("-fsyntax-only");
driver.ParseDriverMode(args);
if (driver.IsCLMode())
args.push_back("/Zs");
else
args.push_back("-fsyntax-only");
unique_ptr<Compilation> compilation(driver.BuildCompilation(args));
if (!compilation)
return NULL;

View File

@ -81,6 +81,7 @@ class OneIwyuTest(unittest.TestCase):
clang_flags_map = {
'alias_template.cc': ['-std=c++11'],
'auto_type_within_template.cc': ['-std=c++11'],
'clmode.cc': ['--driver-mode=cl', '/C', '/Os', '/W2'],
'conversion_ctor.cc': ['-std=c++11'],
'deleted_implicit.cc' : ['-std=c++11'],
'lambda_fwd_decl.cc': ['-std=c++11'],

31
tests/cxx/clmode.cc Normal file
View File

@ -0,0 +1,31 @@
//===--- clmode.cc - test input file for iwyu -----------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// This test will be executed with --driver-mode=cl and some MSVC-shaped
// flags to ensure we can run IWYU with MSVC-compatible command-line switches.
#include "tests/cxx/direct.h"
// This use isn't really important, we just want to make sure IWYU does
// something reasonable even in CL driver mode.
// IWYU: IndirectClass is...*indirect.h
IndirectClass random_use;
/**** IWYU_SUMMARY
tests/cxx/clmode.cc should add these lines:
#include "tests/cxx/indirect.h"
tests/cxx/clmode.cc should remove these lines:
- #include "tests/cxx/direct.h" // lines XX-XX
The full include-list for tests/cxx/clmode.cc:
#include "tests/cxx/indirect.h" // for IndirectClass
***** IWYU_SUMMARY */