From 85b1354098ba0a665fdd47204d0e53e63d09d9ab Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Fri, 31 Jul 2020 10:44:12 +0100 Subject: [C++20][Modules][HU 5/5] Add fdirectives-only mode for preprocessing output. When the -fdirectives-only option is used together with -E, the preprocessor output reflects evaluation of if/then/else directives. As such, it preserves defines and undefs of macros that are still live after such processing. The intent is that this output could be consumed as input to generate considered a C++20 header unit. We strip out any (unused) defines that come from built-in, built-in-file or command line; these are re-added when the preprocessed source is consumed. Differential Revision: https://reviews.llvm.org/D121099 --- clang/lib/Frontend/CompilerInvocation.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 5bb480a..b2221198 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4413,6 +4413,8 @@ static void GeneratePreprocessorOutputArgs( GenerateArg(Args, OPT_dM, SA); if (!Generate_dM && Opts.ShowMacros) GenerateArg(Args, OPT_dD, SA); + if (Opts.DirectivesOnly) + GenerateArg(Args, OPT_fdirectives_only, SA); } static bool ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts, @@ -4435,6 +4437,7 @@ static bool ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts, Opts.ShowCPP = isStrictlyPreprocessorAction(Action) && !Args.hasArg(OPT_dM); Opts.ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD); + Opts.DirectivesOnly = Args.hasArg(OPT_fdirectives_only); return Diags.getNumErrors() == NumErrorsBefore; } -- cgit v1.1