From 8e3230ffa3ad2994c3bbddffc3e53b3bccb2ee41 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Tue, 22 Dec 2020 15:05:16 +0100 Subject: [clang][cli] Port DiagnosticOpts to new option parsing system This patch introduces additional infrastructure necessary to accommodate DiagnosticOptions. DiagnosticOptions are unique in that they are parsed by the same function in cc1 AND in the Clang driver. The call to the parsing function from the driver occurs early on in the compilation process, where no proper DiagnosticEngine exists, because the diagnostic options (passed through command line) are not known yet. To preserve the current behavior, we need to be able to selectively parse: * all options (for -cc1), * only diagnostic options (for driver). This patch achieves that in the following way: * new MacroPrefix field is added to the Option TableGen class, * new IsDiag TableGen mixin sets MacroPrefix to "DIAG_", * TableGen backend serializes option records into a macro with the prefix, * CompilerInvocation parse/generate methods define the [DIAG_]OPTION_WITH_MARSHALLING macros to handle diagnostic options separately. Depends on D93700, D93701 & D93702. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D84673 --- clang/unittests/Frontend/CompilerInvocationTest.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp') diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index 577059f..8efba9c 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -680,4 +680,19 @@ TEST_F(CommandLineTest, PresentAndNotImpliedGenerated) { ASSERT_THAT(GeneratedArgs, Contains(StrEq("-cl-mad-enable"))); ASSERT_THAT(GeneratedArgs, Contains(StrEq("-menable-unsafe-fp-math"))); } + +// Diagnostic option. + +TEST_F(CommandLineTest, DiagnosticOptionPresent) { + const char *Args[] = {"-verify=xyz"}; + + ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags)); + + ASSERT_EQ(Invocation.getDiagnosticOpts().VerifyPrefixes, + std::vector({"xyz"})); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + + ASSERT_THAT(GeneratedArgs, ContainsN(StrEq("-verify=xyz"), 1)); +} } // anonymous namespace -- cgit v1.1