44 #include "llvm/ADT/APSInt.h"
45 #include "llvm/ADT/Triple.h"
46 #include "llvm/IR/CallSite.h"
47 #include "llvm/IR/CallingConv.h"
48 #include "llvm/IR/DataLayout.h"
49 #include "llvm/IR/Intrinsics.h"
50 #include "llvm/IR/LLVMContext.h"
51 #include "llvm/IR/Module.h"
52 #include "llvm/ProfileData/InstrProfReader.h"
53 #include "llvm/Support/ConvertUTF.h"
54 #include "llvm/Support/ErrorHandling.h"
56 using namespace clang;
57 using namespace CodeGen;
74 llvm_unreachable(
"invalid C++ ABI kind");
80 const llvm::DataLayout &TD,
83 :
Context(C), LangOpts(C.getLangOpts()), HeaderSearchOpts(HSO),
84 PreprocessorOpts(PPO), CodeGenOpts(CGO), TheModule(M), Diags(diags),
85 TheDataLayout(TD), Target(C.getTargetInfo()), ABI(
createCXXABI(*this)),
86 VMContext(M.getContext()), TBAA(nullptr), TheTargetCodeGenInfo(nullptr),
88 OpenCLRuntime(nullptr), OpenMPRuntime(nullptr), CUDARuntime(nullptr),
89 DebugInfo(nullptr), ARCData(nullptr),
90 NoObjCARCExceptionsMetadata(nullptr), RRData(nullptr), PGOReader(nullptr),
91 CFConstantStringClassRef(nullptr), ConstantStringClassRef(nullptr),
92 NSConstantStringType(nullptr), NSConcreteGlobalBlock(nullptr),
93 NSConcreteStackBlock(nullptr), BlockObjectAssign(nullptr),
94 BlockObjectDispose(nullptr), BlockDescriptorType(nullptr),
95 GenericBlockLiteralType(nullptr), LifetimeStartFn(nullptr),
99 llvm::LLVMContext &LLVMContext = M.getContext();
100 VoidTy = llvm::Type::getVoidTy(LLVMContext);
101 Int8Ty = llvm::Type::getInt8Ty(LLVMContext);
102 Int16Ty = llvm::Type::getInt16Ty(LLVMContext);
103 Int32Ty = llvm::Type::getInt32Ty(LLVMContext);
104 Int64Ty = llvm::Type::getInt64Ty(LLVMContext);
105 FloatTy = llvm::Type::getFloatTy(LLVMContext);
106 DoubleTy = llvm::Type::getDoubleTy(LLVMContext);
121 createOpenCLRuntime();
123 createOpenMPRuntime();
128 if (LangOpts.
Sanitize.
has(SanitizerKind::Thread) ||
129 (!CodeGenOpts.RelaxedAliasing && CodeGenOpts.OptimizationLevel > 0))
136 CodeGenOpts.EmitGcovArcs ||
137 CodeGenOpts.EmitGcovNotes)
140 Block.GlobalUniqueCount = 0;
149 if (std::error_code EC = ReaderOrErr.getError()) {
151 "Could not read profile %0: %1");
155 PGOReader = std::move(ReaderOrErr.get());
160 if (CodeGenOpts.CoverageMapping)
166 delete OpenCLRuntime;
167 delete OpenMPRuntime;
169 delete TheTargetCodeGenInfo;
176 void CodeGenModule::createObjCRuntime() {
192 llvm_unreachable(
"bad runtime kind");
195 void CodeGenModule::createOpenCLRuntime() {
199 void CodeGenModule::createOpenMPRuntime() {
203 void CodeGenModule::createCUDARuntime() {
208 Replacements[Name] =
C;
211 void CodeGenModule::applyReplacements() {
212 for (
auto &I : Replacements) {
213 StringRef MangledName = I.first();
214 llvm::Constant *Replacement = I.second;
218 auto *OldF = cast<llvm::Function>(Entry);
219 auto *NewF = dyn_cast<llvm::Function>(Replacement);
221 if (
auto *Alias = dyn_cast<llvm::GlobalAlias>(Replacement)) {
222 NewF = dyn_cast<llvm::Function>(Alias->getAliasee());
224 auto *CE = cast<llvm::ConstantExpr>(Replacement);
225 assert(CE->getOpcode() == llvm::Instruction::BitCast ||
226 CE->getOpcode() == llvm::Instruction::GetElementPtr);
227 NewF = dyn_cast<llvm::Function>(CE->getOperand(0));
232 OldF->replaceAllUsesWith(Replacement);
234 NewF->removeFromParent();
235 OldF->getParent()->getFunctionList().insertAfter(OldF, NewF);
237 OldF->eraseFromParent();
244 llvm::SmallPtrSet<const llvm::GlobalAlias*, 4> Visited;
245 const llvm::Constant *
C = &GA;
247 C = C->stripPointerCasts();
248 if (
auto *GO = dyn_cast<llvm::GlobalObject>(C))
251 auto *GA2 = dyn_cast<llvm::GlobalAlias>(
C);
254 if (!Visited.insert(GA2).second)
256 C = GA2->getAliasee();
260 void CodeGenModule::checkAliases() {
267 const auto *D = cast<ValueDecl>(GD.getDecl());
268 const AliasAttr *AA = D->getAttr<AliasAttr>();
271 auto *Alias = cast<llvm::GlobalAlias>(Entry);
275 Diags.
Report(AA->getLocation(), diag::err_cyclic_alias);
276 }
else if (GV->isDeclaration()) {
278 Diags.
Report(AA->getLocation(), diag::err_alias_to_undefined);
281 llvm::Constant *Aliasee = Alias->getAliasee();
282 llvm::GlobalValue *AliaseeGV;
283 if (
auto CE = dyn_cast<llvm::ConstantExpr>(Aliasee))
284 AliaseeGV = cast<llvm::GlobalValue>(CE->getOperand(0));
286 AliaseeGV = cast<llvm::GlobalValue>(Aliasee);
288 if (
const SectionAttr *SA = D->getAttr<SectionAttr>()) {
289 StringRef AliasSection = SA->getName();
290 if (AliasSection != AliaseeGV->getSection())
291 Diags.
Report(SA->getLocation(), diag::warn_alias_with_section)
300 if (
auto GA = dyn_cast<llvm::GlobalAlias>(AliaseeGV)) {
301 if (GA->mayBeOverridden()) {
302 Diags.
Report(AA->getLocation(), diag::warn_alias_to_weak_alias)
303 << GV->getName() << GA->getName();
304 Aliasee = llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
305 GA->getAliasee(), Alias->getType());
306 Alias->setAliasee(Aliasee);
316 auto *Alias = cast<llvm::GlobalAlias>(Entry);
317 Alias->replaceAllUsesWith(llvm::UndefValue::get(Alias->getType()));
318 Alias->eraseFromParent();
323 DeferredDeclsToEmit.clear();
325 OpenMPRuntime->clear();
329 StringRef MainFile) {
332 if (VisitedInMainFile > 0 && VisitedInMainFile == MissingInMainFile) {
333 if (MainFile.empty())
334 MainFile =
"<stdin>";
335 Diags.
Report(diag::warn_profile_data_unprofiled) << MainFile;
337 Diags.
Report(diag::warn_profile_data_out_of_date) << Visited << Missing
345 EmitCXXGlobalInitFunc();
346 EmitCXXGlobalDtorFunc();
347 EmitCXXThreadLocalInitFunc();
349 if (llvm::Function *ObjCInitFunction =
ObjCRuntime->ModuleInitFunction())
350 AddGlobalCtor(ObjCInitFunction);
354 AddGlobalCtor(CudaCtorFunction);
356 AddGlobalDtor(CudaDtorFunction);
360 EmitCtorList(GlobalCtors,
"llvm.global_ctors");
361 EmitCtorList(GlobalDtors,
"llvm.global_dtors");
363 EmitStaticExternCAliases();
366 CoverageMapping->emit();
369 if (CodeGenOpts.Autolink &&
370 (Context.
getLangOpts().Modules || !LinkerOptionsMetadata.empty())) {
371 EmitModuleLinkOptions();
373 if (CodeGenOpts.DwarfVersion)
377 CodeGenOpts.DwarfVersion);
383 llvm::DEBUG_METADATA_VERSION);
388 if ( Arch == llvm::Triple::arm
389 || Arch == llvm::Triple::armeb
390 || Arch == llvm::Triple::thumb
391 || Arch == llvm::Triple::thumbeb) {
393 uint64_t WCharWidth =
398 uint64_t EnumWidth = Context.
getLangOpts().ShortEnums ? 1 : 4;
402 if (uint32_t PLevel = Context.
getLangOpts().PICLevel) {
406 case 1: PL = llvm::PICLevel::Small;
break;
407 case 2: PL = llvm::PICLevel::Large;
break;
408 default: llvm_unreachable(
"Invalid PIC Level");
414 SimplifyPersonality();
425 EmitVersionIdentMetadata();
427 EmitTargetMetadata();
460 llvm::MDNode *AccessN,
472 llvm::MDNode *TBAAInfo,
473 bool ConvertTypeToTag) {
474 if (ConvertTypeToTag && TBAA)
475 Inst->setMetadata(llvm::LLVMContext::MD_tbaa,
478 Inst->setMetadata(llvm::LLVMContext::MD_tbaa, TBAAInfo);
490 "cannot compile this %0 yet");
491 std::string Msg = Type;
493 << Msg << S->getSourceRange();
500 "cannot compile this %0 yet");
501 std::string Msg = Type;
512 if (GV->hasLocalLinkage()) {
524 return llvm::StringSwitch<llvm::GlobalVariable::ThreadLocalMode>(
S)
525 .Case(
"global-dynamic", llvm::GlobalVariable::GeneralDynamicTLSModel)
526 .Case(
"local-dynamic", llvm::GlobalVariable::LocalDynamicTLSModel)
527 .Case(
"initial-exec", llvm::GlobalVariable::InitialExecTLSModel)
528 .Case(
"local-exec", llvm::GlobalVariable::LocalExecTLSModel);
535 return llvm::GlobalVariable::GeneralDynamicTLSModel;
537 return llvm::GlobalVariable::LocalDynamicTLSModel;
539 return llvm::GlobalVariable::InitialExecTLSModel;
541 return llvm::GlobalVariable::LocalExecTLSModel;
543 llvm_unreachable(
"Invalid TLS model!");
547 assert(D.
getTLSKind() &&
"setting TLS mode on non-TLS var!");
549 llvm::GlobalValue::ThreadLocalMode TLM;
553 if (
const TLSModelAttr *
Attr = D.
getAttr<TLSModelAttr>()) {
557 GV->setThreadLocalMode(TLM);
562 if (!FoundStr.empty())
565 const auto *ND = cast<NamedDecl>(GD.
getDecl());
569 llvm::raw_svector_ostream Out(Buffer);
570 if (
const auto *D = dyn_cast<CXXConstructorDecl>(ND))
572 else if (
const auto *D = dyn_cast<CXXDestructorDecl>(ND))
579 assert(II &&
"Attempt to mangle unnamed decl.");
584 auto Result = Manglings.insert(std::make_pair(Str, GD));
585 return FoundStr =
Result.first->first();
594 llvm::raw_svector_ostream Out(Buffer);
597 dyn_cast_or_null<VarDecl>(initializedGlobalDecl.
getDecl()), Out);
598 else if (
const auto *CD = dyn_cast<CXXConstructorDecl>(D))
600 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(D))
603 MangleCtx.
mangleBlock(cast<DeclContext>(D), BD, Out);
605 auto Result = Manglings.insert(std::make_pair(Out.str(), BD));
606 return Result.first->first();
615 void CodeGenModule::AddGlobalCtor(llvm::Function *Ctor,
int Priority,
616 llvm::Constant *AssociatedData) {
618 GlobalCtors.push_back(Structor(Priority, Ctor, AssociatedData));
623 void CodeGenModule::AddGlobalDtor(llvm::Function *Dtor,
int Priority) {
625 GlobalDtors.push_back(Structor(Priority, Dtor,
nullptr));
628 void CodeGenModule::EmitCtorList(
const CtorList &Fns,
const char *GlobalName) {
630 llvm::FunctionType* CtorFTy = llvm::FunctionType::get(
VoidTy,
false);
631 llvm::Type *CtorPFTy = llvm::PointerType::getUnqual(CtorFTy);
634 llvm::StructType *CtorStructTy = llvm::StructType::get(
639 for (
const auto &I : Fns) {
640 llvm::Constant *
S[] = {
641 llvm::ConstantInt::get(
Int32Ty, I.Priority,
false),
642 llvm::ConstantExpr::getBitCast(I.Initializer, CtorPFTy),
644 ? llvm::ConstantExpr::getBitCast(I.AssociatedData,
VoidPtrTy)
645 : llvm::Constant::getNullValue(
VoidPtrTy))};
646 Ctors.push_back(llvm::ConstantStruct::get(CtorStructTy, S));
649 if (!Ctors.empty()) {
650 llvm::ArrayType *AT = llvm::ArrayType::get(CtorStructTy, Ctors.size());
651 new llvm::GlobalVariable(TheModule, AT,
false,
652 llvm::GlobalValue::AppendingLinkage,
653 llvm::ConstantArray::get(AT, Ctors),
658 llvm::GlobalValue::LinkageTypes
660 const auto *D = cast<FunctionDecl>(GD.
getDecl());
664 if (isa<CXXDestructorDecl>(D) &&
665 getCXXABI().useThunkForDtorVariant(cast<CXXDestructorDecl>(D),
670 : llvm::GlobalValue::LinkOnceODRLinkage;
677 const auto *FD = cast<FunctionDecl>(GD.
getDecl());
679 if (
const auto *Dtor = dyn_cast_or_null<CXXDestructorDecl>(FD)) {
682 F->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
687 if (FD->hasAttr<DLLImportAttr>())
688 F->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);
689 else if (FD->hasAttr<DLLExportAttr>())
690 F->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass);
692 F->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass);
697 setNonAliasAttributes(D, F);
706 F->setAttributes(llvm::AttributeSet::get(
getLLVMContext(), AttributeList));
707 F->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
717 if (!LangOpts.Exceptions)
return false;
720 if (LangOpts.CXXExceptions)
return true;
723 if (LangOpts.ObjCExceptions) {
734 if (CodeGenOpts.UnwindTables)
735 B.addAttribute(llvm::Attribute::UWTable);
738 B.addAttribute(llvm::Attribute::NoUnwind);
742 B.addAttribute(llvm::Attribute::Naked);
743 B.addAttribute(llvm::Attribute::NoInline);
744 }
else if (D->
hasAttr<NoDuplicateAttr>()) {
745 B.addAttribute(llvm::Attribute::NoDuplicate);
746 }
else if (D->
hasAttr<NoInlineAttr>()) {
747 B.addAttribute(llvm::Attribute::NoInline);
748 }
else if (D->
hasAttr<AlwaysInlineAttr>() &&
749 !F->getAttributes().hasAttribute(llvm::AttributeSet::FunctionIndex,
750 llvm::Attribute::NoInline)) {
752 B.addAttribute(llvm::Attribute::AlwaysInline);
756 if (!D->
hasAttr<OptimizeNoneAttr>())
757 B.addAttribute(llvm::Attribute::OptimizeForSize);
758 B.addAttribute(llvm::Attribute::Cold);
762 B.addAttribute(llvm::Attribute::MinSize);
765 B.addAttribute(llvm::Attribute::StackProtect);
767 B.addAttribute(llvm::Attribute::StackProtectStrong);
769 B.addAttribute(llvm::Attribute::StackProtectReq);
771 F->addAttributes(llvm::AttributeSet::FunctionIndex,
772 llvm::AttributeSet::get(
773 F->getContext(), llvm::AttributeSet::FunctionIndex, B));
775 if (D->
hasAttr<OptimizeNoneAttr>()) {
777 F->addFnAttr(llvm::Attribute::OptimizeNone);
778 F->addFnAttr(llvm::Attribute::NoInline);
781 assert(!F->hasFnAttribute(llvm::Attribute::OptimizeForSize) &&
782 "OptimizeNone and OptimizeForSize on same function!");
783 assert(!F->hasFnAttribute(llvm::Attribute::MinSize) &&
784 "OptimizeNone and MinSize on same function!");
785 assert(!F->hasFnAttribute(llvm::Attribute::AlwaysInline) &&
786 "OptimizeNone and AlwaysInline on same function!");
790 F->removeFnAttr(llvm::Attribute::InlineHint);
793 if (isa<CXXConstructorDecl>(D) || isa<CXXDestructorDecl>(D))
794 F->setUnnamedAddr(
true);
795 else if (
const auto *MD = dyn_cast<CXXMethodDecl>(D))
797 F->setUnnamedAddr(
true);
801 F->setAlignment(alignment);
804 if (F->getAlignment() < 2 && isa<CXXMethodDecl>(D))
809 llvm::GlobalValue *GV) {
810 if (
const auto *ND = dyn_cast<NamedDecl>(D))
820 llvm::GlobalValue *GV) {
825 if (D->
hasAttr<DLLExportAttr>())
826 GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
829 void CodeGenModule::setNonAliasAttributes(
const Decl *D,
830 llvm::GlobalObject *GO) {
833 if (
const SectionAttr *SA = D->
getAttr<SectionAttr>())
834 GO->setSection(SA->getName());
847 setNonAliasAttributes(D, F);
857 if (ND->
hasAttr<DLLImportAttr>()) {
859 GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
860 }
else if (ND->
hasAttr<DLLExportAttr>()) {
862 GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
866 GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
875 void CodeGenModule::SetFunctionAttributes(
GlobalDecl GD, llvm::Function *F,
876 bool IsIncompleteFunction,
881 F->setAttributes(llvm::Intrinsic::getAttributes(
getLLVMContext(), IID));
885 const auto *FD = cast<FunctionDecl>(GD.
getDecl());
887 if (!IsIncompleteFunction)
893 if (!IsThunk &&
getCXXABI().HasThisReturn(GD) &&
896 assert(!F->arg_empty() &&
897 F->arg_begin()->getType()
898 ->canLosslesslyBitCastTo(F->getReturnType()) &&
899 "unexpected this return");
900 F->addAttribute(1, llvm::Attribute::Returned);
908 if (
const SectionAttr *SA = FD->getAttr<SectionAttr>())
909 F->setSection(SA->getName());
913 if (FD->isReplaceableGlobalAllocationFunction())
914 F->addAttribute(llvm::AttributeSet::FunctionIndex,
915 llvm::Attribute::NoBuiltin);
919 assert(!GV->isDeclaration() &&
920 "Only globals with definition can force usage.");
921 LLVMUsed.emplace_back(GV);
925 assert(!GV->isDeclaration() &&
926 "Only globals with definition can force usage.");
927 LLVMCompilerUsed.emplace_back(GV);
931 std::vector<llvm::WeakVH> &List) {
938 UsedArray.resize(List.size());
939 for (
unsigned i = 0, e = List.size(); i != e; ++i) {
941 llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
942 cast<llvm::Constant>(&*List[i]), CGM.
Int8PtrTy);
945 if (UsedArray.empty())
947 llvm::ArrayType *ATy = llvm::ArrayType::get(CGM.
Int8PtrTy, UsedArray.size());
949 auto *GV =
new llvm::GlobalVariable(
950 CGM.
getModule(), ATy,
false, llvm::GlobalValue::AppendingLinkage,
951 llvm::ConstantArray::get(ATy, UsedArray), Name);
953 GV->setSection(
"llvm.metadata");
956 void CodeGenModule::emitLLVMUsed() {
957 emitUsed(*
this,
"llvm.used", LLVMUsed);
958 emitUsed(*
this,
"llvm.compiler.used", LLVMCompilerUsed);
963 LinkerOptionsMetadata.push_back(llvm::MDNode::get(
getLLVMContext(), MDOpts));
970 LinkerOptionsMetadata.push_back(llvm::MDNode::get(
getLLVMContext(), MDOpts));
977 LinkerOptionsMetadata.push_back(llvm::MDNode::get(
getLLVMContext(), MDOpts));
984 llvm::SmallPtrSet<Module *, 16> &Visited) {
986 if (Mod->
Parent && Visited.insert(Mod->
Parent).second) {
991 for (
unsigned I = Mod->
Imports.size(); I > 0; --I) {
992 if (Visited.insert(Mod->
Imports[I - 1]).second)
1003 llvm::Metadata *Args[2] = {
1004 llvm::MDString::get(Context,
"-framework"),
1005 llvm::MDString::get(Context, Mod->
LinkLibraries[I - 1].Library)};
1007 Metadata.push_back(llvm::MDNode::get(Context, Args));
1015 auto *OptString = llvm::MDString::get(Context, Opt);
1016 Metadata.push_back(llvm::MDNode::get(Context, OptString));
1020 void CodeGenModule::EmitModuleLinkOptions() {
1024 llvm::SetVector<clang::Module *> LinkModules;
1025 llvm::SmallPtrSet<clang::Module *, 16> Visited;
1029 for (
Module *M : ImportedModules)
1030 if (Visited.insert(M).second)
1035 while (!Stack.empty()) {
1038 bool AnyChildren =
false;
1043 Sub != SubEnd; ++Sub) {
1046 if ((*Sub)->IsExplicit)
1049 if (Visited.insert(*Sub).second) {
1050 Stack.push_back(*Sub);
1058 LinkModules.insert(Mod);
1067 for (
Module *M : LinkModules)
1068 if (Visited.insert(M).second)
1070 std::reverse(MetadataArgs.begin(), MetadataArgs.end());
1071 LinkerOptionsMetadata.append(MetadataArgs.begin(), MetadataArgs.end());
1074 getModule().addModuleFlag(llvm::Module::AppendUnique,
"Linker Options",
1076 LinkerOptionsMetadata));
1079 void CodeGenModule::EmitDeferred() {
1084 if (!DeferredVTables.empty()) {
1085 EmitDeferredVTables();
1090 assert(DeferredVTables.empty());
1094 if (DeferredDeclsToEmit.empty())
1099 std::vector<DeferredGlobal> CurDeclsToEmit;
1100 CurDeclsToEmit.swap(DeferredDeclsToEmit);
1102 for (DeferredGlobal &G : CurDeclsToEmit) {
1104 llvm::GlobalValue *GV = G.GV;
1117 if (GV && !GV->isDeclaration())
1121 EmitGlobalDefinition(D, GV);
1126 if (!DeferredVTables.empty() || !DeferredDeclsToEmit.empty()) {
1128 assert(DeferredVTables.empty() && DeferredDeclsToEmit.empty());
1134 if (Annotations.empty())
1138 llvm::Constant *Array = llvm::ConstantArray::get(llvm::ArrayType::get(
1139 Annotations[0]->getType(), Annotations.size()), Annotations);
1140 auto *gv =
new llvm::GlobalVariable(
getModule(), Array->getType(),
false,
1141 llvm::GlobalValue::AppendingLinkage,
1142 Array,
"llvm.global.annotations");
1147 llvm::Constant *&AStr = AnnotationStrings[Str];
1152 llvm::Constant *s = llvm::ConstantDataArray::getString(
getLLVMContext(), Str);
1154 new llvm::GlobalVariable(
getModule(), s->getType(),
true,
1155 llvm::GlobalValue::PrivateLinkage, s,
".str");
1157 gv->setUnnamedAddr(
true);
1175 return llvm::ConstantInt::get(
Int32Ty, LineNo);
1179 const AnnotateAttr *AA,
1187 llvm::Constant *Fields[4] = {
1188 llvm::ConstantExpr::getBitCast(GV,
Int8PtrTy),
1189 llvm::ConstantExpr::getBitCast(AnnoGV,
Int8PtrTy),
1190 llvm::ConstantExpr::getBitCast(UnitGV,
Int8PtrTy),
1193 return llvm::ConstantStruct::getAnon(Fields);
1197 llvm::GlobalValue *GV) {
1198 assert(D->
hasAttr<AnnotateAttr>() &&
"no annotate attribute");
1208 if (SanitizerBL.isBlacklistedFunction(Fn->getName()))
1217 return SanitizerBL.isBlacklistedFile(MainFile->getName());
1224 StringRef Category)
const {
1227 SanitizerKind::Address | SanitizerKind::KernelAddress))
1230 if (SanitizerBL.isBlacklistedGlobal(GV->getName(), Category))
1232 if (SanitizerBL.isBlacklistedLocation(Loc, Category))
1238 while (
auto AT = dyn_cast<ArrayType>(Ty.
getTypePtr()))
1239 Ty = AT->getElementType();
1244 if (SanitizerBL.isBlacklistedType(TypeStr, Category))
1251 bool CodeGenModule::MustBeEmitted(
const ValueDecl *Global) {
1253 if (LangOpts.EmitAllDecls)
1259 bool CodeGenModule::MayBeEmittedEagerly(
const ValueDecl *Global) {
1260 if (
const auto *FD = dyn_cast<FunctionDecl>(Global))
1267 if (LangOpts.OpenMP && LangOpts.OpenMPUseTLS &&
1279 std::string Name =
"_GUID_" + Uuid.lower();
1280 std::replace(Name.begin(), Name.end(),
'-',
'_');
1283 if (llvm::GlobalVariable *GV =
getModule().getNamedGlobal(Name))
1286 llvm::Constant *Init = EmitUuidofInitializer(Uuid);
1287 assert(Init &&
"failed to initialize as constant");
1289 auto *GV =
new llvm::GlobalVariable(
1291 true, llvm::GlobalValue::LinkOnceODRLinkage, Init, Name);
1293 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
1298 const AliasAttr *AA = VD->
getAttr<AliasAttr>();
1299 assert(AA &&
"No alias?");
1307 return llvm::ConstantExpr::getBitCast(Entry, DeclTy->getPointerTo(AS));
1310 llvm::Constant *Aliasee;
1311 if (isa<llvm::FunctionType>(DeclTy))
1312 Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy,
1316 Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
1317 llvm::PointerType::getUnqual(DeclTy),
1320 auto *F = cast<llvm::GlobalValue>(Aliasee);
1321 F->setLinkage(llvm::Function::ExternalWeakLinkage);
1322 WeakRefReferences.insert(F);
1328 const auto *Global = cast<ValueDecl>(GD.
getDecl());
1331 if (Global->
hasAttr<WeakRefAttr>())
1336 if (Global->
hasAttr<AliasAttr>())
1337 return EmitAliasDefinition(GD);
1340 if (LangOpts.CUDA) {
1341 if (LangOpts.CUDAIsDevice) {
1342 if (!Global->
hasAttr<CUDADeviceAttr>() &&
1343 !Global->
hasAttr<CUDAGlobalAttr>() &&
1344 !Global->
hasAttr<CUDAConstantAttr>() &&
1345 !Global->
hasAttr<CUDASharedAttr>())
1348 if (!Global->
hasAttr<CUDAHostAttr>() && (
1349 Global->
hasAttr<CUDADeviceAttr>() ||
1350 Global->
hasAttr<CUDAConstantAttr>() ||
1351 Global->
hasAttr<CUDASharedAttr>()))
1357 if (
const auto *FD = dyn_cast<FunctionDecl>(Global)) {
1359 if (!FD->doesThisDeclarationHaveABody()) {
1360 if (!FD->doesDeclarationForceExternallyVisibleDefinition())
1369 GetOrCreateLLVMFunction(MangledName, Ty, GD,
false,
1374 const auto *VD = cast<VarDecl>(Global);
1375 assert(VD->isFileVarDecl() &&
"Cannot emit local var decl as global.");
1385 if (MustBeEmitted(Global) && MayBeEmittedEagerly(Global)) {
1387 EmitGlobalDefinition(GD);
1394 cast<VarDecl>(Global)->hasInit()) {
1395 DelayedCXXInitPosition[Global] = CXXGlobalInits.size();
1396 CXXGlobalInits.push_back(
nullptr);
1402 addDeferredDeclToEmit(GV, GD);
1403 }
else if (MustBeEmitted(Global)) {
1405 assert(!MayBeEmittedEagerly(Global));
1406 addDeferredDeclToEmit(
nullptr, GD);
1411 DeferredDecls[MangledName] = GD;
1416 struct FunctionIsDirectlyRecursive :
1418 const StringRef Name;
1426 bool TraverseCallExpr(
CallExpr *E) {
1431 if (Attr && Name == Attr->getLabel()) {
1436 if (!BuiltinID || !BI.isLibFunction(BuiltinID))
1438 StringRef BuiltinName = BI.GetName(BuiltinID);
1439 if (BuiltinName.startswith(
"__builtin_") &&
1440 Name == BuiltinName.slice(strlen(
"__builtin_"), StringRef::npos)) {
1453 CodeGenModule::isTriviallyRecursive(
const FunctionDecl *FD) {
1455 if (
getCXXABI().getMangleContext().shouldMangleDeclName(FD)) {
1457 AsmLabelAttr *Attr = FD->
getAttr<AsmLabelAttr>();
1460 Name = Attr->getLabel();
1465 FunctionIsDirectlyRecursive Walker(Name, Context.
BuiltinInfo);
1466 Walker.TraverseFunctionDecl(const_cast<FunctionDecl*>(FD));
1467 return Walker.Result;
1471 CodeGenModule::shouldEmitFunction(
GlobalDecl GD) {
1474 const auto *F = cast<FunctionDecl>(GD.
getDecl());
1475 if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr<AlwaysInlineAttr>())
1482 return !isTriviallyRecursive(F);
1490 void CodeGenModule::CompleteDIClassType(
const CXXMethodDecl* D) {
1497 DI->getOrCreateRecordType(ThisPtr->getPointeeType(), D->
getLocation());
1501 void CodeGenModule::EmitGlobalDefinition(
GlobalDecl GD, llvm::GlobalValue *GV) {
1502 const auto *D = cast<ValueDecl>(GD.
getDecl());
1506 "Generating code for declaration");
1508 if (isa<FunctionDecl>(D)) {
1511 if (!shouldEmitFunction(GD))
1514 if (
const auto *Method = dyn_cast<CXXMethodDecl>(D)) {
1515 CompleteDIClassType(Method);
1518 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(Method))
1520 else if (
const auto *DD = dyn_cast<CXXDestructorDecl>(Method))
1523 EmitGlobalFunctionDefinition(GD, GV);
1525 if (Method->isVirtual())
1531 return EmitGlobalFunctionDefinition(GD, GV);
1534 if (
const auto *VD = dyn_cast<VarDecl>(D))
1535 return EmitGlobalVarDefinition(VD);
1537 llvm_unreachable(
"Invalid argument to EmitGlobalDefinition()");
1548 CodeGenModule::GetOrCreateLLVMFunction(StringRef MangledName,
1551 bool DontDefer,
bool IsThunk,
1552 llvm::AttributeSet ExtraAttrs) {
1558 if (WeakRefReferences.erase(Entry)) {
1559 const FunctionDecl *FD = cast_or_null<FunctionDecl>(D);
1560 if (FD && !FD->
hasAttr<WeakAttr>())
1565 if (D && !D->
hasAttr<DLLImportAttr>() && !D->
hasAttr<DLLExportAttr>())
1566 Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
1568 if (Entry->getType()->getElementType() == Ty)
1572 return llvm::ConstantExpr::getBitCast(Entry, Ty->getPointerTo());
1578 bool IsIncompleteFunction =
false;
1580 llvm::FunctionType *FTy;
1581 if (isa<llvm::FunctionType>(Ty)) {
1582 FTy = cast<llvm::FunctionType>(Ty);
1584 FTy = llvm::FunctionType::get(
VoidTy,
false);
1585 IsIncompleteFunction =
true;
1591 assert(F->getName() == MangledName &&
"name was uniqued!");
1593 SetFunctionAttributes(GD, F, IsIncompleteFunction, IsThunk);
1594 if (ExtraAttrs.hasAttributes(llvm::AttributeSet::FunctionIndex)) {
1595 llvm::AttrBuilder B(ExtraAttrs, llvm::AttributeSet::FunctionIndex);
1596 F->addAttributes(llvm::AttributeSet::FunctionIndex,
1597 llvm::AttributeSet::get(VMContext,
1598 llvm::AttributeSet::FunctionIndex,
1606 if (D && isa<CXXDestructorDecl>(D) &&
1607 getCXXABI().useThunkForDtorVariant(cast<CXXDestructorDecl>(D),
1609 addDeferredDeclToEmit(F, GD);
1614 auto DDI = DeferredDecls.find(MangledName);
1615 if (DDI != DeferredDecls.end()) {
1619 addDeferredDeclToEmit(F, DDI->second);
1620 DeferredDecls.erase(DDI);
1635 for (
const auto *FD = cast<FunctionDecl>(D)->getMostRecentDecl(); FD;
1648 if (!IsIncompleteFunction) {
1649 assert(F->getType()->getElementType() == Ty);
1653 llvm::Type *PTy = llvm::PointerType::getUnqual(Ty);
1654 return llvm::ConstantExpr::getBitCast(F, PTy);
1669 return GetOrCreateLLVMFunction(MangledName, Ty, GD, ForVTable, DontDefer);
1677 llvm::AttributeSet ExtraAttrs) {
1679 GetOrCreateLLVMFunction(Name, FTy,
GlobalDecl(),
false,
1680 false,
false, ExtraAttrs);
1681 if (
auto *F = dyn_cast<llvm::Function>(C))
1692 llvm::AttributeSet ExtraAttrs) {
1694 GetOrCreateLLVMFunction(Name, FTy,
GlobalDecl(),
false,
1695 false,
false, ExtraAttrs);
1696 if (
auto *F = dyn_cast<llvm::Function>(C))
1715 return ExcludeCtor && !Record->hasMutableFields() &&
1716 Record->hasTrivialDestructor();
1730 CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
1731 llvm::PointerType *Ty,
1736 if (WeakRefReferences.erase(Entry)) {
1737 if (D && !D->
hasAttr<WeakAttr>())
1742 if (D && !D->
hasAttr<DLLImportAttr>() && !D->
hasAttr<DLLExportAttr>())
1743 Entry->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
1745 if (Entry->getType() == Ty)
1749 if (Entry->getType()->getAddressSpace() != Ty->getAddressSpace())
1750 return llvm::ConstantExpr::getAddrSpaceCast(Entry, Ty);
1752 return llvm::ConstantExpr::getBitCast(Entry, Ty);
1756 auto *GV =
new llvm::GlobalVariable(
1757 getModule(), Ty->getElementType(),
false,
1759 llvm::GlobalVariable::NotThreadLocal, AddrSpace);
1764 auto DDI = DeferredDecls.find(MangledName);
1765 if (DDI != DeferredDecls.end()) {
1768 addDeferredDeclToEmit(GV, DDI->second);
1769 DeferredDecls.erase(DDI);
1778 GV->setAlignment(
getContext().getDeclAlign(D).getQuantity());
1784 CXXThreadLocals.push_back(std::make_pair(D, GV));
1790 if (
getContext().isMSStaticDataMemberInlineDefinition(D)) {
1791 EmitGlobalVarDefinition(D);
1799 GV->setSection(
".cp.rodata");
1802 if (AddrSpace != Ty->getAddressSpace())
1803 return llvm::ConstantExpr::getAddrSpaceCast(GV, Ty);
1809 llvm::GlobalVariable *
1812 llvm::GlobalValue::LinkageTypes
Linkage) {
1813 llvm::GlobalVariable *GV =
getModule().getNamedGlobal(Name);
1814 llvm::GlobalVariable *OldGV =
nullptr;
1818 if (GV->getType()->getElementType() == Ty)
1823 assert(GV->isDeclaration() &&
"Declaration has wrong type!");
1828 GV =
new llvm::GlobalVariable(
getModule(), Ty,
true,
1829 Linkage,
nullptr, Name);
1833 GV->takeName(OldGV);
1835 if (!OldGV->use_empty()) {
1836 llvm::Constant *NewPtrForOldDecl =
1837 llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
1838 OldGV->replaceAllUsesWith(NewPtrForOldDecl);
1841 OldGV->eraseFromParent();
1845 !GV->hasAvailableExternallyLinkage())
1846 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
1862 llvm::PointerType *PTy =
1863 llvm::PointerType::get(Ty,
getContext().getTargetAddressSpace(ASTTy));
1866 return GetOrCreateLLVMGlobal(MangledName, PTy, D);
1874 return GetOrCreateLLVMGlobal(Name, llvm::PointerType::getUnqual(Ty),
nullptr);
1878 assert(!D->
getInit() &&
"Cannot emit definite definitions here!");
1880 if (!MustBeEmitted(D)) {
1886 DeferredDecls[MangledName] = D;
1892 EmitGlobalVarDefinition(D);
1897 TheDataLayout.getTypeStoreSizeInBits(Ty));
1901 unsigned AddrSpace) {
1902 if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {
1903 if (D->
hasAttr<CUDAConstantAttr>())
1905 else if (D->
hasAttr<CUDASharedAttr>())
1914 template<
typename SomeDecl>
1916 llvm::GlobalValue *GV) {
1922 if (!D->template hasAttr<UsedAttr>())
1931 const SomeDecl *First = D->getFirstDecl();
1932 if (First->getDeclContext()->isRecord() || !First->isInExternCContext())
1938 std::pair<StaticExternCMap::iterator, bool> R =
1939 StaticExternCValues.insert(std::make_pair(D->getIdentifier(), GV));
1944 R.first->second =
nullptr;
1951 if (D.
hasAttr<SelectAnyAttr>())
1955 if (
auto *VD = dyn_cast<VarDecl>(&D))
1969 llvm_unreachable(
"No such linkage");
1973 llvm::GlobalObject &GO) {
1976 GO.setComdat(TheModule.getOrInsertComdat(GO.getName()));
1979 void CodeGenModule::EmitGlobalVarDefinition(
const VarDecl *D) {
1980 llvm::Constant *Init =
nullptr;
1983 bool NeedsGlobalCtor =
false;
2012 NeedsGlobalCtor =
true;
2015 Init = llvm::UndefValue::get(
getTypes().ConvertType(T));
2022 DelayedCXXInitPosition.erase(D);
2026 llvm::Type* InitType = Init->getType();
2030 if (
auto *CE = dyn_cast<llvm::ConstantExpr>(Entry)) {
2031 assert(CE->getOpcode() == llvm::Instruction::BitCast ||
2032 CE->getOpcode() == llvm::Instruction::AddrSpaceCast ||
2034 CE->getOpcode() == llvm::Instruction::GetElementPtr);
2035 Entry = CE->getOperand(0);
2039 auto *GV = dyn_cast<llvm::GlobalVariable>(Entry);
2051 GV->getType()->getElementType() != InitType ||
2052 GV->getType()->getAddressSpace() !=
2056 Entry->setName(StringRef());
2062 llvm::Constant *NewPtrForOldDecl =
2063 llvm::ConstantExpr::getBitCast(GV, Entry->getType());
2064 Entry->replaceAllUsesWith(NewPtrForOldDecl);
2067 cast<llvm::GlobalValue>(Entry)->eraseFromParent();
2072 if (D->
hasAttr<AnnotateAttr>())
2075 GV->setInitializer(Init);
2078 GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&
2082 if (
const SectionAttr *SA = D->
getAttr<SectionAttr>()) {
2085 GV->setConstant(
true);
2088 GV->setAlignment(
getContext().getDeclAlign(D).getQuantity());
2091 llvm::GlobalValue::LinkageTypes
Linkage =
2102 GV->setLinkage(Linkage);
2103 if (D->
hasAttr<DLLImportAttr>())
2104 GV->setDLLStorageClass(llvm::GlobalVariable::DLLImportStorageClass);
2105 else if (D->
hasAttr<DLLExportAttr>())
2106 GV->setDLLStorageClass(llvm::GlobalVariable::DLLExportStorageClass);
2108 GV->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass);
2110 if (Linkage == llvm::GlobalVariable::CommonLinkage)
2112 GV->setConstant(
false);
2114 setNonAliasAttributes(D, GV);
2116 if (D->
getTLSKind() && !GV->isThreadLocal()) {
2118 CXXThreadLocals.push_back(std::make_pair(D, GV));
2125 if (NeedsGlobalCtor || NeedsGlobalDtor)
2126 EmitCXXGlobalVarDeclInitFunc(D, GV, NeedsGlobalCtor);
2128 SanitizerMD->reportGlobalToASan(GV, *D, NeedsGlobalCtor);
2133 DI->EmitGlobalVariable(GV, D);
2141 if ((NoCommon || D->
hasAttr<NoCommonAttr>()) && !D->
hasAttr<CommonAttr>())
2152 if (D->
hasAttr<SectionAttr>())
2160 if (D->
hasAttr<WeakImportAttr>())
2170 if (D->
hasAttr<AlignedAttr>())
2179 if (FD->isBitField())
2181 if (FD->
hasAttr<AlignedAttr>())
2198 if (IsConstantVariable)
2199 return llvm::GlobalVariable::WeakODRLinkage;
2201 return llvm::GlobalVariable::WeakAnyLinkage;
2207 return llvm::Function::AvailableExternallyLinkage;
2221 return !Context.
getLangOpts().AppleKext ? llvm::Function::LinkOnceODRLinkage
2229 return !Context.
getLangOpts().AppleKext ? llvm::Function::WeakODRLinkage
2236 CodeGenOpts.NoCommon))
2237 return llvm::GlobalVariable::CommonLinkage;
2243 if (D->
hasAttr<SelectAnyAttr>())
2244 return llvm::GlobalVariable::WeakODRLinkage;
2252 const VarDecl *VD,
bool IsConstant) {
2260 llvm::Function *newFn) {
2262 if (old->use_empty())
return;
2264 llvm::Type *newRetTy = newFn->getReturnType();
2267 for (llvm::Value::use_iterator ui = old->use_begin(), ue = old->use_end();
2269 llvm::Value::use_iterator use = ui++;
2270 llvm::User *user = use->getUser();
2274 if (
auto *bitcast = dyn_cast<llvm::ConstantExpr>(user)) {
2275 if (bitcast->getOpcode() == llvm::Instruction::BitCast)
2281 llvm::CallSite callSite(user);
2282 if (!callSite)
continue;
2283 if (!callSite.isCallee(&*use))
continue;
2287 if (callSite->getType() != newRetTy && !callSite->use_empty())
2292 llvm::AttributeSet oldAttrs = callSite.getAttributes();
2295 if (oldAttrs.hasAttributes(llvm::AttributeSet::ReturnIndex))
2297 llvm::AttributeSet::get(newFn->getContext(),
2298 oldAttrs.getRetAttributes()));
2301 unsigned newNumArgs = newFn->arg_size();
2302 if (callSite.arg_size() < newNumArgs)
continue;
2307 bool dontTransform =
false;
2308 for (llvm::Function::arg_iterator ai = newFn->arg_begin(),
2309 ae = newFn->arg_end(); ai != ae; ++ai, ++argNo) {
2310 if (callSite.getArgument(argNo)->getType() != ai->getType()) {
2311 dontTransform =
true;
2316 if (oldAttrs.hasAttributes(argNo + 1))
2319 AttributeSet::get(newFn->getContext(),
2320 oldAttrs.getParamAttributes(argNo + 1)));
2325 if (oldAttrs.hasAttributes(llvm::AttributeSet::FunctionIndex))
2326 newAttrs.push_back(llvm::AttributeSet::get(newFn->getContext(),
2327 oldAttrs.getFnAttributes()));
2331 newArgs.append(callSite.arg_begin(), callSite.arg_begin() + argNo);
2333 llvm::CallSite newCall;
2334 if (callSite.isCall()) {
2336 callSite.getInstruction());
2338 auto *oldInvoke = cast<llvm::InvokeInst>(callSite.getInstruction());
2340 oldInvoke->getNormalDest(),
2341 oldInvoke->getUnwindDest(),
2343 callSite.getInstruction());
2347 if (!newCall->getType()->isVoidTy())
2348 newCall->takeName(callSite.getInstruction());
2349 newCall.setAttributes(
2350 llvm::AttributeSet::get(newFn->getContext(), newAttrs));
2351 newCall.setCallingConv(callSite.getCallingConv());
2354 if (!callSite->use_empty())
2355 callSite->replaceAllUsesWith(newCall.getInstruction());
2358 if (callSite->getDebugLoc())
2359 newCall->setDebugLoc(callSite->getDebugLoc());
2360 callSite->eraseFromParent();
2374 llvm::Function *NewFn) {
2376 if (!isa<llvm::Function>(Old))
return;
2391 void CodeGenModule::EmitGlobalFunctionDefinition(
GlobalDecl GD,
2392 llvm::GlobalValue *GV) {
2393 const auto *D = cast<FunctionDecl>(GD.
getDecl());
2405 if (
auto *CE = dyn_cast<llvm::ConstantExpr>(C)) {
2406 assert(CE->getOpcode() == llvm::Instruction::BitCast);
2407 GV = cast<llvm::GlobalValue>(CE->getOperand(0));
2409 GV = cast<llvm::GlobalValue>(
C);
2413 if (!GV->isDeclaration()) {
2415 GlobalDecl OldGD = Manglings.lookup(GV->getName());
2416 if (
auto *Prev = OldGD.
getDecl())
2417 getDiags().
Report(Prev->getLocation(), diag::note_previous_definition);
2421 if (GV->getType()->getElementType() != Ty) {
2423 assert(GV->isDeclaration() &&
"Shouldn't replace non-declaration");
2433 GV->setName(StringRef());
2443 if (!GV->use_empty()) {
2445 GV->removeDeadConstantUsers();
2449 if (!GV->use_empty()) {
2450 llvm::Constant *NewPtrForOldDecl =
2451 llvm::ConstantExpr::getBitCast(NewFn, GV->getType());
2452 GV->replaceAllUsesWith(NewPtrForOldDecl);
2456 GV->eraseFromParent();
2465 auto *Fn = cast<llvm::Function>(GV);
2481 if (
const ConstructorAttr *CA = D->
getAttr<ConstructorAttr>())
2482 AddGlobalCtor(Fn, CA->getPriority());
2483 if (
const DestructorAttr *DA = D->
getAttr<DestructorAttr>())
2484 AddGlobalDtor(Fn, DA->getPriority());
2485 if (D->
hasAttr<AnnotateAttr>())
2489 void CodeGenModule::EmitAliasDefinition(
GlobalDecl GD) {
2490 const auto *D = cast<ValueDecl>(GD.
getDecl());
2491 const AliasAttr *AA = D->
getAttr<AliasAttr>();
2492 assert(AA &&
"Not an alias?");
2499 if (Entry && !Entry->isDeclaration())
2502 Aliases.push_back(GD);
2508 llvm::Constant *Aliasee;
2509 if (isa<llvm::FunctionType>(DeclTy))
2510 Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GD,
2513 Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
2514 llvm::PointerType::getUnqual(DeclTy),
2519 cast<llvm::PointerType>(Aliasee->getType()),
2523 if (GA->getAliasee() == Entry) {
2524 Diags.
Report(AA->getLocation(), diag::err_cyclic_alias);
2528 assert(Entry->isDeclaration());
2537 GA->takeName(Entry);
2539 Entry->replaceAllUsesWith(llvm::ConstantExpr::getBitCast(GA,
2541 Entry->eraseFromParent();
2543 GA->setName(MangledName);
2551 GA->setLinkage(llvm::Function::WeakAnyLinkage);
2554 if (
const auto *VD = dyn_cast<VarDecl>(D))
2555 if (VD->getTLSKind())
2567 static llvm::StringMapEntry<llvm::GlobalVariable *> &
2570 bool &IsUTF16,
unsigned &StringLength) {
2571 StringRef String = Literal->
getString();
2572 unsigned NumBytes = String.size();
2576 StringLength = NumBytes;
2577 return *Map.insert(std::make_pair(String,
nullptr)).first;
2584 const UTF8 *FromPtr = (
const UTF8 *)String.data();
2585 UTF16 *ToPtr = &ToBuf[0];
2587 (void)ConvertUTF8toUTF16(&FromPtr, FromPtr + NumBytes,
2588 &ToPtr, ToPtr + NumBytes,
2592 StringLength = ToPtr - &ToBuf[0];
2596 return *Map.insert(std::make_pair(
2597 StringRef(reinterpret_cast<const char *>(ToBuf.data()),
2598 (StringLength + 1) * 2),
2602 static llvm::StringMapEntry<llvm::GlobalVariable *> &
2605 StringRef String = Literal->
getString();
2606 StringLength = String.size();
2607 return *Map.insert(std::make_pair(String,
nullptr)).first;
2612 unsigned StringLength = 0;
2613 bool isUTF16 =
false;
2614 llvm::StringMapEntry<llvm::GlobalVariable *> &Entry =
2619 if (
auto *C = Entry.second)
2622 llvm::Constant *Zero = llvm::Constant::getNullValue(
Int32Ty);
2623 llvm::Constant *Zeros[] = { Zero, Zero };
2627 if (!CFConstantStringClassRef) {
2629 Ty = llvm::ArrayType::get(Ty, 0);
2631 "__CFConstantStringClassReference");
2633 V = llvm::ConstantExpr::getGetElementPtr(Ty, GV, Zeros);
2634 CFConstantStringClassRef = V;
2637 V = CFConstantStringClassRef;
2643 llvm::Constant *Fields[4];
2646 Fields[0] = cast<llvm::ConstantExpr>(V);
2650 Fields[1] = isUTF16 ? llvm::ConstantInt::get(Ty, 0x07d0) :
2651 llvm::ConstantInt::get(Ty, 0x07C8);
2654 llvm::Constant *C =
nullptr;
2657 reinterpret_cast<uint16_t *
>(
const_cast<char *
>(Entry.first().data())),
2658 Entry.first().size() / 2);
2659 C = llvm::ConstantDataArray::get(VMContext, Arr);
2661 C = llvm::ConstantDataArray::getString(VMContext, Entry.first());
2667 new llvm::GlobalVariable(
getModule(), C->getType(),
true,
2668 llvm::GlobalValue::PrivateLinkage,
C,
".str");
2669 GV->setUnnamedAddr(
true);
2678 GV->setSection(
"__TEXT,__ustring");
2682 GV->setSection(
"__TEXT,__cstring,cstring_literals");
2687 llvm::ConstantExpr::getGetElementPtr(GV->getValueType(), GV, Zeros);
2691 Fields[2] = llvm::ConstantExpr::getBitCast(Fields[2],
Int8PtrTy);
2695 Fields[3] = llvm::ConstantInt::get(Ty, StringLength);
2698 C = llvm::ConstantStruct::get(STy, Fields);
2699 GV =
new llvm::GlobalVariable(
getModule(), C->getType(),
true,
2700 llvm::GlobalVariable::PrivateLinkage,
C,
2701 "_unnamed_cfstring_");
2702 GV->setSection(
"__DATA,__cfstring");
2708 llvm::GlobalVariable *
2710 unsigned StringLength = 0;
2711 llvm::StringMapEntry<llvm::GlobalVariable *> &Entry =
2714 if (
auto *C = Entry.second)
2717 llvm::Constant *Zero = llvm::Constant::getNullValue(
Int32Ty);
2718 llvm::Constant *Zeros[] = { Zero, Zero };
2721 if (!ConstantStringClassRef) {
2722 std::string StringClass(
getLangOpts().ObjCConstantStringClass);
2727 StringClass.empty() ?
"OBJC_CLASS_$_NSConstantString"
2728 :
"OBJC_CLASS_$_" + StringClass;
2731 llvm::Type *PTy = llvm::PointerType::getUnqual(Ty);
2732 V = llvm::ConstantExpr::getBitCast(GV, PTy);
2733 ConstantStringClassRef = V;
2736 StringClass.empty() ?
"_NSConstantStringClassReference"
2737 :
"_" + StringClass +
"ClassReference";
2738 llvm::Type *PTy = llvm::ArrayType::get(Ty, 0);
2741 V = llvm::ConstantExpr::getGetElementPtr(PTy, GV, Zeros);
2742 ConstantStringClassRef = V;
2745 V = ConstantStringClassRef;
2747 if (!NSConstantStringType) {
2762 for (
unsigned i = 0; i < 3; ++i) {
2766 FieldTypes[i],
nullptr,
2779 llvm::Constant *Fields[3];
2782 Fields[0] = cast<llvm::ConstantExpr>(V);
2786 llvm::ConstantDataArray::getString(VMContext, Entry.first());
2788 llvm::GlobalValue::LinkageTypes
Linkage;
2790 Linkage = llvm::GlobalValue::PrivateLinkage;
2791 isConstant = !LangOpts.WritableStrings;
2793 auto *GV =
new llvm::GlobalVariable(
getModule(), C->getType(), isConstant,
2795 GV->setUnnamedAddr(
true);
2801 llvm::ConstantExpr::getGetElementPtr(GV->getValueType(), GV, Zeros);
2805 Fields[2] = llvm::ConstantInt::get(Ty, StringLength);
2808 C = llvm::ConstantStruct::get(NSConstantStringType, Fields);
2809 GV =
new llvm::GlobalVariable(
getModule(), C->getType(),
true,
2810 llvm::GlobalVariable::PrivateLinkage,
C,
2811 "_unnamed_nsstring_");
2812 const char *NSStringSection =
"__OBJC,__cstring_object,regular,no_dead_strip";
2813 const char *NSStringNonFragileABISection =
2814 "__DATA,__objc_stringobj,regular,no_dead_strip";
2817 ? NSStringNonFragileABISection
2825 if (ObjCFastEnumerationStateType.
isNull()) {
2837 for (
size_t i = 0; i < 4; ++i) {
2842 FieldTypes[i],
nullptr,
2854 return ObjCFastEnumerationStateType;
2868 Str.resize(CAT->getSize().getZExtValue());
2869 return llvm::ConstantDataArray::getString(VMContext, Str,
false);
2873 llvm::Type *ElemTy = AType->getElementType();
2874 unsigned NumElements = AType->getNumElements();
2877 if (ElemTy->getPrimitiveSizeInBits() == 16) {
2879 Elements.reserve(NumElements);
2881 for(
unsigned i = 0, e = E->
getLength(); i != e; ++i)
2883 Elements.resize(NumElements);
2884 return llvm::ConstantDataArray::get(VMContext, Elements);
2887 assert(ElemTy->getPrimitiveSizeInBits() == 32);
2889 Elements.reserve(NumElements);
2891 for(
unsigned i = 0, e = E->
getLength(); i != e; ++i)
2893 Elements.resize(NumElements);
2894 return llvm::ConstantDataArray::get(VMContext, Elements);
2897 static llvm::GlobalVariable *
2900 unsigned Alignment) {
2902 unsigned AddrSpace = 0;
2908 auto *GV =
new llvm::GlobalVariable(
2909 M, C->getType(), !CGM.
getLangOpts().WritableStrings, LT,
C, GlobalName,
2910 nullptr, llvm::GlobalVariable::NotThreadLocal, AddrSpace);
2911 GV->setAlignment(Alignment);
2912 GV->setUnnamedAddr(
true);
2913 if (GV->isWeakForLinker()) {
2914 assert(CGM.
supportsCOMDAT() &&
"Only COFF uses weak string literals");
2915 GV->setComdat(M.getOrInsertComdat(GV->getName()));
2923 llvm::GlobalVariable *
2930 llvm::GlobalVariable **Entry =
nullptr;
2931 if (!LangOpts.WritableStrings) {
2932 Entry = &ConstantStringMap[
C];
2933 if (
auto GV = *Entry) {
2934 if (Alignment > GV->getAlignment())
2935 GV->setAlignment(Alignment);
2941 StringRef GlobalVariableName;
2942 llvm::GlobalValue::LinkageTypes LT;
2947 if (!LangOpts.WritableStrings &&
2950 llvm::raw_svector_ostream Out(MangledNameBuffer);
2954 LT = llvm::GlobalValue::LinkOnceODRLinkage;
2955 GlobalVariableName = MangledNameBuffer;
2957 LT = llvm::GlobalValue::PrivateLinkage;
2958 GlobalVariableName = Name;
2965 SanitizerMD->reportGlobalToASan(GV, S->
getStrTokenLoc(0),
"<string literal>",
2972 llvm::GlobalVariable *
2984 const std::string &Str,
const char *GlobalName,
unsigned Alignment) {
2985 StringRef StrWithNull(Str.c_str(), Str.size() + 1);
2986 if (Alignment == 0) {
2993 llvm::ConstantDataArray::getString(
getLLVMContext(), StrWithNull,
false);
2996 llvm::GlobalVariable **Entry =
nullptr;
2997 if (!LangOpts.WritableStrings) {
2998 Entry = &ConstantStringMap[
C];
2999 if (
auto GV = *Entry) {
3000 if (Alignment > GV->getAlignment())
3001 GV->setAlignment(Alignment);
3008 GlobalName =
".str";
3011 GlobalName, Alignment);
3027 MaterializedType = E->
getType();
3029 llvm::Constant *&Slot = MaterializedGlobalTemporaryMap[E];
3037 llvm::raw_svector_ostream Out(Name);
3057 Value = &EvalResult.
Val;
3059 llvm::Constant *InitialValue =
nullptr;
3060 bool Constant =
false;
3066 Type = InitialValue->getType();
3074 llvm::GlobalValue::LinkageTypes Linkage =
3078 if (VD->isStaticDataMember() && VD->getAnyInitializer(InitVD) &&
3082 Linkage = llvm::GlobalVariable::LinkOnceODRLinkage;
3090 VD,
getContext().getTargetAddressSpace(MaterializedType));
3091 auto *GV =
new llvm::GlobalVariable(
3092 getModule(),
Type, Constant, Linkage, InitialValue, Name.c_str(),
3093 nullptr, llvm::GlobalVariable::NotThreadLocal,
3097 getContext().getTypeAlignInChars(MaterializedType).getQuantity());
3099 GV->setComdat(TheModule.getOrInsertComdat(GV->getName()));
3100 if (VD->getTLSKind())
3108 void CodeGenModule::EmitObjCPropertyImplementations(
const
3122 const_cast<ObjCImplementationDecl *>(D), PID);
3126 const_cast<ObjCImplementationDecl *>(D), PID);
3135 if (ivar->getType().isDestructedType())
3198 void CodeGenModule::EmitNamespace(
const NamespaceDecl *ND) {
3199 for (
auto *I : ND->
decls()) {
3200 if (
const auto *VD = dyn_cast<VarDecl>(I))
3216 for (
auto *I : LSD->
decls()) {
3219 if (
auto *OID = dyn_cast<ObjCImplDecl>(I)) {
3220 for (
auto *M : OID->methods())
3234 case Decl::CXXConversion:
3235 case Decl::CXXMethod:
3236 case Decl::Function:
3238 if (cast<FunctionDecl>(D)->getDescribedFunctionTemplate() ||
3239 cast<FunctionDecl>(D)->isLateTemplateParsed())
3250 if (cast<VarDecl>(D)->getDescribedVarTemplate())
3252 case Decl::VarTemplateSpecialization:
3258 case Decl::IndirectField:
3262 case Decl::Namespace:
3263 EmitNamespace(cast<NamespaceDecl>(D));
3266 case Decl::UsingShadow:
3267 case Decl::ClassTemplate:
3268 case Decl::VarTemplate:
3269 case Decl::VarTemplatePartialSpecialization:
3270 case Decl::FunctionTemplate:
3271 case Decl::TypeAliasTemplate:
3277 DI->EmitUsingDecl(cast<UsingDecl>(*D));
3279 case Decl::NamespaceAlias:
3281 DI->EmitNamespaceAlias(cast<NamespaceAliasDecl>(*D));
3283 case Decl::UsingDirective:
3285 DI->EmitUsingDirective(cast<UsingDirectiveDecl>(*D));
3287 case Decl::CXXConstructor:
3289 if (cast<FunctionDecl>(D)->getDescribedFunctionTemplate() ||
3290 cast<FunctionDecl>(D)->isLateTemplateParsed())
3295 case Decl::CXXDestructor:
3296 if (cast<FunctionDecl>(D)->isLateTemplateParsed())
3301 case Decl::StaticAssert:
3308 case Decl::ObjCInterface:
3309 case Decl::ObjCCategory:
3312 case Decl::ObjCProtocol: {
3313 auto *Proto = cast<ObjCProtocolDecl>(D);
3314 if (Proto->isThisDeclarationADefinition())
3319 case Decl::ObjCCategoryImpl:
3322 ObjCRuntime->GenerateCategory(cast<ObjCCategoryImplDecl>(D));
3325 case Decl::ObjCImplementation: {
3326 auto *OMD = cast<ObjCImplementationDecl>(D);
3327 EmitObjCPropertyImplementations(OMD);
3328 EmitObjCIvarInitializations(OMD);
3333 DI->getOrCreateInterfaceType(
getContext().getObjCInterfaceType(
3334 OMD->getClassInterface()), OMD->getLocation());
3337 case Decl::ObjCMethod: {
3338 auto *OMD = cast<ObjCMethodDecl>(D);
3344 case Decl::ObjCCompatibleAlias:
3345 ObjCRuntime->RegisterAlias(cast<ObjCCompatibleAliasDecl>(D));
3348 case Decl::LinkageSpec:
3349 EmitLinkageSpec(cast<LinkageSpecDecl>(D));
3352 case Decl::FileScopeAsm: {
3354 if (LangOpts.CUDA && LangOpts.CUDAIsDevice)
3356 auto *AD = cast<FileScopeAsmDecl>(D);
3357 getModule().appendModuleInlineAsm(AD->getAsmString()->getString());
3361 case Decl::Import: {
3362 auto *Import = cast<ImportDecl>(D);
3365 if (
clang::Module *Owner = Import->getImportedOwningModule()) {
3371 DI->EmitImportDecl(*Import);
3373 ImportedModules.insert(Import->getImportedModule());
3377 case Decl::OMPThreadPrivate:
3381 case Decl::ClassTemplateSpecialization: {
3382 const auto *Spec = cast<ClassTemplateSpecializationDecl>(D);
3385 Spec->hasDefinition())
3394 assert(isa<TypeDecl>(D) &&
"Unsupported decl kind");
3401 if (!CodeGenOpts.CoverageMapping)
3404 case Decl::CXXConversion:
3405 case Decl::CXXMethod:
3406 case Decl::Function:
3407 case Decl::ObjCMethod:
3408 case Decl::CXXConstructor:
3409 case Decl::CXXDestructor: {
3410 if (!cast<FunctionDecl>(D)->hasBody())
3412 auto I = DeferredEmptyCoverageMappingDecls.find(D);
3413 if (I == DeferredEmptyCoverageMappingDecls.end())
3414 DeferredEmptyCoverageMappingDecls[D] =
true;
3424 if (!CodeGenOpts.CoverageMapping)
3426 if (
const auto *Fn = dyn_cast<FunctionDecl>(D)) {
3427 if (Fn->isTemplateInstantiation())
3430 auto I = DeferredEmptyCoverageMappingDecls.find(D);
3431 if (I == DeferredEmptyCoverageMappingDecls.end())
3432 DeferredEmptyCoverageMappingDecls[D] =
false;
3438 std::vector<const Decl *> DeferredDecls;
3439 for (
const auto &I : DeferredEmptyCoverageMappingDecls) {
3442 DeferredDecls.push_back(I.first);
3446 if (CodeGenOpts.DumpCoverageMapping)
3447 std::sort(DeferredDecls.begin(), DeferredDecls.end(),
3448 [] (
const Decl *LHS,
const Decl *RHS) {
3451 for (
const auto *D : DeferredDecls) {
3453 case Decl::CXXConversion:
3454 case Decl::CXXMethod:
3455 case Decl::Function:
3456 case Decl::ObjCMethod: {
3463 case Decl::CXXConstructor: {
3470 case Decl::CXXDestructor: {
3486 uintptr_t PtrInt =
reinterpret_cast<uintptr_t
>(Ptr);
3487 llvm::Type *i64 = llvm::Type::getInt64Ty(Context);
3488 return llvm::ConstantInt::get(i64, PtrInt);
3492 llvm::NamedMDNode *&GlobalMetadata,
3494 llvm::GlobalValue *Addr) {
3495 if (!GlobalMetadata)
3497 CGM.
getModule().getOrInsertNamedMetadata(
"clang.global.decl.ptrs");
3500 llvm::Metadata *Ops[] = {llvm::ConstantAsMetadata::get(Addr),
3503 GlobalMetadata->addOperand(llvm::MDNode::get(CGM.
getLLVMContext(), Ops));
3511 void CodeGenModule::EmitStaticExternCAliases() {
3512 for (
auto &I : StaticExternCValues) {
3514 llvm::GlobalValue *Val = I.second;
3522 auto Res = Manglings.find(MangledName);
3523 if (Res == Manglings.end())
3525 Result = Res->getValue();
3536 void CodeGenModule::EmitDeclMetadata() {
3537 llvm::NamedMDNode *GlobalMetadata =
nullptr;
3540 for (
auto &I : MangledDeclNames) {
3541 llvm::GlobalValue *Addr =
getModule().getNamedValue(I.second);
3548 void CodeGenFunction::EmitDeclMetadata() {
3549 if (LocalDeclMap.empty())
return;
3554 unsigned DeclPtrKind = Context.getMDKindID(
"clang.decl.ptr");
3556 llvm::NamedMDNode *GlobalMetadata =
nullptr;
3558 for (
auto &I : LocalDeclMap) {
3559 const Decl *D = I.first;
3561 if (
auto *Alloca = dyn_cast<llvm::AllocaInst>(Addr)) {
3563 Alloca->setMetadata(
3564 DeclPtrKind, llvm::MDNode::get(
3565 Context, llvm::ValueAsMetadata::getConstant(DAddr)));
3566 }
else if (
auto *GV = dyn_cast<llvm::GlobalValue>(Addr)) {
3573 void CodeGenModule::EmitVersionIdentMetadata() {
3574 llvm::NamedMDNode *IdentMetadata =
3575 TheModule.getOrInsertNamedMetadata(
"llvm.ident");
3577 llvm::LLVMContext &Ctx = TheModule.getContext();
3579 llvm::Metadata *IdentNode[] = {llvm::MDString::get(Ctx, Version)};
3580 IdentMetadata->addOperand(llvm::MDNode::get(Ctx, IdentNode));
3583 void CodeGenModule::EmitTargetMetadata() {
3590 for (
unsigned I = 0; I != MangledDeclNames.size(); ++I) {
3591 auto Val = *(MangledDeclNames.begin() + I);
3598 void CodeGenModule::EmitCoverageFile() {
3600 if (llvm::NamedMDNode *CUNode = TheModule.getNamedMetadata(
"llvm.dbg.cu")) {
3601 llvm::NamedMDNode *GCov = TheModule.getOrInsertNamedMetadata(
"llvm.gcov");
3602 llvm::LLVMContext &Ctx = TheModule.getContext();
3603 llvm::MDString *CoverageFile =
3605 for (
int i = 0, e = CUNode->getNumOperands(); i != e; ++i) {
3606 llvm::MDNode *CU = CUNode->getOperand(i);
3607 llvm::Metadata *Elts[] = {CoverageFile, CU};
3608 GCov->addOperand(llvm::MDNode::get(Ctx, Elts));
3614 llvm::Constant *CodeGenModule::EmitUuidofInitializer(StringRef Uuid) {
3617 assert(Uuid.size() == 36);
3618 for (
unsigned i = 0; i < 36; ++i) {
3619 if (i == 8 || i == 13 || i == 18 || i == 23) assert(Uuid[i] ==
'-');
3624 const unsigned Field3ValueOffsets[8] = { 19, 21, 24, 26, 28, 30, 32, 34 };
3626 llvm::Constant *Field3[8];
3627 for (
unsigned Idx = 0; Idx < 8; ++Idx)
3628 Field3[Idx] = llvm::ConstantInt::get(
3629 Int8Ty, Uuid.substr(Field3ValueOffsets[Idx], 2), 16);
3631 llvm::Constant *Fields[4] = {
3632 llvm::ConstantInt::get(
Int32Ty, Uuid.substr(0, 8), 16),
3633 llvm::ConstantInt::get(
Int16Ty, Uuid.substr(9, 4), 16),
3634 llvm::ConstantInt::get(
Int16Ty, Uuid.substr(14, 4), 16),
3635 llvm::ConstantArray::get(llvm::ArrayType::get(
Int8Ty, 8), Field3)
3638 return llvm::ConstantStruct::getAnon(Fields);
3653 return llvm::Constant::getNullValue(
Int8PtrTy);
3663 for (
auto RefExpr : D->
varlists()) {
3664 auto *VD = cast<VarDecl>(cast<DeclRefExpr>(RefExpr)->getDecl());
3666 VD->getAnyInitializer() &&
3667 !VD->getAnyInitializer()->isConstantInitializer(
getContext(),
3671 CXXGlobalInits.push_back(InitFunction);
3677 std::string OutName;
3678 llvm::raw_string_ostream Out(OutName);
3681 llvm::Metadata *BitsetOps[] = {
3683 llvm::ConstantAsMetadata::get(VTable),
3684 llvm::ConstantAsMetadata::get(
void setLinkage(Linkage L)
llvm::Constant * GetAddrOfConstantCFString(const StringLiteral *Literal)
Return a pointer to a constant CFString object for the given string.
llvm::PointerType * Int8PtrPtrTy
llvm::MDNode * getTBAAStructTypeInfo(QualType QTy)
Return the MDNode in the type DAG for the given struct type.
Defines the clang::ASTContext interface.
llvm::IntegerType * IntTy
int
const ABIInfo & getABIInfo() const
getABIInfo() - Returns ABI info helper for the target.
External linkage, which indicates that the entity can be referred to from other translation units...
StringRef getName() const
void EmitDeferredUnusedCoverageMappings()
Emit all the deferred coverage mappings for the uninstrumented functions.
Smart pointer class that efficiently represents Objective-C method names.
Holds information about both target-independent and target-specific builtins, allowing easy queries b...
GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const
TemplateSpecializationKind getTemplateSpecializationKind() const
If this variable is an instantiation of a variable template or a static data member of a class templa...
CodeGenTypes & getTypes()
GlobalDecl getWithDecl(const Decl *D)
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
void UpdateCompletedType(const TagDecl *TD)
CXXCtorType getCtorType() const
llvm::Module & getModule() const
RecordDecl * buildImplicitRecord(StringRef Name, RecordDecl::TagKind TK=TTK_Struct) const
Create a new implicit TU-level CXXRecordDecl or RecordDecl declaration.
llvm::LLVMContext & getLLVMContext()
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number...
submodule_iterator submodule_begin()
llvm::CallingConv::ID BuiltinCC
StringRef getUuidAsStringRef(ASTContext &Context) const
SanitizerSet Sanitize
Set of enabled sanitizers.
virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, raw_ostream &)=0
Expr * GetTemporaryExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue...
Defines the SourceManager interface.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
bool isRecordType() const
virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, raw_ostream &)=0
Defines the clang::Module class, which describes a module in the source code.
llvm::MDNode * getTBAAStructInfo(QualType QTy)
virtual llvm::GlobalVariable * GetClassGlobal(const std::string &Name, bool Weak=false)=0
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
void setAliasAttributes(const Decl *D, llvm::GlobalValue *GV)
Defines the C++ template declaration subclasses.
llvm::CallingConv::ID getRuntimeCC() const
bool isAlignmentRequired(const Type *T) const
Determine if the alignment the type has was required using an alignment attribute.
llvm::Type * FloatTy
float, double
std::string getAsString() const
const llvm::DataLayout & getDataLayout() const
FullSourceLoc getFullLoc(SourceLocation Loc) const
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
void setFunctionLinkage(GlobalDecl GD, llvm::Function *F)
Stores additional source code information like skipped ranges which is required by the coverage mappi...
void GenerateObjCSetter(ObjCImplementationDecl *IMP, const ObjCPropertyImplDecl *PID)
Generate an Objective-C property setter function.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
const Expr * getInit() const
NamespaceDecl - Represent a C++ namespace.
static void setLinkageAndVisibilityForGV(llvm::GlobalValue *GV, const NamedDecl *ND)
virtual void completeDefinition()
bool isWeakImported() const
Determine whether this is a weak-imported symbol.
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a prvalue temporary that is written into memory so that a reference can bind to it...
static llvm::GlobalValue::VisibilityTypes GetLLVMVisibility(Visibility V)
llvm::Constant * EmitConstantValue(const APValue &Value, QualType DestType, CodeGenFunction *CGF=nullptr)
void HandleCXXStaticMemberVarInstantiation(VarDecl *VD)
Tell the consumer that this variable has been instantiated.
Expr * getInit() const
Get the initializer.
TLSKind getTLSKind() const
void setFunctionDefinitionAttributes(const FunctionDecl *D, llvm::Function *F)
Set attributes for a global definition.
CGDebugInfo * getModuleDebugInfo()
void setFunctionDLLStorageClass(GlobalDecl GD, llvm::Function *F)
Set the DLL storage class on F.
CharUnits GetTargetTypeStoreSize(llvm::Type *Ty) const
Return the store size, in character units, of the given LLVM type.
QualType getThisType(ASTContext &C) const
Returns the type of the this pointer.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr)
void DecorateInstruction(llvm::Instruction *Inst, llvm::MDNode *TBAAInfo, bool ConvertTypeToTag=true)
llvm::Type * ConvertTypeForMem(QualType T)
void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD)
llvm::GlobalVariable * GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *)
Return a pointer to a constant array for the given ObjCEncodeExpr node.
llvm::Constant * getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType)
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
llvm::GlobalVariable * GetAddrOfConstantStringFromLiteral(const StringLiteral *S, StringRef Name=".str")
Return a pointer to a constant array for the given string literal.
QualType withConst() const
Retrieves a version of this type with const applied. Note that this does not always yield a canonical...
llvm::CallingConv::ID getRuntimeCC() const
GlobalDecl getCanonicalDecl() const
Visibility getVisibility() const
unsigned getMaxAlignment() const
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
llvm::IntegerType * Int64Ty
virtual void mangleCXXVTableBitSet(const CXXRecordDecl *RD, raw_ostream &)=0
bool isReferenceType() const
static CGCXXABI * createCXXABI(CodeGenModule &CGM)
llvm::IntegerType * SizeTy
unsigned getManglingNumber() const
StructorType getFromDtorType(CXXDtorType T)
void startDefinition()
Starts the definition of this tag declaration.
This declaration is definitely a definition.
void GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, ObjCMethodDecl *MD, bool ctor)
llvm::MDNode * getTBAAInfoForVTablePtr()
llvm::Constant * CreateBuiltinFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeSet ExtraAttrs=llvm::AttributeSet())
Create a new compiler builtin function with the specified type and name.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
llvm::CallingConv::ID RuntimeCC
const Decl * getDecl() const
Linkage getLinkage() const
Describes a module or submodule.
bool shouldMangleDeclName(const NamedDecl *D)
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
llvm::Constant * GetConstantArrayFromStringLiteral(const StringLiteral *E)
Return a constant array for the given string.
static void EmitGlobalDeclMetadata(CodeGenModule &CGM, llvm::NamedMDNode *&GlobalMetadata, GlobalDecl D, llvm::GlobalValue *Addr)
CGOpenMPRuntime(CodeGenModule &CGM)
static llvm::GlobalVariable * GenerateStringLiteral(llvm::Constant *C, llvm::GlobalValue::LinkageTypes LT, CodeGenModule &CGM, StringRef GlobalName, unsigned Alignment)
bool isBlacklistedLocation(SourceLocation Loc, StringRef Category=StringRef()) const
uint32_t getCodeUnit(size_t i) const
const TargetInfo & getTargetInfo() const
const LangOptions & getLangOpts() const
unsigned getLength() const
APValue Val
Val - This is the value the expression can be folded to.
const ValueDecl * getExtendingDecl() const
Get the declaration which triggered the lifetime-extension of this temporary, if any.
virtual void mangleReferenceTemporary(const VarDecl *D, unsigned ManglingNumber, raw_ostream &)=0
llvm::GlobalVariable * GetAddrOfConstantCString(const std::string &Str, const char *GlobalName=nullptr, unsigned Alignment=0)
unsigned char PointerWidthInBits
The width of a pointer into the generic address space.
field_range fields() const
llvm::PointerType * VoidPtrTy
Concrete class used by the front-end to report problems and issues.
CGObjCRuntime * CreateMacObjCRuntime(CodeGenModule &CGM)
Module * Parent
The parent of this module. This will be NULL for the top-level module.
Selector getSetterName() const
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr * > VL, ArrayRef< Expr * > IL, Expr *Step, Expr *CalcStep)
Creates clause with a list of variables VL and a linear step Step.
const SanitizerBlacklist & getSanitizerBlacklist() const
submodule_iterator submodule_end()
llvm::MDNode * getTBAAStructTypeInfo(QualType QType)
Get the MDNode in the type DAG for given struct type QType.
void addCompilerUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.compiler.used metadata.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Def If non-NULL, and the type refers to some kind of declaration that can be completed (such as a C s...
llvm::Constant * CreateRuntimeVariable(llvm::Type *Ty, StringRef Name)
Create a new runtime global variable with the specified type and name.
DeclContext * getLexicalDeclContext()
bool isStaticLocal() const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
void EmitTentativeDefinition(const VarDecl *D)
unsigned getLine() const
Return the presumed line number of this location.
void addInstanceMethod(ObjCMethodDecl *method)
A class that does preorder depth-first traversal on the entire Clang AST and visits each node...
Represents an ObjC class declaration.
propimpl_range property_impls() const
Represents a linkage specification.
void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const
Set the visibility for the given LLVM GlobalValue.
const CGFunctionInfo & arrangeGlobalDeclaration(GlobalDecl GD)
std::vector< Module * >::iterator submodule_iterator
void mangleName(const NamedDecl *D, raw_ostream &)
bool isTypeConstant(QualType QTy, bool ExcludeCtorDtor)
bool hasUnwindExceptions() const
Does this runtime use zero-cost exceptions?
llvm::StringMap< SectionInfo > SectionInfos
static bool hasUnwindExceptions(const LangOptions &LangOpts)
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
static bool AllTrivialInitializers(CodeGenModule &CGM, ObjCImplementationDecl *D)
std::string CurrentModule
The name of the current module.
void setHasDestructors(bool val)
const TargetCodeGenInfo & getTargetCodeGenInfo()
void AddDetectMismatch(StringRef Name, StringRef Value)
Appends a detect mismatch command to the linker options.
const TargetInfo & getTarget() const
Represents a ValueDecl that came out of a declarator. Contains type source information through TypeSo...
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
void getObjCEncodingForType(QualType T, std::string &S, const FieldDecl *Field=nullptr, QualType *NotEncodedT=nullptr) const
Emit the Objective-CC type encoding for the given type T into S.
StringRef getBlockMangledName(GlobalDecl GD, const BlockDecl *BD)
std::vector< bool > & Stack
ID
Defines the set of possible language-specific address spaces.
static llvm::StringMapEntry< llvm::GlobalVariable * > & GetConstantStringEntry(llvm::StringMap< llvm::GlobalVariable * > &Map, const StringLiteral *Literal, unsigned &StringLength)
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
void SetLLVMFunctionAttributes(const Decl *D, const CGFunctionInfo &Info, llvm::Function *F)
Set the LLVM function attributes (sext, zext, etc).
llvm::Constant * EmitAnnotationUnit(SourceLocation Loc)
Emit the annotation's translation unit.
bool isMSStaticDataMemberInlineDefinition(const VarDecl *VD) const
Returns true if this is an inline-initialized static data member which is treated as a definition for...
virtual void EmitCXXConstructors(const CXXConstructorDecl *D)=0
Emit constructor variants required by this ABI.
StringRef getName() const
Return the actual identifier string.
CXXDtorType getDtorType() const
static ObjCMethodDecl * Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl, bool isInstance=true, bool isVariadic=false, bool isPropertyAccessor=false, bool isImplicitlyDeclared=false, bool isDefined=false, ImplementationControl impControl=None, bool HasRelatedResultType=false)
virtual void EmitCXXDestructors(const CXXDestructorDecl *D)=0
Emit destructor variants required by this ABI.
CGCXXABI & getCXXABI() const
virtual llvm::Constant * getAddrOfCXXCatchHandlerType(QualType Ty, QualType CatchHandlerType)=0
void AddGlobalAnnotations(const ValueDecl *D, llvm::GlobalValue *GV)
static void addLinkOptionsPostorder(CodeGenModule &CGM, Module *Mod, SmallVectorImpl< llvm::Metadata * > &Metadata, llvm::SmallPtrSet< Module *, 16 > &Visited)
Add link options implied by the given module, including modules it depends on, using a postorder walk...
llvm::MDNode * getTBAAScalarTagInfo(llvm::MDNode *AccessNode)
Get the scalar tag MDNode for a given scalar type.
void GenerateObjCMethod(const ObjCMethodDecl *OMD)
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
void SetInternalFunctionAttributes(const Decl *D, llvm::Function *F, const CGFunctionInfo &FI)
Organizes the cross-function state that is used while generating code coverage mapping data...
void reportDiagnostics(DiagnosticsEngine &Diags, StringRef MainFile)
Report potential problems we've found to Diags.
Defines version macros and version-related utility functions for Clang.
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const
const char * getBufferName(SourceLocation Loc, bool *Invalid=nullptr) const
Return the filename or buffer identifier of the buffer the location is in.
DeclContext * getDeclContext()
ASTContext & getContext() const
unsigned getExpansionLineNumber(SourceLocation Loc, bool *Invalid=nullptr) const
static llvm::StringMapEntry< llvm::GlobalVariable * > & GetConstantCFStringEntry(llvm::StringMap< llvm::GlobalVariable * > &Map, const StringLiteral *Literal, bool TargetIsLSB, bool &IsUTF16, unsigned &StringLength)
llvm::SmallVector< LinkLibrary, 2 > LinkLibraries
The set of libraries or frameworks to link against when an entity from this module is used...
virtual void getDetectMismatchOption(llvm::StringRef Name, llvm::StringRef Value, llvm::SmallString< 32 > &Opt) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
llvm::IntegerType * Int32Ty
virtual void getDependentLibraryOption(llvm::StringRef Lib, llvm::SmallString< 24 > &Opt) const
llvm::GlobalValue::LinkageTypes getLLVMLinkageVarDefinition(const VarDecl *VD, bool IsConstant)
Returns LLVM linkage for a declarator.
clang::ObjCRuntime ObjCRuntime
llvm::Constant * EmitAnnotationString(StringRef Str)
Emit an annotation string.
QualType getObjCIdType() const
Represents the Objective-CC id type.
bool isExternallyVisible(Linkage L)
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD)
Represents an unpacked "presumed" location which can be presented to the user.
static bool isVarDeclStrongDefinition(const ASTContext &Context, CodeGenModule &CGM, const VarDecl *D, bool NoCommon)
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type * > Tys=None)
llvm::Constant * GetAddrOfUuidDescriptor(const CXXUuidofExpr *E)
Get the address of a uuid descriptor .
The result type of a method or function.
'gnustep' is the modern non-fragile GNUstep runtime.
bool lookupRepresentativeDecl(StringRef MangledName, GlobalDecl &Result) const
CallingConv
CallingConv - Specifies the calling convention that a function uses.
QualType getWideCharType() const
Return the type of wide characters. In C++, this returns the unique wchar_t type. In C99...
llvm::GlobalVariable * CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage)
const Expr * getAnyInitializer() const
llvm::Constant * EmitAnnotateAttr(llvm::GlobalValue *GV, const AnnotateAttr *AA, SourceLocation L)
init_iterator init_begin()
init_begin() - Retrieve an iterator to the first initializer.
llvm::CallingConv::ID getBuiltinCC() const
Return the calling convention to use for compiler builtins.
llvm::Constant * GetWeakRefReference(const ValueDecl *VD)
Get a reference to the target of VD.
SourceLocation getLocStart() const LLVM_READONLY
virtual llvm::Function * makeModuleDtorFunction()=0
bool doesThisDeclarationHaveABody() const
llvm::CallingConv::ID getBuiltinCC() const
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
SelectorTable & Selectors
llvm::Constant * CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeSet ExtraAttrs=llvm::AttributeSet())
Create a new runtime function with the specified type and name.
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
uint64_t getPointerAlign(unsigned AddrSpace) const
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV)
If the declaration has internal linkage but is inside an extern "C" linkage specification, prepare to emit an alias for it to the expected name.
const char * getFilename() const
Return the presumed filename of this location.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
virtual bool shouldMangleStringLiteral(const StringLiteral *SL)=0
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
const Type * getTypePtr() const
'objfw' is the Objective-C runtime included in ObjFW
bool hasSideEffects() const
bool isConstant(ASTContext &Ctx) const
TagDecl - Represents the declaration of a struct/union/class/enum.
llvm::IntegerType * Int16Ty
void mangleDtorBlock(const CXXDestructorDecl *CD, CXXDtorType DT, const BlockDecl *BD, raw_ostream &Out)
Represents a static or instance method of a struct/union/class.
virtual llvm::Function * emitThreadPrivateVarDefinition(const VarDecl *VD, llvm::Value *VDAddr, SourceLocation Loc, bool PerformInit, CodeGenFunction *CGF=nullptr)
Emit a code for initialization of threadprivate variable. It emits a call to runtime library which ad...
const ConstantArrayType * getAsConstantArrayType(QualType T) const
SourceLocation getStrTokenLoc(unsigned TokNum) const
std::string InstrProfileInput
Name of the profile file to use as input for -fprofile-instr-use.
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
const ObjCInterfaceDecl * getClassInterface() const
bool isTrivialInitializer(const Expr *Init)
Determine whether the given initializer is trivial in the sense that it requires no code to be genera...
llvm::MDNode * getTBAAStructTagInfo(QualType BaseTy, llvm::MDNode *AccessN, uint64_t O)
Return the path-aware tag for given base type, access node and offset.
unsigned getCharByteWidth() const
const CodeGenOptions & getCodeGenOpts() const
const Type * getBaseElementTypeUnsafe() const
LinkageInfo getLinkageAndVisibility() const
Determines the linkage and visibility of this entity.
init_iterator init_end()
init_end() - Retrieve an iterator past the last initializer.
const LangOptions & getLangOpts() const
Represents one property declaration in an Objective-C interface.
void SetLLVMFunctionAttributesForDefinition(const Decl *D, llvm::Function *F)
bool containsNonAsciiOrNull() const
bool isGNUFamily() const
Is this runtime basically of the GNU family of runtimes?
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
llvm::MDTuple * CreateVTableBitSetEntry(llvm::GlobalVariable *VTable, CharUnits Offset, const CXXRecordDecl *RD)
Create a bitset entry for the given vtable.
void EmitTopLevelDecl(Decl *D)
Emit code for a single top level declaration.
MangleContext & getMangleContext()
Gets the mangle context.
FileID getMainFileID() const
Returns the FileID of the main source file.
CGCXXABI * CreateMicrosoftCXXABI(CodeGenModule &CGM)
Creates a Microsoft-family ABI.
llvm::MDNode * getTBAAStructInfo(QualType QTy)
llvm::Constant * EmitAnnotationLineNo(SourceLocation L)
Emit the annotation line number.
unsigned getBuiltinID() const
Returns a value indicating whether this function corresponds to a builtin function.
llvm::MDNode * getTBAAStructTagInfo(QualType BaseQType, llvm::MDNode *AccessNode, uint64_t Offset)
Return a TBAA tag node for both scalar TBAA and struct-path aware TBAA.
llvm::Constant * GetAddrOfGlobalTemporary(const MaterializeTemporaryExpr *E, const Expr *Inner)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
void Error(SourceLocation loc, StringRef error)
Emit a general error that something can't be done.
void addReplacement(StringRef Name, llvm::Constant *C)
static const llvm::GlobalObject * getAliasedGlobal(const llvm::GlobalAlias &GA)
void addUsedGlobal(llvm::GlobalValue *GV)
Add a global to a list to be added to the llvm.used metadata.
ObjCIvarDecl * getNextIvar()
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T-> getSizeExpr()))
TLS with a dynamic initializer.
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
llvm::GlobalValue * GetGlobalValue(StringRef Ref)
void mangleGlobalBlock(const BlockDecl *BD, const NamedDecl *ID, raw_ostream &Out)
void mangleBlock(const DeclContext *DC, const BlockDecl *BD, raw_ostream &Out)
EvalResult is a struct with detailed info about an evaluated expression.
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=0, bool ForVTable=false, bool DontDefer=false)
void GenerateObjCGetter(ObjCImplementationDecl *IMP, const ObjCPropertyImplDecl *PID)
GenerateObjCGetter - Synthesize an Objective-C property getter function.
virtual llvm::Function * makeModuleCtorFunction()=0
unsigned char PointerAlignInBytes
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
ObjCMethodDecl * getInstanceMethod(Selector Sel, bool AllowHidden=false) const
The basic abstraction for the target Objective-C runtime.
void ConstructAttributeList(const CGFunctionInfo &Info, const Decl *TargetDecl, AttributeListType &PAL, unsigned &CallingConv, bool AttrOnCallSite)
void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const
void EmitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D)
Emit a code for threadprivate directive.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
LanguageIDs getLanguage() const
Return the language specified by this linkage specification.
llvm::IntegerType * IntPtrTy
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
Selector getGetterName() const
llvm::MDNode * getTBAAInfo(QualType QTy)
StringRef getString() const
llvm::Constant * EmitNullConstant(QualType T)
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
void UpdateCompletedType(const TagDecl *TD)
static bool needsDestructMethod(ObjCImplementationDecl *impl)
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace)
static llvm::GlobalVariable::ThreadLocalMode GetLLVMTLSModel(StringRef S)
const llvm::Triple & getTriple() const
void maybeSetTrivialComdat(const Decl &D, llvm::GlobalObject &GO)
bool isInSanitizerBlacklist(llvm::Function *Fn, SourceLocation Loc) const
void EmitThunks(GlobalDecl GD)
EmitThunks - Emit the associated thunks for the given global decl.
void AddDeferredUnusedCoverageMapping(Decl *D)
Stored a deferred empty coverage mapping for an unused and thus uninstrumented top level declaration...
Defines the Diagnostic-related interfaces.
bool isVisibilityExplicit() const
GVALinkage GetGVALinkageForVariable(const VarDecl *VD)
llvm::GlobalVariable * GetAddrOfConstantString(const StringLiteral *Literal)
void emitEmptyCounterMapping(const Decl *D, StringRef FuncName, llvm::GlobalValue::LinkageTypes Linkage)
StructorType getFromCtorType(CXXCtorType T)
void AppendLinkerOptions(StringRef Opts)
Appends Opts to the "Linker Options" metadata value.
void setHasNonZeroConstructors(bool val)
QualType getCanonicalType() const
Represents a C++ base or member initializer.
virtual llvm::Constant * getAddrOfRTTIDescriptor(QualType Ty)=0
CanQualType UnsignedLongTy
Implements C++ ABI-specific code generation functions.
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
bool hasDiagnostics()
Whether or not the stats we've gathered indicate any potential problems.
llvm::PointerType * Int8PtrTy
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
static void emitUsed(CodeGenModule &CGM, StringRef Name, std::vector< llvm::WeakVH > &List)
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
static void ReplaceUsesOfNonProtoTypeWithRealFunction(llvm::GlobalValue *Old, llvm::Function *NewFn)
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
StringRef getMangledName(GlobalDecl GD)
uint64_t getCharWidth() const
Return the size of the character type, in bits.
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
void addDecl(Decl *D)
Add the declaration D into this context.
CGCUDARuntime * CreateNVCUDARuntime(CodeGenModule &CGM)
Creates an instance of a CUDA runtime class.
unsigned getIntWidth() const
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
llvm::Constant * EmitConstantInit(const VarDecl &D, CodeGenFunction *CGF=nullptr)
static const char AnnotationSection[]
SourceManager & getSourceManager()
bool isTLSSupported() const
Whether the target supports thread-local storage.
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
DiagnosticsEngine & getDiags() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Represents a C++ struct/union/class.
CGCXXABI * CreateItaniumCXXABI(CodeGenModule &CGM)
Creates an Itanium-family ABI.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
bool isReadOnly() const
isReadOnly - Return true iff the property has a setter.
bool isObjCObjectPointerType() const
QualType getEncodedType() const
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
void Release()
Finalize LLVM code generation.
static bool shouldBeInCOMDAT(CodeGenModule &CGM, const Decl &D)
void ClearUnusedCoverageMapping(const Decl *D)
Remove the deferred empty coverage mapping as this declaration is actually instrumented.
Builtin::Context & BuiltinInfo
virtual void mangleStringLiteral(const StringLiteral *SL, raw_ostream &)=0
void EmitGlobalAnnotations()
Emit all the global annotations.
void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV)
Defines the clang::TargetInfo interface.
virtual bool useThunkForDtorVariant(const CXXDestructorDecl *Dtor, CXXDtorType DT) const =0
llvm::MDNode * getTBAAInfo(QualType QTy)
virtual void emitTargetMD(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const
QualType getObjCFastEnumerationStateType()
Retrieve the record type that describes the state of an Objective-C fast enumeration loop (for...
unsigned getTargetAddressSpace(QualType T) const
GVALinkage
A more specific kind of linkage than enum Linkage.
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type...
static llvm::Constant * GetPointerConstant(llvm::LLVMContext &Context, const void *Ptr)
Turns the given pointer into a constant.
CodeGenVTables & getVTables()
SourceLocation getLocation() const
ObjCIvarDecl * all_declared_ivar_begin()
void setAccess(AccessSpecifier AS)
static void replaceUsesOfNonProtoConstant(llvm::Constant *old, llvm::Function *newFn)
bool DeclMustBeEmitted(const Decl *D)
Determines if the decl can be CodeGen'ed or deserialized from PCH lazily, only when used; this is onl...
CharUnits getAlignOfGlobalVarInChars(QualType T) const
Return the alignment in characters that should be given to a global variable with type T...
bool isNull() const
isNull - Return true if this QualType doesn't point to a type yet.
void mangleCtorBlock(const CXXConstructorDecl *CD, CXXCtorType CT, const BlockDecl *BD, raw_ostream &Out)
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
This represents '#pragma omp threadprivate ...' directive. For example, in the following, both 'a' and 'A::b' are threadprivate:
This class handles loading and caching of source files into memory.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
void EmitGlobal(GlobalDecl D)
Defines enum values for all the target-independent builtin functions.
void AddDependentLib(StringRef Lib)
Appends a dependent lib to the "Linker Options" metadata value.
llvm::GlobalValue::LinkageTypes getLLVMLinkageForDeclarator(const DeclaratorDecl *D, GVALinkage Linkage, bool IsConstantVariable)
Returns LLVM linkage for a declarator.
Attr - This represents one attribute.
bool supportsCOMDAT() const
APValue * getMaterializedTemporaryValue(const MaterializeTemporaryExpr *E, bool MayCreate)
Get the storage for the constant value of a materialized temporary of static storage duration...
CanQualType UnsignedIntTy
llvm::MDNode * getTBAAInfoForVTablePtr()
unsigned getNumIvarInitializers() const
getNumArgs - Number of ivars which must be initialized.
CGObjCRuntime * CreateGNUObjCRuntime(CodeGenModule &CGM)
Creates an instance of an Objective-C runtime class.
bool isPointerType() const
static LLVM_READONLY bool isHexDigit(unsigned char c)
Return true if this character is an ASCII hex digit: [0-9a-fA-F].
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
QualType getCFConstantStringType() const
Return the C structure type used to represent constant CFStrings.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.