184778b2aSKeno Fischer //===- unittests/CodeGen/BufferSourceTest.cpp - MemoryBuffer source tests -===// 284778b2aSKeno Fischer // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 684778b2aSKeno Fischer // 784778b2aSKeno Fischer //===----------------------------------------------------------------------===// 884778b2aSKeno Fischer 954e655b3SVassil Vassilev #include "TestCompiler.h" 1054e655b3SVassil Vassilev 1184778b2aSKeno Fischer #include "clang/AST/ASTContext.h" 1284778b2aSKeno Fischer #include "clang/AST/RecursiveASTVisitor.h" 13575bc3baSChandler Carruth #include "clang/Basic/TargetInfo.h" 14575bc3baSChandler Carruth #include "clang/CodeGen/ModuleBuilder.h" 1584778b2aSKeno Fischer #include "clang/Frontend/CompilerInstance.h" 1684778b2aSKeno Fischer #include "clang/Lex/Preprocessor.h" 1784778b2aSKeno Fischer #include "clang/Parse/ParseAST.h" 18575bc3baSChandler Carruth #include "clang/Sema/Sema.h" 19575bc3baSChandler Carruth #include "llvm/IR/LLVMContext.h" 2084778b2aSKeno Fischer #include "llvm/Support/MemoryBuffer.h" 21*d768bf99SArchibald Elliott #include "llvm/TargetParser/Host.h" 2262c7f035SArchibald Elliott #include "llvm/TargetParser/Triple.h" 2384778b2aSKeno Fischer #include "gtest/gtest.h" 2484778b2aSKeno Fischer 2584778b2aSKeno Fischer using namespace llvm; 2684778b2aSKeno Fischer using namespace clang; 2784778b2aSKeno Fischer 2884778b2aSKeno Fischer namespace { 2984778b2aSKeno Fischer TEST(BufferSourceTest,EmitCXXGlobalInitFunc)3054e655b3SVassil VassilevTEST(BufferSourceTest, EmitCXXGlobalInitFunc) { 3184778b2aSKeno Fischer // Emitting constructors for global objects involves looking 3284778b2aSKeno Fischer // at the source file name. This makes sure that we don't crash 3384778b2aSKeno Fischer // if the source file is a memory buffer. 3484778b2aSKeno Fischer const char TestProgram[] = 3584778b2aSKeno Fischer "class EmitCXXGlobalInitFunc " 3684778b2aSKeno Fischer "{ " 3784778b2aSKeno Fischer "public: " 3884778b2aSKeno Fischer " EmitCXXGlobalInitFunc() {} " 3984778b2aSKeno Fischer "}; " 4084778b2aSKeno Fischer "EmitCXXGlobalInitFunc test; "; 4184778b2aSKeno Fischer 4254e655b3SVassil Vassilev clang::LangOptions LO; 4354e655b3SVassil Vassilev LO.CPlusPlus = 1; 4454e655b3SVassil Vassilev LO.CPlusPlus11 = 1; 4554e655b3SVassil Vassilev TestCompiler Compiler(LO); 4654e655b3SVassil Vassilev Compiler.init(TestProgram); 4784778b2aSKeno Fischer 4854e655b3SVassil Vassilev clang::ParseAST(Compiler.compiler.getSema(), false, false); 4984778b2aSKeno Fischer } 5084778b2aSKeno Fischer 51dcfba334SHans Wennborg } // end anonymous namespace 52