Skip to content

Commit 3f0578d

Browse files
committed
[clang-cl] Add -emit-ast to clang-cl driver
Also make the output of -emit-ast end up where /o points. The same with .plist files from the static analyzer. These are changes needed to make it possible to do CTU static analysing work with clang-cl. Reviewed By: hans Differential Revision: https://reviews.llvm.org/D128409
1 parent 8686610 commit 3f0578d

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ def dynamiclib : Flag<["-"], "dynamiclib">;
10971097
def dynamic : Flag<["-"], "dynamic">, Flags<[NoArgumentUnused]>;
10981098
def d_Flag : Flag<["-"], "d">, Group<d_Group>;
10991099
def d_Joined : Joined<["-"], "d">, Group<d_Group>;
1100-
def emit_ast : Flag<["-"], "emit-ast">,
1100+
def emit_ast : Flag<["-"], "emit-ast">, Flags<[CoreOption]>,
11011101
HelpText<"Emit Clang AST files for source inputs">;
11021102
def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option, FC1Option, FlangOption]>, Group<Action_Group>,
11031103
HelpText<"Use the LLVM representation for assembler and object files">;

clang/lib/Driver/Driver.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5661,6 +5661,14 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
56615661
}
56625662
} else if (JA.getType() == types::TY_PCH && IsCLMode()) {
56635663
NamedOutput = C.getArgs().MakeArgString(GetClPchPath(C, BaseName));
5664+
} else if ((JA.getType() == types::TY_Plist || JA.getType() == types::TY_AST) &&
5665+
C.getArgs().hasArg(options::OPT__SLASH_o)) {
5666+
StringRef Val =
5667+
C.getArgs()
5668+
.getLastArg(options::OPT__SLASH_o)
5669+
->getValue();
5670+
NamedOutput =
5671+
MakeCLOutputFilename(C.getArgs(), Val, BaseName, types::TY_Object);
56645672
} else {
56655673
const char *Suffix = types::getTypeTempSuffix(JA.getType(), IsCLMode());
56665674
assert(Suffix && "All types used for output should have a suffix.");

clang/test/Driver/ast.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@
2525
// FIXME: There is a problem with compiling AST's in that the input language is
2626
// not available for use by other tools (for example, to automatically add
2727
// -lstdc++). We may need -x [objective-]c++-ast and all that goodness. :(
28+
29+
// Also check clang-cl since the driver is slightly different
30+
// RUN: %clang_cl -ccc-print-phases -emit-ast -- %s 2> %t
31+
// RUN: echo 'END' >> %t
32+
// RUN: FileCheck -check-prefix EMIT-AST-PHASES-CLANGCL -input-file %t %s
33+
34+
// EMIT-AST-PHASES-CLANGCL: 0: input,
35+
// EMIT-AST-PHASES-CLANGCL: , c
36+
// EMIT-AST-PHASES-CLANGCL: 1: preprocessor, {0}, cpp-output
37+
// EMIT-AST-PHASES-CLANGCL: 2: compiler, {1}, ast
38+
// EMIT-AST-PHASES-CLANGCL-NOT: 3:
39+
// EMIT-AST-PHASES-CLANGCL: END

clang/test/Driver/cl-outputs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
// RUN: %clang_cl /c /o mydir/ -### -- %s %s 2>&1 | FileCheck -check-prefix=CHECK-oMULTIPLESOURCEOK2 %s
8383
// CHECK-oMULTIPLESOURCEOK2: "-o" "mydir{{[/\\]+}}cl-outputs.obj"
8484

85+
// RUN: %clang_cl -emit-ast /otest.ast -### -- %s 2>&1 | FileCheck -check-prefix=oASTNAME %s
86+
// oASTNAME: "-o" "test.ast"
87+
88+
// RUN: %clang_cl --analyze /otest.plist -### -- %s 2>&1 | FileCheck -check-prefix=oPLIST %s
89+
// oPLIST: "-o" "test.plist"
8590

8691
// RUN: %clang_cl /c /obar /Fofoo -### -- %s 2>&1 | FileCheck -check-prefix=FooRACE1 %s
8792
// FooRACE1: "-o" "foo.obj"

0 commit comments

Comments
 (0)