aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
diff options
context:
space:
mode:
authorStefan Gränitz <stefan.graenitz@gmail.com>2024-03-06 16:46:56 +0100
committerStefan Gränitz <stefan.graenitz@gmail.com>2024-03-07 23:15:02 +0100
commit2a4a852a67eab2f8d0533c23719b1bd08d6edea9 (patch)
treec7d7e01be36afabd8636e945f45a74a6953bde07 /clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
parentf78129e2bbafdd04a71bc09fc44e0797dd08db05 (diff)
downloadllvm-2a4a852a67eab2f8d0533c23719b1bd08d6edea9.zip
llvm-2a4a852a67eab2f8d0533c23719b1bd08d6edea9.tar.gz
llvm-2a4a852a67eab2f8d0533c23719b1bd08d6edea9.tar.bz2
Reland [clang-repl] Expose setter for triple in IncrementalCompilerBuilder (#84174)
With out-of-process execution the target triple can be different from the one on the host. We need an interface to configure it. Relanding this with cleanup-fixes in the unittest.
Diffstat (limited to 'clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp')
-rw-r--r--clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp b/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
new file mode 100644
index 0000000..f729566
--- /dev/null
+++ b/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
@@ -0,0 +1,47 @@
+//=== unittests/Interpreter/IncrementalCompilerBuilderTest.cpp ------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Support/Error.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang;
+
+namespace {
+
+// Usually FrontendAction takes the raw pointers and wraps them back into
+// unique_ptrs in InitializeFileRemapping()
+static void cleanupRemappedFileBuffers(CompilerInstance &CI) {
+ for (const auto &RB : CI.getPreprocessorOpts().RemappedFileBuffers) {
+ delete RB.second;
+ }
+ CI.getPreprocessorOpts().clearRemappedFiles();
+}
+
+TEST(IncrementalCompilerBuilder, SetCompilerArgs) {
+ std::vector<const char *> ClangArgv = {"-Xclang", "-ast-dump-all"};
+ auto CB = clang::IncrementalCompilerBuilder();
+ CB.SetCompilerArgs(ClangArgv);
+ auto CI = cantFail(CB.CreateCpp());
+ EXPECT_TRUE(CI->getFrontendOpts().ASTDumpAll);
+ cleanupRemappedFileBuffers(*CI);
+}
+
+TEST(IncrementalCompilerBuilder, SetTargetTriple) {
+ auto CB = clang::IncrementalCompilerBuilder();
+ CB.SetTargetTriple("armv6-none-eabi");
+ auto CI = cantFail(CB.CreateCpp());
+ EXPECT_EQ(CI->getTargetOpts().Triple, "armv6-none-unknown-eabi");
+ cleanupRemappedFileBuffers(*CI);
+}
+
+} // end anonymous namespace