[clang] 3f0578d - [clang-cl] Add -emit-ast to clang-cl driver
Tobias Hieta via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 28 00:11:46 PDT 2022
Author: Tobias Hieta
Date: 2022-06-28T09:11:34+02:00
New Revision: 3f0578dd87ee5539eccae507b6a77cfe3354d705
URL: https://github.com/llvm/llvm-project/commit/3f0578dd87ee5539eccae507b6a77cfe3354d705
DIFF: https://github.com/llvm/llvm-project/commit/3f0578dd87ee5539eccae507b6a77cfe3354d705.diff
LOG: [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
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/test/Driver/ast.c
clang/test/Driver/cl-outputs.c
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index d379ec8285103..f4fe08aa1a5b3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1097,7 +1097,7 @@ def dynamiclib : Flag<["-"], "dynamiclib">;
def dynamic : Flag<["-"], "dynamic">, Flags<[NoArgumentUnused]>;
def d_Flag : Flag<["-"], "d">, Group<d_Group>;
def d_Joined : Joined<["-"], "d">, Group<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<Action_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
index c34da3a67a2e0..0da32dae2ef60 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5661,6 +5661,14 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
}
} 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_o)) {
+ StringRef Val =
+ C.getArgs()
+ .getLastArg(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
index c1d7b1a6d7b03..7187454bf90e8 100644
--- 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
diff erent
+// 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
index abca67b12e55e..972e4499dbd9c 100644
--- a/clang/test/Driver/cl-outputs.c
+++ b/clang/test/Driver/cl-outputs.c
@@ -82,6 +82,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"
More information about the cfe-commits
mailing list