| 1 |
//=== unittests/Interpreter/IncrementalCompilerBuilderTest.cpp ------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "clang/Basic/TargetOptions.h" |
| 10 |
#include "clang/Frontend/CompilerInstance.h" |
| 11 |
#include "clang/Interpreter/Interpreter.h" |
| 12 |
#include "clang/Lex/PreprocessorOptions.h" |
| 13 |
#include "llvm/Support/Error.h" |
| 14 |
#include "gtest/gtest.h" |
| 15 |
|
| 16 |
using namespace llvm; |
| 17 |
using namespace clang; |
| 18 |
|
| 19 |
namespace { |
| 20 |
|
| 21 |
// Usually FrontendAction takes the raw pointers and wraps them back into |
| 22 |
// unique_ptrs in InitializeFileRemapping() |
| 23 |
static void cleanupRemappedFileBuffers(CompilerInstance &CI) { |
| 24 |
for (const auto &RB : CI.getPreprocessorOpts().RemappedFileBuffers) { |
| 25 |
delete RB.second; |
| 26 |
} |
| 27 |
CI.getPreprocessorOpts().clearRemappedFiles(); |
| 28 |
} |
| 29 |
|
| 30 |
TEST(IncrementalCompilerBuilder, SetCompilerArgs) { |
| 31 |
std::vector<const char *> ClangArgv = {"-Xclang", "-ast-dump-all"}; |
| 32 |
auto CB = clang::IncrementalCompilerBuilder(); |
| 33 |
CB.SetCompilerArgs(ClangArgv); |
| 34 |
auto CI = cantFail(CB.CreateCpp()); |
| 35 |
EXPECT_TRUE(CI->getFrontendOpts().ASTDumpAll); |
| 36 |
cleanupRemappedFileBuffers(*CI); |
| 37 |
} |
| 38 |
|
| 39 |
TEST(IncrementalCompilerBuilder, SetTargetTriple) { |
| 40 |
// FIXME : This test doesn't current work for Emscripten builds. |
| 41 |
// It should be possible to make it work.For details on how it fails and |
| 42 |
// the current progress to enable this test see |
| 43 |
// the following Github issue https: // |
| 44 |
// github.com/llvm/llvm-project/issues/153461 |
| 45 |
#ifdef __EMSCRIPTEN__ |
| 46 |
GTEST_SKIP() << "Test fails for Emscipten builds"; |
| 47 |
#endif |
| 48 |
auto CB = clang::IncrementalCompilerBuilder(); |
| 49 |
CB.SetTargetTriple("armv6-none-eabi"); |
| 50 |
auto CI = cantFail(CB.CreateCpp()); |
| 51 |
EXPECT_EQ(CI->getTargetOpts().Triple, "armv6-unknown-none-eabi"); |
| 52 |
cleanupRemappedFileBuffers(*CI); |
| 53 |
} |
| 54 |
|
| 55 |
} // end anonymous namespace |