2014-08-27 06:10:15 +08:00
|
|
|
//===- unittests/CodeGen/BufferSourceTest.cpp - MemoryBuffer source tests -===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2014-08-27 06:10:15 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-11-16 20:56:11 +08:00
|
|
|
#include "TestCompiler.h"
|
|
|
|
|
2014-08-27 06:10:15 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/RecursiveASTVisitor.h"
|
2015-01-14 19:23:58 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
|
|
|
#include "clang/CodeGen/ModuleBuilder.h"
|
2014-08-27 06:10:15 +08:00
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
|
|
|
#include "clang/Lex/Preprocessor.h"
|
|
|
|
#include "clang/Parse/ParseAST.h"
|
2015-01-14 19:23:58 +08:00
|
|
|
#include "clang/Sema/Sema.h"
|
2014-08-27 06:10:15 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2015-01-14 19:23:58 +08:00
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2014-08-27 06:10:15 +08:00
|
|
|
#include "llvm/Support/Host.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-11-16 20:56:11 +08:00
|
|
|
TEST(BufferSourceTest, EmitCXXGlobalInitFunc) {
|
|
|
|
// Emitting constructors for global objects involves looking
|
|
|
|
// at the source file name. This makes sure that we don't crash
|
|
|
|
// if the source file is a memory buffer.
|
|
|
|
const char TestProgram[] =
|
2014-08-27 06:10:15 +08:00
|
|
|
"class EmitCXXGlobalInitFunc "
|
|
|
|
"{ "
|
|
|
|
"public: "
|
|
|
|
" EmitCXXGlobalInitFunc() {} "
|
|
|
|
"}; "
|
|
|
|
"EmitCXXGlobalInitFunc test; ";
|
|
|
|
|
2020-11-16 20:56:11 +08:00
|
|
|
clang::LangOptions LO;
|
|
|
|
LO.CPlusPlus = 1;
|
|
|
|
LO.CPlusPlus11 = 1;
|
|
|
|
TestCompiler Compiler(LO);
|
|
|
|
Compiler.init(TestProgram);
|
2014-08-27 06:10:15 +08:00
|
|
|
|
2020-11-16 20:56:11 +08:00
|
|
|
clang::ParseAST(Compiler.compiler.getSema(), false, false);
|
2014-08-27 06:10:15 +08:00
|
|
|
}
|
|
|
|
|
2015-10-07 07:40:43 +08:00
|
|
|
} // end anonymous namespace
|