| 1 | //===- unittests/CodeGen/BufferSourceTest.cpp - MemoryBuffer source tests -===// |
|---|---|
| 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 "TestCompiler.h" |
| 10 | |
| 11 | #include "clang/AST/ASTContext.h" |
| 12 | #include "clang/AST/RecursiveASTVisitor.h" |
| 13 | #include "clang/Basic/TargetInfo.h" |
| 14 | #include "clang/CodeGen/ModuleBuilder.h" |
| 15 | #include "clang/Frontend/CompilerInstance.h" |
| 16 | #include "clang/Lex/Preprocessor.h" |
| 17 | #include "clang/Parse/ParseAST.h" |
| 18 | #include "clang/Sema/Sema.h" |
| 19 | #include "llvm/IR/LLVMContext.h" |
| 20 | #include "llvm/Support/MemoryBuffer.h" |
| 21 | #include "llvm/TargetParser/Host.h" |
| 22 | #include "llvm/TargetParser/Triple.h" |
| 23 | #include "gtest/gtest.h" |
| 24 | |
| 25 | using namespace llvm; |
| 26 | using namespace clang; |
| 27 | |
| 28 | namespace { |
| 29 | |
| 30 | TEST(BufferSourceTest, EmitCXXGlobalInitFunc) { |
| 31 | // Emitting constructors for global objects involves looking |
| 32 | // at the source file name. This makes sure that we don't crash |
| 33 | // if the source file is a memory buffer. |
| 34 | const char TestProgram[] = |
| 35 | "class EmitCXXGlobalInitFunc " |
| 36 | "{ " |
| 37 | "public: " |
| 38 | " EmitCXXGlobalInitFunc() {} " |
| 39 | "}; " |
| 40 | "EmitCXXGlobalInitFunc test; "; |
| 41 | |
| 42 | clang::LangOptions LO; |
| 43 | LO.CPlusPlus = 1; |
| 44 | LO.CPlusPlus11 = 1; |
| 45 | TestCompiler Compiler(LO); |
| 46 | Compiler.init(TestProgram); |
| 47 | |
| 48 | clang::ParseAST(S&: Compiler.compiler.getSema(), PrintStats: false, SkipFunctionBodies: false); |
| 49 | } |
| 50 | |
| 51 | } // end anonymous namespace |
| 52 |
