diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1091,7 +1091,7 @@ def dynamic : Flag<["-"], "dynamic">, Flags<[NoArgumentUnused]>; def d_Flag : Flag<["-"], "d">, Group; def d_Joined : Joined<["-"], "d">, Group; -def emit_ast : Flag<["-"], "emit-ast">, +def emit_ast : Flag<["-"], "emit-ast">, Flags<[CoreOption]>, HelpText<"Emit Clang AST files for source inputs">; def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option, FC1Option, FlangOption]>, Group, HelpText<"Use the LLVM representation for assembler and object files">; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5672,6 +5672,14 @@ } } else if (JA.getType() == types::TY_PCH && IsCLMode()) { NamedOutput = C.getArgs().MakeArgString(GetClPchPath(C, BaseName)); + } else if ((JA.getType() == types::TY_Plist || JA.getType() == types::TY_AST) && + C.getArgs().hasArg(options::OPT__SLASH_Fo, options::OPT__SLASH_o)) { + StringRef Val = + C.getArgs() + .getLastArg(options::OPT__SLASH_Fo, options::OPT__SLASH_o) + ->getValue(); + NamedOutput = + MakeCLOutputFilename(C.getArgs(), Val, BaseName, types::TY_Object); } else { const char *Suffix = types::getTypeTempSuffix(JA.getType(), IsCLMode()); assert(Suffix && "All types used for output should have a suffix."); diff --git a/clang/test/Driver/ast.c b/clang/test/Driver/ast.c --- a/clang/test/Driver/ast.c +++ b/clang/test/Driver/ast.c @@ -25,3 +25,15 @@ // FIXME: There is a problem with compiling AST's in that the input language is // not available for use by other tools (for example, to automatically add // -lstdc++). We may need -x [objective-]c++-ast and all that goodness. :( + +// Also check clang-cl since the driver is slightly different +// RUN: %clang_cl -ccc-print-phases -emit-ast -- %s 2> %t +// RUN: echo 'END' >> %t +// RUN: FileCheck -check-prefix EMIT-AST-PHASES-CLANGCL -input-file %t %s + +// EMIT-AST-PHASES-CLANGCL: 0: input, +// EMIT-AST-PHASES-CLANGCL: , c +// EMIT-AST-PHASES-CLANGCL: 1: preprocessor, {0}, cpp-output +// EMIT-AST-PHASES-CLANGCL: 2: compiler, {1}, ast +// EMIT-AST-PHASES-CLANGCL-NOT: 3: +// EMIT-AST-PHASES-CLANGCL: END diff --git a/clang/test/Driver/cl-outputs.c b/clang/test/Driver/cl-outputs.c --- a/clang/test/Driver/cl-outputs.c +++ b/clang/test/Driver/cl-outputs.c @@ -37,6 +37,12 @@ // CHECK-MULTIPLESOURCEOK2: "-o" "cl-outputs.obj" // CHECK-MULTIPLESOURCEOK2: "-o" "cl-outputs.obj" +// RUN: %clang_cl -emit-ast /Fotest.ast -### -- %s 2>&1 | FileCheck -check-prefix=FoASTNAME %s +// FoASTNAME: "-o" "test.ast" + +// RUN: %clang_cl --analyze /Fotest.plist -### -- %s 2>&1 | FileCheck -check-prefix=FoPLIST %s +// FoPLIST: "-o" "test.plist" + // RUN: %clang_cl /c /oa -### -- %s 2>&1 | FileCheck -check-prefix=oNAME1 %s // oNAME1: "-o" "a.obj" @@ -82,6 +88,11 @@ // RUN: %clang_cl /c /o mydir/ -### -- %s %s 2>&1 | FileCheck -check-prefix=CHECK-oMULTIPLESOURCEOK2 %s // CHECK-oMULTIPLESOURCEOK2: "-o" "mydir{{[/\\]+}}cl-outputs.obj" +// RUN: %clang_cl -emit-ast /otest.ast -### -- %s 2>&1 | FileCheck -check-prefix=oASTNAME %s +// oASTNAME: "-o" "test.ast" + +// RUN: %clang_cl --analyze /otest.plist -### -- %s 2>&1 | FileCheck -check-prefix=oPLIST %s +// oPLIST: "-o" "test.plist" // RUN: %clang_cl /c /obar /Fofoo -### -- %s 2>&1 | FileCheck -check-prefix=FooRACE1 %s // FooRACE1: "-o" "foo.obj"