llvm-project/clang/unittests/Interpreter/IncrementalCompilerBuilderTest.cpp
mcbarton b24b8a5bb4
Enable running ClangReplInterpreterTests in an Emscripten environment (#150977)
@vgvassilev @anutosh491 This is what it took for me to enable running
ClangReplInterpreterTests in an Emscripten environment. When I ran this
patch for llvm 20 we could run InterpreterTest.InstantiateTemplate , but
now it crashes gtest when running in node. Let me know what you think.
2025-08-14 14:07:13 +05:30

56 lines
1.9 KiB
C++

//=== 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) {
// FIXME : This test doesn't current work for Emscripten builds.
// It should be possible to make it work.For details on how it fails and
// the current progress to enable this test see
// the following Github issue https: //
// github.com/llvm/llvm-project/issues/153461
#ifdef __EMSCRIPTEN__
GTEST_SKIP() << "Test fails for Emscipten builds";
#endif
auto CB = clang::IncrementalCompilerBuilder();
CB.SetTargetTriple("armv6-none-eabi");
auto CI = cantFail(CB.CreateCpp());
EXPECT_EQ(CI->getTargetOpts().Triple, "armv6-unknown-none-eabi");
cleanupRemappedFileBuffers(*CI);
}
} // end anonymous namespace