35 #include "llvm/IR/DataLayout.h" 36 #include "llvm/IR/Dominators.h" 37 #include "llvm/IR/Intrinsics.h" 38 #include "llvm/IR/MDBuilder.h" 39 #include "llvm/IR/Operator.h" 40 #include "llvm/Transforms/Utils/PromoteMemToReg.h" 41 using namespace clang;
42 using namespace CodeGen;
48 if (CGOpts.DisableLifetimeMarkers)
57 if (CGOpts.SanitizeAddressUseAfterScope)
61 return CGOpts.OptimizationLevel != 0;
64 CodeGenFunction::CodeGenFunction(
CodeGenModule &cgm,
bool suppressNewContext)
66 Builder(cgm, cgm.getModule().getContext(),
llvm::ConstantFolder(),
68 SanOpts(CGM.getLangOpts().Sanitize), DebugInfo(CGM.getModuleDebugInfo()),
70 CGM.getCodeGenOpts(), CGM.getLangOpts())) {
71 if (!suppressNewContext)
74 llvm::FastMathFlags FMF;
85 FMF.setNoSignedZeros();
88 FMF.setAllowReciprocal();
91 FMF.setAllowReassoc();
119 bool forPointeeType) {
127 if (
auto Align = TT->getDecl()->getMaxAlignment()) {
155 if (
unsigned MaxAlign =
getLangOpts().MaxTypeAlign) {
196 #define TYPE(name, parent) 197 #define ABSTRACT_TYPE(name, parent) 198 #define NON_CANONICAL_TYPE(name, parent) case Type::name: 199 #define DEPENDENT_TYPE(name, parent) case Type::name: 200 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(name, parent) case Type::name: 201 #include "clang/AST/TypeNodes.def" 202 llvm_unreachable(
"non-canonical or dependent type in IR-generation");
205 case Type::DeducedTemplateSpecialization:
206 llvm_unreachable(
"undeduced type in IR-generation");
211 case Type::BlockPointer:
212 case Type::LValueReference:
213 case Type::RValueReference:
214 case Type::MemberPointer:
216 case Type::ExtVector:
217 case Type::FunctionProto:
218 case Type::FunctionNoProto:
220 case Type::ObjCObjectPointer:
229 case Type::ConstantArray:
230 case Type::IncompleteArray:
231 case Type::VariableArray:
233 case Type::ObjCObject:
234 case Type::ObjCInterface:
239 type = cast<AtomicType>(
type)->getValueType();
242 llvm_unreachable(
"unknown type kind!");
249 llvm::BasicBlock *CurBB =
Builder.GetInsertBlock();
252 assert(!CurBB->getTerminator() &&
"Unexpected terminated block.");
261 return llvm::DebugLoc();
268 llvm::BranchInst *BI =
270 if (BI && BI->isUnconditional() &&
274 llvm::DebugLoc Loc = BI->getDebugLoc();
275 Builder.SetInsertPoint(BI->getParent());
276 BI->eraseFromParent();
287 return llvm::DebugLoc();
292 if (!BB->use_empty())
293 return CGF.
CurFn->getBasicBlockList().push_back(BB);
298 assert(BreakContinueStack.empty() &&
299 "mismatched push/pop in break/continue stack!");
301 bool OnlySimpleReturnStmts = NumSimpleReturnExprs > 0
302 && NumSimpleReturnExprs == NumReturnExprs
317 if (OnlySimpleReturnStmts)
318 DI->EmitLocation(
Builder, LastStopPoint);
320 DI->EmitLocation(
Builder, EndLoc);
328 bool HasOnlyLifetimeMarkers =
330 bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
335 if (OnlySimpleReturnStmts)
336 DI->EmitLocation(
Builder, EndLoc);
346 CurFn->addFnAttr(
"instrument-function-exit",
"__cyg_profile_func_exit");
348 CurFn->addFnAttr(
"instrument-function-exit-inlined",
349 "__cyg_profile_func_exit");
363 "did not remove all scopes from cleanup stack!");
367 if (IndirectBranch) {
374 if (!EscapedLocals.empty()) {
378 EscapeArgs.resize(EscapedLocals.size());
379 for (
auto &Pair : EscapedLocals)
380 EscapeArgs[Pair.second] = Pair.first;
381 llvm::Function *FrameEscapeFn = llvm::Intrinsic::getDeclaration(
389 Ptr->eraseFromParent();
393 if (IndirectBranch) {
394 llvm::PHINode *PN = cast<llvm::PHINode>(IndirectBranch->getAddress());
395 if (PN->getNumIncomingValues() == 0) {
396 PN->replaceAllUsesWith(llvm::UndefValue::get(PN->getType()));
397 PN->eraseFromParent();
406 for (
const auto &FuncletAndParent : TerminateFunclets)
412 for (
SmallVectorImpl<std::pair<llvm::Instruction *, llvm::Value *> >::iterator
413 I = DeferredReplacements.begin(),
414 E = DeferredReplacements.end();
416 I->first->replaceAllUsesWith(I->second);
417 I->first->eraseFromParent();
427 llvm::DominatorTree DT(*
CurFn);
428 llvm::PromoteMemToReg(
434 if (LargestVectorWidth != 0)
435 CurFn->addFnAttr(
"min-legal-vector-width",
436 llvm::utostr(LargestVectorWidth));
475 llvm::Constant *Addr) {
483 auto *GV =
new llvm::GlobalVariable(
CGM.
getModule(), Addr->getType(),
485 llvm::GlobalValue::PrivateLinkage, Addr);
488 auto *GOTAsInt = llvm::ConstantExpr::getPtrToInt(GV,
IntPtrTy);
489 auto *FuncAsInt = llvm::ConstantExpr::getPtrToInt(F,
IntPtrTy);
490 auto *PCRelAsInt = llvm::ConstantExpr::getSub(GOTAsInt, FuncAsInt);
493 : llvm::ConstantExpr::getTrunc(PCRelAsInt,
Int32Ty);
501 auto *FuncAsInt =
Builder.CreatePtrToInt(F,
IntPtrTy,
"func_addr.int");
502 auto *GOTAsInt =
Builder.CreateAdd(PCRelAsInt, FuncAsInt,
"global_addr.int");
511 std::string ReadOnlyQual(
"__read_only");
512 std::string::size_type ReadOnlyPos = TyName.find(ReadOnlyQual);
513 if (ReadOnlyPos != std::string::npos)
515 TyName.erase(ReadOnlyPos, ReadOnlyQual.size() + 1);
517 std::string WriteOnlyQual(
"__write_only");
518 std::string::size_type WriteOnlyPos = TyName.find(WriteOnlyQual);
519 if (WriteOnlyPos != std::string::npos)
520 TyName.erase(WriteOnlyPos, WriteOnlyQual.size() + 1);
522 std::string ReadWriteQual(
"__read_write");
523 std::string::size_type ReadWritePos = TyName.find(ReadWriteQual);
524 if (ReadWritePos != std::string::npos)
525 TyName.erase(ReadWritePos, ReadWriteQual.size() + 1);
577 for (
unsigned i = 0, e = FD->
getNumParams(); i != e; ++i) {
580 std::string typeQuals;
586 addressQuals.push_back(llvm::ConstantAsMetadata::get(Builder.getInt32(
590 std::string typeName =
594 std::string::size_type pos = typeName.find(
"unsigned");
595 if (pointeeTy.
isCanonical() && pos != std::string::npos)
596 typeName.erase(pos+1, 8);
598 argTypeNames.push_back(llvm::MDString::get(Context, typeName));
600 std::string baseTypeName =
606 pos = baseTypeName.find(
"unsigned");
607 if (pos != std::string::npos)
608 baseTypeName.erase(pos+1, 8);
610 argBaseTypeNames.push_back(llvm::MDString::get(Context, baseTypeName));
614 typeQuals =
"restrict";
617 typeQuals += typeQuals.empty() ?
"const" :
" const";
619 typeQuals += typeQuals.empty() ?
"volatile" :
" volatile";
621 uint32_t AddrSpc = 0;
626 addressQuals.push_back(
627 llvm::ConstantAsMetadata::get(Builder.getInt32(AddrSpc)));
630 std::string typeName;
633 .getAsString(Policy);
638 std::string::size_type pos = typeName.find(
"unsigned");
640 typeName.erase(pos+1, 8);
642 std::string baseTypeName;
645 ->getElementType().getCanonicalType()
646 .getAsString(Policy);
660 argTypeNames.push_back(llvm::MDString::get(Context, typeName));
663 pos = baseTypeName.find(
"unsigned");
664 if (pos != std::string::npos)
665 baseTypeName.erase(pos+1, 8);
667 argBaseTypeNames.push_back(llvm::MDString::get(Context, baseTypeName));
673 argTypeQuals.push_back(llvm::MDString::get(Context, typeQuals));
677 const Decl *PDecl = parm;
678 if (
auto *TD = dyn_cast<TypedefType>(ty))
679 PDecl = TD->getDecl();
680 const OpenCLAccessAttr *A = PDecl->
getAttr<OpenCLAccessAttr>();
681 if (A && A->isWriteOnly())
682 accessQuals.push_back(llvm::MDString::get(Context,
"write_only"));
683 else if (A && A->isReadWrite())
684 accessQuals.push_back(llvm::MDString::get(Context,
"read_write"));
686 accessQuals.push_back(llvm::MDString::get(Context,
"read_only"));
688 accessQuals.push_back(llvm::MDString::get(Context,
"none"));
691 argNames.push_back(llvm::MDString::get(Context, parm->
getName()));
694 Fn->setMetadata(
"kernel_arg_addr_space",
695 llvm::MDNode::get(Context, addressQuals));
696 Fn->setMetadata(
"kernel_arg_access_qual",
697 llvm::MDNode::get(Context, accessQuals));
698 Fn->setMetadata(
"kernel_arg_type",
699 llvm::MDNode::get(Context, argTypeNames));
700 Fn->setMetadata(
"kernel_arg_base_type",
701 llvm::MDNode::get(Context, argBaseTypeNames));
702 Fn->setMetadata(
"kernel_arg_type_qual",
703 llvm::MDNode::get(Context, argTypeQuals));
705 Fn->setMetadata(
"kernel_arg_name",
706 llvm::MDNode::get(Context, argNames));
709 void CodeGenFunction::EmitOpenCLKernelMetadata(
const FunctionDecl *FD,
712 if (!FD->
hasAttr<OpenCLKernelAttr>())
719 if (
const VecTypeHintAttr *A = FD->
getAttr<VecTypeHintAttr>()) {
720 QualType HintQTy = A->getTypeHint();
722 bool IsSignedInteger =
725 llvm::Metadata *AttrMDArgs[] = {
726 llvm::ConstantAsMetadata::get(llvm::UndefValue::get(
728 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
729 llvm::IntegerType::get(Context, 32),
730 llvm::APInt(32, (uint64_t)(IsSignedInteger ? 1 : 0))))};
731 Fn->setMetadata(
"vec_type_hint", llvm::MDNode::get(Context, AttrMDArgs));
734 if (
const WorkGroupSizeHintAttr *A = FD->
getAttr<WorkGroupSizeHintAttr>()) {
735 llvm::Metadata *AttrMDArgs[] = {
736 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getXDim())),
737 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getYDim())),
738 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getZDim()))};
739 Fn->setMetadata(
"work_group_size_hint", llvm::MDNode::get(Context, AttrMDArgs));
742 if (
const ReqdWorkGroupSizeAttr *A = FD->
getAttr<ReqdWorkGroupSizeAttr>()) {
743 llvm::Metadata *AttrMDArgs[] = {
744 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getXDim())),
745 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getYDim())),
746 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getZDim()))};
747 Fn->setMetadata(
"reqd_work_group_size", llvm::MDNode::get(Context, AttrMDArgs));
750 if (
const OpenCLIntelReqdSubGroupSizeAttr *A =
751 FD->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>()) {
752 llvm::Metadata *AttrMDArgs[] = {
753 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getSubGroupSize()))};
754 Fn->setMetadata(
"intel_reqd_sub_group_size",
755 llvm::MDNode::get(Context, AttrMDArgs));
761 const Stmt *Body =
nullptr;
762 if (
auto *FD = dyn_cast_or_null<FunctionDecl>(F))
764 else if (
auto *OMD = dyn_cast_or_null<ObjCMethodDecl>(F))
765 Body = OMD->getBody();
767 if (
auto *CS = dyn_cast_or_null<CompoundStmt>(Body)) {
768 auto LastStmt = CS->body_rbegin();
769 if (LastStmt != CS->body_rend())
770 return isa<ReturnStmt>(*LastStmt);
776 Fn->addFnAttr(
"sanitize_thread_no_checking_at_run_time");
777 Fn->removeFnAttr(llvm::Attribute::SanitizeThread);
781 auto *MD = dyn_cast_or_null<CXXMethodDecl>(D);
782 if (!MD || !MD->getDeclName().getAsIdentifierInfo() ||
783 !MD->getDeclName().getAsIdentifierInfo()->isStr(
"allocate") ||
784 (MD->getNumParams() != 1 && MD->getNumParams() != 2))
787 if (MD->parameters()[0]->getType().getCanonicalType() != Ctx.
getSizeType())
790 if (MD->getNumParams() == 2) {
791 auto *PT = MD->parameters()[1]->getType()->getAs<
PointerType>();
792 if (!PT || !PT->isVoidPointerType() ||
793 !PT->getPointeeType().isConstQualified())
803 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD))
817 "Do not use a CodeGenFunction object for more than one function");
821 DidCallStackSave =
false;
823 if (
const auto *FD = dyn_cast_or_null<FunctionDecl>(D))
830 assert(
CurFn->isDeclaration() &&
"Function already has body?");
835 #define SANITIZER(NAME, ID) \ 836 if (SanOpts.empty()) \ 838 if (SanOpts.has(SanitizerKind::ID)) \ 839 if (CGM.isInSanitizerBlacklist(SanitizerKind::ID, Fn, Loc)) \ 840 SanOpts.set(SanitizerKind::ID, false); 842 #include "clang/Basic/Sanitizers.def" 851 if (mask & SanitizerKind::Address)
852 SanOpts.
set(SanitizerKind::KernelAddress,
false);
853 if (mask & SanitizerKind::KernelAddress)
855 if (mask & SanitizerKind::HWAddress)
856 SanOpts.
set(SanitizerKind::KernelHWAddress,
false);
857 if (mask & SanitizerKind::KernelHWAddress)
863 if (
SanOpts.
hasOneOf(SanitizerKind::Address | SanitizerKind::KernelAddress))
864 Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
865 if (
SanOpts.
hasOneOf(SanitizerKind::HWAddress | SanitizerKind::KernelHWAddress))
866 Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
868 Fn->addFnAttr(llvm::Attribute::SanitizeThread);
870 Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
872 Fn->addFnAttr(llvm::Attribute::SafeStack);
873 if (
SanOpts.
has(SanitizerKind::ShadowCallStack))
874 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
877 if (
SanOpts.
hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
878 Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
883 if (
const auto *OMD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
884 IdentifierInfo *II = OMD->getSelector().getIdentifierInfoForSlot(0);
887 (OMD->getSelector().isUnarySelector() && II->
isStr(
".cxx_destruct"))) {
890 }
else if (
const auto *FD = dyn_cast_or_null<FunctionDecl>(D)) {
892 if (II && II->
isStr(
"__destroy_helper_block_"))
900 if (D &&
SanOpts.
has(SanitizerKind::CFIUnrelatedCast)) {
909 if (D && InstrumentXray) {
910 if (
const auto *XRayAttr = D->
getAttr<XRayInstrumentAttr>()) {
911 if (XRayAttr->alwaysXRayInstrument())
912 Fn->addFnAttr(
"function-instrument",
"xray-always");
913 if (XRayAttr->neverXRayInstrument())
914 Fn->addFnAttr(
"function-instrument",
"xray-never");
915 if (
const auto *LogArgs = D->
getAttr<XRayLogArgsAttr>()) {
916 Fn->addFnAttr(
"xray-log-args",
917 llvm::utostr(LogArgs->getArgumentCount()));
922 "xray-instruction-threshold",
928 Fn->addFnAttr(
"no-jump-tables",
933 Fn->addFnAttr(
"profile-sample-accurate");
937 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
938 EmitOpenCLKernelMetadata(FD, Fn);
944 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
951 llvm::Constant *FTRTTIConst =
953 llvm::Constant *FTRTTIConstEncoded =
955 llvm::Constant *PrologueStructElems[] = {PrologueSig,
957 llvm::Constant *PrologueStructConst =
958 llvm::ConstantStruct::getAnon(PrologueStructElems,
true);
959 Fn->setPrologueData(PrologueStructConst);
966 if (
SanOpts.
has(SanitizerKind::NullabilityReturn)) {
969 if (!(
SanOpts.
has(SanitizerKind::ReturnsNonnullAttribute) &&
971 RetValNullabilityPrecondition =
980 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
982 Fn->addFnAttr(llvm::Attribute::NoRecurse);
994 Builder.SetInsertPoint(EntryBB);
998 if (requiresReturnValueCheck()) {
1009 if (
auto *FD = dyn_cast_or_null<FunctionDecl>(D))
1011 CC = SrcFnTy->getCallConv();
1013 for (
const VarDecl *VD : Args)
1014 ArgTypes.push_back(VD->getType());
1023 CurFn->addFnAttr(
"instrument-function-entry",
"__cyg_profile_func_enter");
1025 CurFn->addFnAttr(
"instrument-function-entry-inlined",
1026 "__cyg_profile_func_enter");
1028 CurFn->addFnAttr(
"instrument-function-entry-inlined",
1029 "__cyg_profile_func_enter_bare");
1041 Fn->addFnAttr(
"fentry-call",
"true");
1043 Fn->addFnAttr(
"instrument-function-entry-inlined",
1060 auto AI =
CurFn->arg_begin();
1068 llvm::Function::arg_iterator EI =
CurFn->arg_end();
1095 if (D && isa<CXXMethodDecl>(D) && cast<CXXMethodDecl>(D)->isInstance()) {
1122 if (FD->hasCapturedVLAType()) {
1125 auto VAT = FD->getCapturedVLAType();
1126 VLASizeMap[VAT->getSizeExpr()] = ExprArg;
1133 CXXThisValue = CXXABIThisValue;
1137 if (CXXABIThisValue) {
1139 SkippedChecks.
set(SanitizerKind::ObjectSize,
true);
1147 SkippedChecks.
set(SanitizerKind::Null,
true);
1151 Loc, CXXABIThisValue, ThisTy,
1159 for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
1167 if (
const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(VD))
1168 Ty = PVD->getOriginalType();
1177 DI->EmitLocation(
Builder, StartLoc);
1183 LargestVectorWidth = VecWidth->getVectorWidth();
1189 if (
const CompoundStmt *S = dyn_cast<CompoundStmt>(Body))
1201 llvm::BasicBlock *SkipCountBB =
nullptr;
1223 if (F->isInterposable())
return;
1225 for (llvm::BasicBlock &BB : *F)
1226 for (llvm::Instruction &I : BB)
1230 F->setDoesNotThrow();
1250 bool PassedParams =
true;
1252 if (
auto Inherited = CD->getInheritedConstructor())
1258 Args.push_back(Param);
1259 if (!Param->hasAttr<PassObjectSizeAttr>())
1263 getContext(), Param->getDeclContext(), Param->getLocation(),
1265 SizeArguments[Param] = Implicit;
1266 Args.push_back(Implicit);
1270 if (MD && (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)))
1283 if (
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl()))
1284 return !ClassDecl->hasTrivialDestructor();
1298 if (FD->
hasAttr<NoDebugAttr>())
1299 DebugInfo =
nullptr;
1305 BodyRange = Body->getSourceRange();
1308 CurEHLocation = BodyRange.
getEnd();
1320 if (SpecDecl->hasBody(SpecDecl))
1321 Loc = SpecDecl->getLocation();
1327 if (Body && ShouldEmitLifetimeMarkers)
1335 if (isa<CXXDestructorDecl>(FD))
1337 else if (isa<CXXConstructorDecl>(FD))
1341 FD->
hasAttr<CUDAGlobalAttr>())
1343 else if (isa<CXXMethodDecl>(FD) &&
1344 cast<CXXMethodDecl>(FD)->isLambdaStaticInvoker()) {
1348 }
else if (FD->
isDefaulted() && isa<CXXMethodDecl>(FD) &&
1349 (cast<CXXMethodDecl>(FD)->isCopyAssignmentOperator() ||
1350 cast<CXXMethodDecl>(FD)->isMoveAssignmentOperator())) {
1357 llvm_unreachable(
"no definition for emitted function");
1367 bool ShouldEmitUnreachable =
1373 EmitCheck(std::make_pair(IsFalse, SanitizerKind::Return),
1374 SanitizerHandler::MissingReturn,
1376 }
else if (ShouldEmitUnreachable) {
1380 if (
SanOpts.
has(SanitizerKind::Return) || ShouldEmitUnreachable) {
1382 Builder.ClearInsertionPoint();
1391 if (!
CurFn->doesNotThrow())
1400 if (!S)
return false;
1407 if (isa<LabelStmt>(S))
1412 if (isa<SwitchCase>(S) && !IgnoreCaseStmts)
1416 if (isa<SwitchStmt>(S))
1417 IgnoreCaseStmts =
true;
1432 if (!S)
return false;
1436 if (isa<SwitchStmt>(S) || isa<WhileStmt>(S) || isa<DoStmt>(S) ||
1440 if (isa<BreakStmt>(S))
1452 if (!S)
return false;
1458 if (isa<IfStmt>(S) || isa<SwitchStmt>(S) || isa<WhileStmt>(S) ||
1459 isa<DoStmt>(S) || isa<ForStmt>(S) || isa<CompoundStmt>(S) ||
1460 isa<CXXForRangeStmt>(S) || isa<CXXTryStmt>(S) ||
1461 isa<ObjCForCollectionStmt>(S) || isa<ObjCAtTryStmt>(S))
1464 if (isa<DeclStmt>(S))
1480 llvm::APSInt ResultInt;
1484 ResultBool = ResultInt.getBoolValue();
1492 llvm::APSInt &ResultInt,
1514 llvm::BasicBlock *TrueBlock,
1515 llvm::BasicBlock *FalseBlock,
1516 uint64_t TrueCount) {
1519 if (
const BinaryOperator *CondBOp = dyn_cast<BinaryOperator>(Cond)) {
1522 if (CondBOp->getOpcode() == BO_LAnd) {
1525 bool ConstantBool =
false;
1568 if (CondBOp->getOpcode() == BO_LOr) {
1571 bool ConstantBool =
false;
1597 uint64_t RHSCount = TrueCount - LHSCount;
1619 if (
const UnaryOperator *CondUOp = dyn_cast<UnaryOperator>(Cond)) {
1621 if (CondUOp->getOpcode() == UO_LNot) {
1644 uint64_t LHSScaledTrueCount = 0;
1648 LHSScaledTrueCount = TrueCount * LHSRatio;
1657 LHSScaledTrueCount);
1664 TrueCount - LHSScaledTrueCount);
1670 if (
const CXXThrowExpr *Throw = dyn_cast<CXXThrowExpr>(Cond)) {
1683 llvm::MDNode *Unpredictable =
nullptr;
1684 auto *Call = dyn_cast<
CallExpr>(Cond);
1686 auto *FD = dyn_cast_or_null<FunctionDecl>(Call->getCalleeDecl());
1687 if (FD && FD->
getBuiltinID() == Builtin::BI__builtin_unpredictable) {
1689 Unpredictable = MDHelper.createUnpredictable();
1696 llvm::MDNode *Weights =
1697 createProfileWeights(TrueCount, CurrentCount - TrueCount);
1705 Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights, Unpredictable);
1733 Builder.CreateInBoundsGEP(begin.getPointer(), sizeInChars,
"vla.end");
1735 llvm::BasicBlock *originBB = CGF.
Builder.GetInsertBlock();
1743 llvm::PHINode *cur = Builder.CreatePHI(begin.getType(), 2,
"vla.cur");
1744 cur->addIncoming(begin.getPointer(), originBB);
1755 Builder.CreateInBoundsGEP(CGF.
Int8Ty, cur, baseSizeInChars,
"vla.next");
1758 llvm::Value *done = Builder.CreateICmpEQ(next, end,
"vla-init.isdone");
1759 Builder.CreateCondBr(done, contBB, loopBB);
1760 cur->addIncoming(next, loopBB);
1770 if (cast<CXXRecordDecl>(RT->getDecl())->isEmpty())
1789 dyn_cast_or_null<VariableArrayType>(
1792 SizeVal = VlaSize.NumElts;
1794 if (!eltSize.
isOne())
1815 llvm::GlobalVariable *NullVariable =
1816 new llvm::GlobalVariable(
CGM.
getModule(), NullConstant->getType(),
1818 llvm::GlobalVariable::PrivateLinkage,
1819 NullConstant, Twine());
1821 NullVariable->setAlignment(NullAlign.getQuantity());
1840 if (!IndirectBranch)
1846 IndirectBranch->addDestination(BB);
1847 return llvm::BlockAddress::get(
CurFn, BB);
1852 if (IndirectBranch)
return IndirectBranch->getParent();
1858 "indirect.goto.dest");
1861 IndirectBranch = TmpBuilder.CreateIndirectBr(DestVal);
1862 return IndirectBranch->getParent();
1875 if (isa<VariableArrayType>(arrayType)) {
1886 baseType = elementType;
1887 return numVLAElements;
1889 }
while (isa<VariableArrayType>(arrayType));
1901 llvm::ConstantInt *zero =
Builder.getInt32(0);
1902 gepIndices.push_back(zero);
1904 uint64_t countFromCLAs = 1;
1907 llvm::ArrayType *llvmArrayType =
1909 while (llvmArrayType) {
1910 assert(isa<ConstantArrayType>(arrayType));
1911 assert(cast<ConstantArrayType>(arrayType)->getSize().getZExtValue()
1912 == llvmArrayType->getNumElements());
1914 gepIndices.push_back(zero);
1915 countFromCLAs *= llvmArrayType->getNumElements();
1919 dyn_cast<llvm::ArrayType>(llvmArrayType->getElementType());
1921 assert((!llvmArrayType || arrayType) &&
1922 "LLVM and Clang types are out-of-synch");
1931 cast<ConstantArrayType>(
arrayType)->getSize().getZExtValue();
1941 gepIndices,
"array.begin"),
1948 = llvm::ConstantInt::get(
SizeTy, countFromCLAs);
1952 numElements =
Builder.CreateNUWMul(numVLAElements, numElements);
1959 assert(vla &&
"type was not a variable array type!");
1972 assert(vlaSize &&
"no size for VLA!");
1973 assert(vlaSize->getType() ==
SizeTy);
1976 numElements = vlaSize;
1980 numElements =
Builder.CreateNUWMul(numElements, vlaSize);
1982 }
while ((type =
getContext().getAsVariableArrayType(elementType)));
1984 return { numElements, elementType };
1990 assert(vla &&
"type was not a variable array type!");
1997 assert(VlaSize &&
"no size for VLA!");
1998 assert(VlaSize->getType() ==
SizeTy);
2004 "Must pass variably modified type to EmitVLASizes!");
2014 switch (ty->getTypeClass()) {
2016 #define TYPE(Class, Base) 2017 #define ABSTRACT_TYPE(Class, Base) 2018 #define NON_CANONICAL_TYPE(Class, Base) 2019 #define DEPENDENT_TYPE(Class, Base) case Type::Class: 2020 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) 2021 #include "clang/AST/TypeNodes.def" 2022 llvm_unreachable(
"unexpected dependent type!");
2028 case Type::ExtVector:
2031 case Type::Elaborated:
2032 case Type::TemplateSpecialization:
2033 case Type::ObjCTypeParam:
2034 case Type::ObjCObject:
2035 case Type::ObjCInterface:
2036 case Type::ObjCObjectPointer:
2037 llvm_unreachable(
"type class is never variably-modified!");
2039 case Type::Adjusted:
2040 type = cast<AdjustedType>(ty)->getAdjustedType();
2044 type = cast<DecayedType>(ty)->getPointeeType();
2048 type = cast<PointerType>(ty)->getPointeeType();
2051 case Type::BlockPointer:
2052 type = cast<BlockPointerType>(ty)->getPointeeType();
2055 case Type::LValueReference:
2056 case Type::RValueReference:
2057 type = cast<ReferenceType>(ty)->getPointeeType();
2060 case Type::MemberPointer:
2061 type = cast<MemberPointerType>(ty)->getPointeeType();
2064 case Type::ConstantArray:
2065 case Type::IncompleteArray:
2067 type = cast<ArrayType>(ty)->getElementType();
2070 case Type::VariableArray: {
2088 size->getType()->isSignedIntegerType()) {
2090 llvm::Value *Zero = llvm::Constant::getNullValue(Size->getType());
2091 llvm::Constant *StaticArgs[] = {
2096 SanitizerKind::VLABound),
2097 SanitizerHandler::VLABoundNotPositive, StaticArgs, Size);
2109 case Type::FunctionProto:
2110 case Type::FunctionNoProto:
2111 type = cast<FunctionType>(ty)->getReturnType();
2116 case Type::UnaryTransform:
2117 case Type::Attributed:
2118 case Type::SubstTemplateTypeParm:
2119 case Type::PackExpansion:
2125 case Type::Decltype:
2127 case Type::DeducedTemplateSpecialization:
2131 case Type::TypeOfExpr:
2137 type = cast<AtomicType>(ty)->getValueType();
2141 type = cast<PipeType>(ty)->getElementType();
2148 if (
getContext().getBuiltinVaListType()->isArrayType())
2159 assert(!Init.
isUninit() &&
"Invalid DeclRefExpr initializer!");
2162 Dbg->EmitGlobalVariable(E->
getDecl(), Init);
2177 llvm::Instruction *inst =
new llvm::BitCastInst(value, value->getType(),
"",
2181 protection.Inst = inst;
2186 if (!protection.Inst)
return;
2189 protection.Inst->eraseFromParent();
2194 StringRef AnnotationStr,
2202 return Builder.CreateCall(AnnotationFn, Args);
2206 assert(D->
hasAttr<AnnotateAttr>() &&
"no annotate attribute");
2217 assert(D->
hasAttr<AnnotateAttr>() &&
"no annotate attribute");
2249 const llvm::Twine &Name,
2250 llvm::BasicBlock *BB,
2251 llvm::BasicBlock::iterator InsertPt)
const {
2258 llvm::Instruction *I,
const llvm::Twine &Name, llvm::BasicBlock *BB,
2259 llvm::BasicBlock::iterator InsertPt)
const {
2260 llvm::IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);
2267 std::string &FirstMissing) {
2269 if (ReqFeatures.empty())
2274 llvm::StringMap<bool> CallerFeatureMap;
2280 ReqFeatures.begin(), ReqFeatures.end(), [&](StringRef Feature) {
2282 Feature.split(OrFeatures,
'|');
2283 return std::any_of(OrFeatures.begin(), OrFeatures.end(),
2284 [&](StringRef Feature) {
2285 if (!CallerFeatureMap.lookup(Feature)) {
2286 FirstMissing = Feature.str();
2312 std::string MissingFeature;
2315 const char *FeatureList =
2318 if (!FeatureList || StringRef(FeatureList) ==
"")
2320 StringRef(FeatureList).split(ReqFeatures,
',');
2326 }
else if (TargetDecl->
hasAttr<TargetAttr>() ||
2327 TargetDecl->
hasAttr<CPUSpecificAttr>()) {
2330 const TargetAttr *TD = TargetDecl->
getAttr<TargetAttr>();
2334 llvm::StringMap<bool> CalleeFeatureMap;
2337 for (
const auto &F : ParsedAttr.Features) {
2338 if (F[0] ==
'+' && CalleeFeatureMap.lookup(F.substr(1)))
2339 ReqFeatures.push_back(StringRef(F).substr(1));
2342 for (
const auto &F : CalleeFeatureMap) {
2345 ReqFeatures.push_back(F.getKey());
2357 llvm::IRBuilder<> IRB(
Builder.GetInsertBlock(),
Builder.GetInsertPoint());
2358 IRB.SetCurrentDebugLocation(
Builder.getCurrentDebugLocation());
2362 llvm::Value *CodeGenFunction::FormResolverCondition(
2371 [&FeatureList](
const std::string &Feature) {
2372 FeatureList.push_back(StringRef{Feature}.substr(1));
2374 llvm::Value *FeatureCmp = EmitX86CpuSupports(FeatureList);
2375 TrueCondition = TrueCondition ?
Builder.CreateAnd(TrueCondition, FeatureCmp)
2378 return TrueCondition;
2382 llvm::Function *Resolver,
2384 assert((
getContext().getTargetInfo().getTriple().getArch() ==
2385 llvm::Triple::x86 ||
2386 getContext().getTargetInfo().getTriple().getArch() ==
2387 llvm::Triple::x86_64) &&
2388 "Only implemented for x86 targets");
2392 Builder.SetInsertPoint(CurBlock);
2395 llvm::Function *DefaultFunc =
nullptr;
2397 Builder.SetInsertPoint(CurBlock);
2398 llvm::Value *TrueCondition = FormResolverCondition(RO);
2400 if (!TrueCondition) {
2404 llvm::IRBuilder<> RetBuilder(RetBlock);
2407 Builder.CreateCondBr(TrueCondition, RetBlock, CurBlock);
2411 assert(DefaultFunc &&
"No default version?");
2413 Builder.SetInsertPoint(CurBlock);
2414 Builder.CreateRet(DefaultFunc);
2418 llvm::Function *Resolver,
2420 assert((
getContext().getTargetInfo().getTriple().getArch() ==
2421 llvm::Triple::x86 ||
2422 getContext().getTargetInfo().getTriple().getArch() ==
2423 llvm::Triple::x86_64) &&
2424 "Only implemented for x86 targets");
2428 Builder.SetInsertPoint(CurBlock);
2432 Builder.SetInsertPoint(CurBlock);
2435 if (RO.FeatureMask == 0) {
2439 llvm::BasicBlock *RetBlock =
createBasicBlock(
"resolver_return", Resolver);
2440 llvm::IRBuilder<> RetBuilder(RetBlock);
2443 llvm::Value *TrueCondition = EmitX86CpuSupports(RO.FeatureMask);
2444 Builder.CreateCondBr(TrueCondition, RetBlock, CurBlock);
2447 Builder.SetInsertPoint(CurBlock);
2448 llvm::CallInst *TrapCall =
EmitTrapCall(llvm::Intrinsic::trap);
2449 TrapCall->setDoesNotReturn();
2450 TrapCall->setDoesNotThrow();
2452 Builder.ClearInsertionPoint();
2457 return DI->SourceLocToDebugLoc(Location);
2459 return llvm::DebugLoc();
llvm::PointerType * Int8PtrPtrTy
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Defines the clang::ASTContext interface.
Represents a function declaration or definition.
LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T)
Given a value of type T* that may not be to a complete object, construct an l-value with the natural ...
void end(CodeGenFunction &CGF)
Other implicit parameter.
no exception specification
PointerType - C99 6.7.5.1 - Pointer Declarators.
void EmitTargetMultiVersionResolver(llvm::Function *Resolver, ArrayRef< TargetMultiVersionResolverOption > Options)
A (possibly-)qualified type.
CodeGenTypes & getTypes()
llvm::Type * ConvertTypeForMem(QualType T)
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
const CodeGenOptions & getCodeGenOpts() const
bool isReturnsRetained() const
In ARC, whether this function retains its return value.
llvm::Constant * EmitCheckTypeDescriptor(QualType T)
Emit a description of a type in a format suitable for passing to a runtime sanitizer handler...
bool HaveInsertPoint() const
HaveInsertPoint - True if an insertion point is defined.
llvm::Constant * EncodeAddrForUseInPrologue(llvm::Function *F, llvm::Constant *Addr)
Encode an address into a form suitable for use in a function prologue.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
virtual void addImplicitStructorParams(CodeGenFunction &CGF, QualType &ResTy, FunctionArgList &Params)=0
Insert any ABI-specific implicit parameters into the parameter list for a function.
CharUnits getClassPointerAlignment(const CXXRecordDecl *CD)
Returns the assumed alignment of an opaque pointer to the given class.
Stmt - This represents one statement.
FunctionType - C99 6.7.5.3 - Function Declarators.
SanitizerSet Sanitize
Set of enabled sanitizers.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program...
static bool endsWithReturn(const Decl *F)
Determine whether the function F ends with a return stmt.
Checking the 'this' pointer for a constructor call.
Address EmitPointerWithAlignment(const Expr *Addr, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
EmitPointerWithAlignment - Given an expression with a pointer type, emit the value and compute our be...
constexpr XRayInstrMask Typed
Decl - This represents one declaration (or definition), e.g.
void EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc, llvm::Value *V, QualType Type, CharUnits Alignment=CharUnits::Zero(), SanitizerSet SkippedChecks=SanitizerSet())
Emit a check that V is the address of storage of the appropriate size and alignment for an object of ...
const Decl * CurCodeDecl
CurCodeDecl - This is the inner-most code context, which includes blocks.
TargetAttr::ParsedTargetAttr ParsedAttribute
void EmitLambdaStaticInvokeBody(const CXXMethodDecl *MD)
void EmitCheck(ArrayRef< std::pair< llvm::Value *, SanitizerMask >> Checked, SanitizerHandler Check, ArrayRef< llvm::Constant *> StaticArgs, ArrayRef< llvm::Value *> DynamicArgs)
Create a basic block that will call a handler function in a sanitizer runtime with the provided argum...
static void markAsIgnoreThreadCheckingAtRuntime(llvm::Function *Fn)
The base class of the type hierarchy.
bool ShouldInstrumentFunction()
ShouldInstrumentFunction - Return true if the current function should be instrumented with __cyg_prof...
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
bool usesSEHTry() const
Indicates the function uses __try.
void GenerateCode(GlobalDecl GD, llvm::Function *Fn, const CGFunctionInfo &FnInfo)
Represents an array type, per C99 6.7.5.2 - Array Declarators.
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
bool isZero() const
isZero - Test whether the quantity equals zero.
static bool hasRequiredFeatures(const SmallVectorImpl< StringRef > &ReqFeatures, CodeGenModule &CGM, const FunctionDecl *FD, std::string &FirstMissing)
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB, llvm::BasicBlock::iterator InsertPt) const
CGBuilder insert helper.
bool imbueXRayAttrs(llvm::Function *Fn, SourceLocation Loc, StringRef Category=StringRef()) const
Imbue XRay attributes to a function, applying the always/never attribute lists in the process...
constexpr XRayInstrMask Function
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a C++ constructor within a class.
bool ConstantFoldsToSimpleInteger(const Expr *Cond, bool &Result, bool AllowLabels=false)
ConstantFoldsToSimpleInteger - If the specified expression does not fold to a constant, or if it does but contains a label, return false.
QualType getElementType() const
bool empty() const
Determines whether the exception-scopes stack is empty.
This file provides some common utility functions for processing Lambda related AST Constructs...
bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer...
TypeEvaluationKind
The kind of evaluation to perform on values of a particular type.
Represents a variable declaration or definition.
QualType getReturnType() const
RAII object to set/unset CodeGenFunction::IsSanitizerScope.
const T * getAs() const
Member-template getAs<specific type>'.
Extra information about a function prototype.
static bool shouldEmitLifetimeMarkers(const CodeGenOptions &CGOpts, const LangOptions &LangOpts)
shouldEmitLifetimeMarkers - Decide whether we need emit the life-time markers.
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
LangAS
Defines the address space values used by the address space qualifier of QualType. ...
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
static bool mightAddDeclToScope(const Stmt *S)
Determine if the given statement might introduce a declaration into the current scope, by being a (possibly-labelled) DeclStmt.
DiagnosticsEngine & getDiags() const
llvm::CallInst * EmitTrapCall(llvm::Intrinsic::ID IntrID)
Emit a call to trap or debugtrap and attach function attribute "trap-func-name" if specified...
void EmitVariablyModifiedType(QualType Ty)
EmitVLASize - Capture all the sizes for the VLA expressions in the given variably-modified type and s...
void setCurrentProfileCount(uint64_t Count)
Set the profiler's current count.
bool ShouldXRayInstrumentFunction() const
ShouldXRayInstrument - Return true if the current function should be instrumented with XRay nop sleds...
llvm::Value * getPointer() const
virtual llvm::Constant * getUBSanFunctionSignature(CodeGen::CodeGenModule &CGM) const
Return a constant used by UBSan as a signature to identify functions possessing type information...
bool IsSanitizerScope
True if CodeGen currently emits code implementing sanitizer checks.
Describes how types, statements, expressions, and declarations should be printed. ...
Defines the Objective-C statement AST node classes.
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
A C++ throw-expression (C++ [except.throw]).
Represents a parameter to a function.
static void destroyBlockInfos(CGBlockInfo *info)
Destroy a chain of block layouts.
void emitImplicitAssignmentOperatorBody(FunctionArgList &Args)
EHScopeStack::stable_iterator PrologueCleanupDepth
PrologueCleanupDepth - The cleanup depth enclosing all the cleanups associated with the parameters...
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
JumpDest getJumpDestForLabel(const LabelDecl *S)
getBasicBlockForLabel - Return the LLVM basicblock that the specified label maps to.
llvm::DenseMap< const VarDecl *, FieldDecl * > LambdaCaptureFields
const TargetInfo & getTarget() const
An object to manage conditionally-evaluated expressions.
PeepholeProtection protectFromPeepholes(RValue rvalue)
protectFromPeepholes - Protect a value that we're intending to store to the side, but which will prob...
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
One of these records is kept for each identifier that is lexed.
VlaSizePair getVLAElements1D(const VariableArrayType *vla)
Return the number of elements for a single dimension for the given array type.
CGBlockInfo * FirstBlockInfo
FirstBlockInfo - The head of a singly-linked-list of block layouts.
void EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, SourceLocation EndLoc)
EmitFunctionEpilog - Emit the target specific LLVM code to return the given temporary.
Address getAddress() const
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
CGDebugInfo * getDebugInfo()
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
const NamedDecl * CurSEHParent
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
LValue EmitLValueForLambdaField(const FieldDecl *Field)
Given that we are currently emitting a lambda, emit an l-value for one of its members.
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
field_range fields() const
Represents a member of a struct/union/class.
llvm::IntegerType * SizeTy
SanitizerMask Mask
Bitmask of enabled sanitizers.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
void InitTempAlloca(Address Alloca, llvm::Value *Value)
InitTempAlloca - Provide an initial value for the given alloca which will be observable at all locati...
bool AlwaysEmitXRayTypedEvents() const
AlwaysEmitXRayTypedEvents - Return true if clang must unconditionally emit XRay typed event handling ...
ArrayRef< ParmVarDecl * > parameters() const
Address CreateIRTemp(QualType T, const Twine &Name="tmp")
CreateIRTemp - Create a temporary IR object of the given type, with appropriate alignment.
virtual void EmitInstanceFunctionProlog(CodeGenFunction &CGF)=0
Emit the ABI-specific prolog for the function.
CGCUDARuntime & getCUDARuntime()
Return a reference to the configured CUDA runtime.
QualType getThisType(ASTContext &C) const
Returns the type of the this pointer.
static bool hasScalarEvaluationKind(QualType T)
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Address CreateElementBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
Cast the element type of the given address to a different type, preserving information like the align...
CharUnits - This is an opaque type for sizes expressed in character units.
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
bool AlwaysEmitXRayCustomEvents() const
AlwaysEmitXRayCustomEvents - Return true if we must unconditionally emit XRay custom event handling c...
bool isOne() const
isOne - Test whether the quantity equals one.
TBAAAccessInfo getTBAAAccessInfo(QualType AccessType)
getTBAAAccessInfo - Get TBAA information that describes an access to an object of the given type...
CharUnits getAlignment() const
Return the alignment of this pointer.
virtual bool hasMostDerivedReturn(GlobalDecl GD) const
const clang::PrintingPolicy & getPrintingPolicy() const
unsigned getInAllocaFieldIndex() const
A builtin binary operation expression such as "x + y" or "x <= y".
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
CXXCtorType getCtorType() const
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
bool containsOnlyLifetimeMarkers(stable_iterator Old) const
bool isLambda() const
Determine whether this class describes a lambda function object.
Values of this type can never be null.
Expr * getSizeExpr() const
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
void assignRegionCounters(GlobalDecl GD, llvm::Function *Fn)
Assign counters to regions and configure them for PGO of a given function.
GlobalDecl CurGD
CurGD - The GlobalDecl for the current function being compiled.
CharUnits getPointerAlign() const
static bool ContainsLabel(const Stmt *S, bool IgnoreCaseStmts=false)
ContainsLabel - Return true if the statement contains a label in it.
bool isAlignmentRequired(const Type *T) const
Determine if the alignment the type has was required using an alignment attribute.
llvm::SanitizerStatReport & getSanStats()
llvm::DebugLoc EmitReturnBlock()
Emit the unified return block, trying to avoid its emission when possible.
bool isLambdaCallOperator(const CXXMethodDecl *MD)
llvm::Function * Function
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
uint64_t getCurrentProfileCount()
Get the profiler's current count.
Address NormalCleanupDest
i32s containing the indexes of the cleanup destinations.
virtual void emitDeviceStub(CodeGenFunction &CGF, FunctionArgList &Args)=0
Emits a kernel launch stub.
static void removeImageAccessQualifier(std::string &TyName)
void begin(CodeGenFunction &CGF)
Checking the 'this' pointer for a call to a non-static member function.
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
void InsertHelper(llvm::Instruction *I) const
Function called by the CodeGenFunction when an instruction is created.
ConditionalOperator - The ?: ternary operator.
CanQualType getReturnType() const
static CharUnits One()
One - Construct a CharUnits quantity of one.
CompoundStmt - This represents a group of statements like { stmt stmt }.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
ASTContext & getContext() const
const TargetCodeGenInfo & getTargetCodeGenInfo()
OverloadedOperatorKind getOverloadedOperator() const
getOverloadedOperator - Which C++ overloaded operator this function represents, if any...
RValue - This trivial value class is used to represent the result of an expression that is evaluated...
void EmitSanitizerStatReport(llvm::SanitizerStatKind SSK)
static void EmitIfUsed(CodeGenFunction &CGF, llvm::BasicBlock *BB)
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
llvm::Value * DecodeAddrUsedInPrologue(llvm::Value *F, llvm::Value *EncodedAddr)
Decode an address used in a function prologue, encoded by EncodeAddrForUseInPrologue.
Address CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name="tmp")
CreateDefaultAlignedTempAlloca - This creates an alloca with the default ABI alignment of the given L...
virtual bool HasThisReturn(GlobalDecl GD) const
Returns true if the given constructor or destructor is one of the kinds that the ABI says returns 'th...
void getFunctionFeatureMap(llvm::StringMap< bool > &FeatureMap, const FunctionDecl *FD)
static TypeEvaluationKind getEvaluationKind(QualType T)
getEvaluationKind - Return the TypeEvaluationKind of QualType T.
llvm::Constant * EmitAnnotationUnit(SourceLocation Loc)
Emit the annotation's translation unit.
llvm::BasicBlock * EHResumeBlock
EHResumeBlock - Unified block containing a call to llvm.eh.resume.
Expr - This represents one expression.
Emit only debug info necessary for generating line number tables (-gline-tables-only).
bool isDefaulted() const
Whether this function is defaulted per C++0x.
llvm::BasicBlock * getBlock() const
bool isObjCRetainableType() const
static void TryMarkNoThrow(llvm::Function *F)
Tries to mark the given function nounwind based on the non-existence of any throwing calls within it...
VlaSizePair getVLASize(const VariableArrayType *vla)
Returns an LLVM value that corresponds to the size, in non-variably-sized elements, of a variable length array type, plus that largest non-variably-sized element type.
const char * getRequiredFeatures(unsigned ID) const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
llvm::LLVMContext & getLLVMContext()
llvm::BasicBlock * GetIndirectGotoBlock()
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], or an enum decl which has a signed representation.
llvm::IntegerType * Int32Ty
static unsigned ArgInfoAddressSpace(LangAS AS)
void EmitConstructorBody(FunctionArgList &Args)
EmitConstructorBody - Emits the body of the current constructor.
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
llvm::Constant * EmitAnnotationString(StringRef Str)
Emit an annotation string.
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T)
llvm::CallInst * CreateMemSet(Address Dest, llvm::Value *Value, llvm::Value *Size, bool IsVolatile=false)
SourceLocation getEnd() const
QualType getFunctionTypeWithExceptionSpec(QualType Orig, const FunctionProtoType::ExceptionSpecInfo &ESI)
Get a function type and produce the equivalent function type with the specified exception specificati...
An object which temporarily prevents a value from being destroyed by aggressive peephole optimization...
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
const LangOptions & getLangOpts() const
ASTContext & getContext() const
virtual void startNewFunction()
CallingConv
CallingConv - Specifies the calling convention that a function uses.
GlobalDecl - represents a global declaration.
SanitizerScope(CodeGenFunction *CGF)
bool isConstQualified() const
Determine whether this type is const-qualified.
VarBypassDetector Bypasses
The l-value was considered opaque, so the alignment was determined from a type.
void PopCleanupBlocks(EHScopeStack::stable_iterator OldCleanupStackSize, std::initializer_list< llvm::Value **> ValuesToReload={})
Takes the old cleanup stack size and emits the cleanup blocks that have been added.
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
bool SawAsmBlock
Whether we processed a Microsoft-style asm block during CodeGen.
Address CreateBitCast(Address Addr, llvm::Type *Ty, const llvm::Twine &Name="")
QualType getCanonicalType() const
Encodes a location in the source.
void EnsureInsertPoint()
EnsureInsertPoint - Ensure that an insertion point is defined so that emitted IR has a place to go...
bool isSRetAfterThis() const
LangAS getAddressSpace() const
Return the address space of this type.
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
llvm::Value * EvaluateExprAsBool(const Expr *E)
EvaluateExprAsBool - Perform the usual unary conversions on the specified expression and compare the ...
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
bool inheritingCtorHasParams(const InheritedConstructor &Inherited, CXXCtorType Type)
Determine if a C++ inheriting constructor should have parameters matching those of its inherited cons...
CharUnits getNaturalPointeeTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr)
QualType getElementType() const
const Decl * getDecl() const
Represents the declaration of a label.
ParsedAttr - Represents a syntactic attribute.
A scoped helper to set the current debug location to the specified location or preferred location of ...
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name, llvm::BasicBlock *BB, llvm::BasicBlock::iterator InsertPt) const
This forwards to CodeGenFunction::InsertHelper.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
TargetAttr::ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD)
Parses the target attributes passed in, and returns only the ones that are valid feature names...
Represents a static or instance method of a struct/union/class.
void EmitStmt(const Stmt *S, ArrayRef< const Attr *> Attrs=None)
EmitStmt - Emit the code for the statement.
const ParmVarDecl * getParamDecl(unsigned i) const
SanitizerSet SanOpts
Sanitizers enabled for this function.
constexpr XRayInstrMask Custom
llvm::Constant * GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH=false)
Get the address of the RTTI descriptor for the given type.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
void StartFunction(GlobalDecl GD, QualType RetTy, llvm::Function *Fn, const CGFunctionInfo &FnInfo, const FunctionArgList &Args, SourceLocation Loc=SourceLocation(), SourceLocation StartLoc=SourceLocation())
Emit code for the start of a function.
XRayInstrSet XRayInstrumentationBundle
Set of XRay instrumentation kinds to emit.
TypeClass getTypeClass() const
MangleContext & getMangleContext()
Gets the mangle context.
JumpDest getJumpDestInCurrentScope(llvm::BasicBlock *Target)
The given basic block lies in the current EH scope, but may be a target of a potentially scope-crossi...
llvm::Constant * EmitAnnotationLineNo(SourceLocation L)
Emit the annotation line number.
InAlloca - Pass the argument directly using the LLVM inalloca attribute.
CharUnits getNaturalTypeAlignment(QualType T, LValueBaseInfo *BaseInfo=nullptr, TBAAAccessInfo *TBAAInfo=nullptr, bool forPointeeType=false)
bool hasImplicitReturnZero() const
Whether falling off this function implicitly returns null/zero.
Address EmitMSVAListRef(const Expr *E)
Emit a "reference" to a __builtin_ms_va_list; this is always the value of the expression, because a __builtin_ms_va_list is a pointer to a char.
const CGFunctionInfo * CurFnInfo
void EmitStartEHSpec(const Decl *D)
EmitStartEHSpec - Emit the start of the exception spec.
void FinishFunction(SourceLocation EndLoc=SourceLocation())
FinishFunction - Complete IR generation of the current function.
This is an IRBuilder insertion helper that forwards to CodeGenFunction::InsertHelper, which adds necessary metadata to instructions.
Address EmitVAListRef(const Expr *E)
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type, returning the result.
FunctionArgList - Type for representing both the decl and type of parameters to a function...
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
void ErrorUnsupported(const Stmt *S, const char *Type)
Print out an error that codegen doesn't support the specified stmt yet.
CGFunctionInfo - Class to encapsulate the information about a function definition.
This class organizes the cross-function state that is used while generating LLVM code.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &Init)
static void emitNonZeroVLAInit(CodeGenFunction &CGF, QualType baseType, Address dest, Address src, llvm::Value *sizeInChars)
emitNonZeroVLAInit - Emit the "zero" initialization of a variable-length array whose elements have a ...
Dataflow Directional Tag Classes.
Address EmitFieldAnnotations(const FieldDecl *D, Address V)
Emit field annotations for the given field & value.
static bool matchesStlAllocatorFn(const Decl *D, const ASTContext &Ctx)
void Init(const Stmt *Body)
Clear the object and pre-process for the given statement, usually function body statement.
virtual ~CGCapturedStmtInfo()
Address CreateStructGEP(Address Addr, unsigned Index, CharUnits Offset, const llvm::Twine &Name="")
llvm::Value * EmitAnnotationCall(llvm::Value *AnnotationFn, llvm::Value *AnnotatedVal, StringRef AnnotationStr, SourceLocation Location)
Emit an annotation call (intrinsic or builtin).
llvm::LoadInst * CreateAlignedLoad(llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::IntegerType * IntPtrTy
FunctionDecl * getTemplateInstantiationPattern() const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks, lambdas, etc.
SourceLocation getLocStart() const LLVM_READONLY
void buildThisParam(CodeGenFunction &CGF, FunctionArgList &Params)
Build a parameter variable suitable for 'this'.
llvm::Constant * EmitNullConstant(QualType T)
Return the result of value-initializing the given type, i.e.
llvm::Function * getIntrinsic(unsigned IID, ArrayRef< llvm::Type *> Tys=None)
llvm::SmallVector< char, 256 > LifetimeExtendedCleanupStack
bool has(XRayInstrMask K) const
llvm::Module & getModule() const
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
static void GenOpenCLArgMetadata(const FunctionDecl *FD, llvm::Function *Fn, CodeGenModule &CGM, llvm::LLVMContext &Context, CGBuilderTy &Builder, ASTContext &ASTCtx)
JumpDest ReturnBlock
ReturnBlock - Unified return block.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
void EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S)
When instrumenting to collect profile data, the counts for some blocks such as switch cases need to n...
llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Location)
Converts Location to a DebugLoc, if debug information is enabled.
CodeGenTypes & getTypes() const
CharUnits getIndirectAlign() const
llvm::Type * getElementType() const
Return the type of the values stored in this address.
llvm::PointerType * Int8PtrTy
llvm::AssertingVH< llvm::Instruction > AllocaInsertPt
AllocaInsertPoint - This is an instruction in the entry block before which we prefer to insert alloca...
ExtVectorType - Extended vector type.
QualType BuildFunctionArgList(GlobalDecl GD, FunctionArgList &Args)
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
void EmitCPUDispatchMultiVersionResolver(llvm::Function *Resolver, ArrayRef< CPUDispatchMultiVersionResolverOption > Options)
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl)
Optional< NullabilityKind > getNullability(const ASTContext &context) const
Determine the nullability of the given type.
FieldDecl * LambdaThisCaptureField
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
ABIArgInfo & getReturnInfo()
void getCaptureFields(llvm::DenseMap< const VarDecl *, FieldDecl *> &Captures, FieldDecl *&ThisCapture) const
For a closure type, retrieve the mapping from captured variables and this to the non-static data memb...
void EmitFunctionBody(FunctionArgList &Args, const Stmt *Body)
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
llvm::ConstantInt * getSize(CharUnits numChars)
Emit the given number of characters as a value of type size_t.
const Decl * CurFuncDecl
CurFuncDecl - Holds the Decl for the current outermost non-closure context.
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
void unprotectFromPeepholes(PeepholeProtection protection)
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet...
bool hasUnaligned() const
Represents a C++ struct/union/class.
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block, taking care to avoid creation of branches from dummy blocks.
unsigned getBuiltinID() const
Returns a value indicating whether this function corresponds to a builtin function.
llvm::Type * ConvertType(QualType T)
void EmitFunctionProlog(const CGFunctionInfo &FI, llvm::Function *Fn, const FunctionArgList &Args)
EmitFunctionProlog - Emit the target specific LLVM code to load the arguments for the given function...
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
static llvm::Constant * getPrologueSignature(CodeGenModule &CGM, const FunctionDecl *FD)
Return the UBSan prologue signature for FD if one is available.
LambdaCaptureDefault getLambdaCaptureDefault() const
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression...
Address ReturnValue
ReturnValue - The temporary alloca to hold the return value.
Builtin::Context & BuiltinInfo
bool AutoreleaseResult
In ARC, whether we should autorelease the return value.
RValue EmitLoadOfLValue(LValue V, SourceLocation Loc)
EmitLoadOfLValue - Given an expression that represents a value lvalue, this method emits the address ...
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
CGCXXABI & getCXXABI() const
const VariableArrayType * getAsVariableArrayType(QualType T) const
__DEVICE__ int max(int __a, int __b)
A reference to a declared variable, function, enum, etc.
static bool shouldUseUndefinedBehaviorReturnOptimization(const FunctionDecl *FD, const ASTContext &Context)
void EmitDestructorBody(FunctionArgList &Args)
EmitDestructorBody - Emits the body of the current destructor.
bool isPointerType() const
This structure provides a set of types that are commonly used during IR emission. ...
void EmitEndEHSpec(const Decl *D)
EmitEndEHSpec - Emit the end of the exception spec.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
llvm::Constant * EmitCheckSourceLocation(SourceLocation Loc)
Emit a description of a source location in a format suitable for passing to a runtime sanitizer handl...
Address EmitCompoundStmtWithoutScope(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
A trivial tuple used to represent a source range.
LValue - This represents an lvalue references.
llvm::BlockAddress * GetAddrOfLabel(const LabelDecl *L)
void EmitVarAnnotations(const VarDecl *D, llvm::Value *V)
Emit local annotations for the local variable V, declared by D.
Represents a C array with a specified size that is not an integer-constant-expression.
SanitizerMetadata * getSanitizerMetadata()
bool CurFuncIsThunk
In C++, whether we are code generating a thunk.
const LangOptions & getLangOpts() const
llvm::Value * emitArrayLength(const ArrayType *arrayType, QualType &baseType, Address &addr)
emitArrayLength - Compute the length of an array, even if it's a VLA, and drill down to the base elem...
static LValue MakeAddr(Address address, QualType type, ASTContext &Context, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
static bool containsBreak(const Stmt *S)
containsBreak - Return true if the statement contains a break out of it.
SourceLocation getBegin() const
bool isZeroInitializable(QualType T)
IsZeroInitializable - Return whether a type can be zero-initialized (in the C++ sense) with an LLVM z...
Defines enum values for all the target-independent builtin functions.
void EmitCXXThrowExpr(const CXXThrowExpr *E, bool KeepInsertionPoint=true)
Attr - This represents one attribute.
SourceLocation getLocation() const
void EmitNullInitialization(Address DestPtr, QualType Ty)
EmitNullInitialization - Generate code to set a value of the given type to null, If the type contains...
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.