[clang] ed86328 - [clang][cli] Add explicit round-trip test
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 16 05:56:33 PST 2021
Author: Jan Svoboda
Date: 2021-02-16T14:56:26+01:00
New Revision: ed86328515888b762277a118773b2f41b106d016
URL: https://github.com/llvm/llvm-project/commit/ed86328515888b762277a118773b2f41b106d016
DIFF: https://github.com/llvm/llvm-project/commit/ed86328515888b762277a118773b2f41b106d016.diff
LOG: [clang][cli] Add explicit round-trip test
This patch adds a test that verifies all `CompilerInvocation` members are filled correctly during command line round-trip.
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D96705
Added:
Modified:
clang/unittests/Frontend/CompilerInvocationTest.cpp
Removed:
################################################################################
diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 268f0d0dca45..b7f9cedc9cb3 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -7,8 +7,10 @@
//===----------------------------------------------------------------------===//
#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Basic/TargetOptions.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/TextDiagnosticBuffer.h"
+#include "clang/Lex/PreprocessorOptions.h"
#include "llvm/Support/Host.h"
#include "gmock/gmock.h"
@@ -740,4 +742,85 @@ TEST_F(CommandLineTest, DigraphsEnabled) {
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fdigraphs")));
}
+
+TEST_F(CommandLineTest, RoundTrip) {
+ // Testing one marshalled and one manually generated option from each
+ // CompilerInvocation member.
+ const char *Args[] = {
+ "-round-trip-args",
+ // LanguageOptions
+ "-std=c17",
+ "-fmax-tokens=10",
+ // TargetOptions
+ "-target-sdk-version=1.2.3",
+ "-meabi",
+ "4",
+ // DiagnosticOptions
+ "-Wundef-prefix=XY",
+ "-fdiagnostics-format",
+ "clang",
+ // HeaderSearchOptions
+ "-stdlib=libc++",
+ "-fimplicit-module-maps",
+ // PreprocessorOptions
+ "-DXY=AB",
+ "-include-pch",
+ "a.pch",
+ // AnalyzerOptions
+ "-analyzer-config",
+ "ctu-import-threshold=42",
+ "-unoptimized-cfg",
+ // MigratorOptions (no manually handled arguments)
+ "-no-ns-alloc-error",
+ // CodeGenOptions
+ "-debug-info-kind=limited",
+ "-debug-info-macro",
+ // DependencyOutputOptions
+ "--show-includes",
+ "-H",
+ // FileSystemOptions (no manually handled arguments)
+ "-working-directory",
+ "folder",
+ // FrontendOptions
+ "-load",
+ "plugin",
+ "-ast-merge",
+ // PreprocessorOutputOptions
+ "-dD",
+ "-CC",
+ };
+
+ ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
+
+ ASSERT_TRUE(Invocation.getLangOpts()->C17);
+ ASSERT_EQ(Invocation.getLangOpts()->MaxTokens, 10u);
+
+ ASSERT_EQ(Invocation.getTargetOpts().SDKVersion, llvm::VersionTuple(1, 2, 3));
+ ASSERT_EQ(Invocation.getTargetOpts().EABIVersion, EABI::EABI4);
+
+ ASSERT_THAT(Invocation.getDiagnosticOpts().UndefPrefixes,
+ Contains(StrEq("XY")));
+ ASSERT_EQ(Invocation.getDiagnosticOpts().getFormat(),
+ TextDiagnosticFormat::Clang);
+
+ ASSERT_TRUE(Invocation.getHeaderSearchOpts().UseLibcxx);
+ ASSERT_TRUE(Invocation.getHeaderSearchOpts().ImplicitModuleMaps);
+
+ ASSERT_THAT(Invocation.getPreprocessorOpts().Macros,
+ Contains(std::make_pair(std::string("XY=AB"), false)));
+ ASSERT_EQ(Invocation.getPreprocessorOpts().ImplicitPCHInclude, "a.pch");
+
+ ASSERT_EQ(Invocation.getAnalyzerOpts()->Config["ctu-import-threshold"], "42");
+ ASSERT_TRUE(Invocation.getAnalyzerOpts()->UnoptimizedCFG);
+
+ ASSERT_TRUE(Invocation.getMigratorOpts().NoNSAllocReallocError);
+
+ ASSERT_EQ(Invocation.getCodeGenOpts().getDebugInfo(),
+ codegenoptions::DebugInfoKind::LimitedDebugInfo);
+ ASSERT_TRUE(Invocation.getCodeGenOpts().MacroDebugInfo);
+
+ ASSERT_EQ(Invocation.getDependencyOutputOpts().ShowIncludesDest,
+ ShowIncludesDestination::Stdout);
+ ASSERT_TRUE(Invocation.getDependencyOutputOpts().ShowHeaderIncludes);
+}
} // anonymous namespace
More information about the cfe-commits
mailing list