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 for (llvm::Argument &A :
CurFn->args())
435 if (
auto *VT = dyn_cast<llvm::VectorType>(A.getType()))
436 LargestVectorWidth =
std::max(LargestVectorWidth,
437 VT->getPrimitiveSizeInBits());
440 if (
auto *VT = dyn_cast<llvm::VectorType>(
CurFn->getReturnType()))
441 LargestVectorWidth =
std::max(LargestVectorWidth,
442 VT->getPrimitiveSizeInBits());
451 CurFn->addFnAttr(
"min-legal-vector-width", llvm::utostr(LargestVectorWidth));
490 llvm::Constant *Addr) {
498 auto *GV =
new llvm::GlobalVariable(
CGM.
getModule(), Addr->getType(),
500 llvm::GlobalValue::PrivateLinkage, Addr);
503 auto *GOTAsInt = llvm::ConstantExpr::getPtrToInt(GV,
IntPtrTy);
504 auto *FuncAsInt = llvm::ConstantExpr::getPtrToInt(F,
IntPtrTy);
505 auto *PCRelAsInt = llvm::ConstantExpr::getSub(GOTAsInt, FuncAsInt);
508 : llvm::ConstantExpr::getTrunc(PCRelAsInt,
Int32Ty);
516 auto *FuncAsInt =
Builder.CreatePtrToInt(F,
IntPtrTy,
"func_addr.int");
517 auto *GOTAsInt =
Builder.CreateAdd(PCRelAsInt, FuncAsInt,
"global_addr.int");
526 std::string ReadOnlyQual(
"__read_only");
527 std::string::size_type ReadOnlyPos = TyName.find(ReadOnlyQual);
528 if (ReadOnlyPos != std::string::npos)
530 TyName.erase(ReadOnlyPos, ReadOnlyQual.size() + 1);
532 std::string WriteOnlyQual(
"__write_only");
533 std::string::size_type WriteOnlyPos = TyName.find(WriteOnlyQual);
534 if (WriteOnlyPos != std::string::npos)
535 TyName.erase(WriteOnlyPos, WriteOnlyQual.size() + 1);
537 std::string ReadWriteQual(
"__read_write");
538 std::string::size_type ReadWritePos = TyName.find(ReadWriteQual);
539 if (ReadWritePos != std::string::npos)
540 TyName.erase(ReadWritePos, ReadWriteQual.size() + 1);
592 for (
unsigned i = 0, e = FD->
getNumParams(); i != e; ++i) {
595 std::string typeQuals;
601 addressQuals.push_back(llvm::ConstantAsMetadata::get(Builder.getInt32(
605 std::string typeName =
609 std::string::size_type pos = typeName.find(
"unsigned");
610 if (pointeeTy.
isCanonical() && pos != std::string::npos)
611 typeName.erase(pos+1, 8);
613 argTypeNames.push_back(llvm::MDString::get(Context, typeName));
615 std::string baseTypeName =
621 pos = baseTypeName.find(
"unsigned");
622 if (pos != std::string::npos)
623 baseTypeName.erase(pos+1, 8);
625 argBaseTypeNames.push_back(llvm::MDString::get(Context, baseTypeName));
629 typeQuals =
"restrict";
632 typeQuals += typeQuals.empty() ?
"const" :
" const";
634 typeQuals += typeQuals.empty() ?
"volatile" :
" volatile";
636 uint32_t AddrSpc = 0;
641 addressQuals.push_back(
642 llvm::ConstantAsMetadata::get(Builder.getInt32(AddrSpc)));
645 std::string typeName;
648 .getAsString(Policy);
653 std::string::size_type pos = typeName.find(
"unsigned");
655 typeName.erase(pos+1, 8);
657 std::string baseTypeName;
660 ->getElementType().getCanonicalType()
661 .getAsString(Policy);
675 argTypeNames.push_back(llvm::MDString::get(Context, typeName));
678 pos = baseTypeName.find(
"unsigned");
679 if (pos != std::string::npos)
680 baseTypeName.erase(pos+1, 8);
682 argBaseTypeNames.push_back(llvm::MDString::get(Context, baseTypeName));
688 argTypeQuals.push_back(llvm::MDString::get(Context, typeQuals));
692 const Decl *PDecl = parm;
693 if (
auto *TD = dyn_cast<TypedefType>(ty))
694 PDecl = TD->getDecl();
695 const OpenCLAccessAttr *A = PDecl->
getAttr<OpenCLAccessAttr>();
696 if (A && A->isWriteOnly())
697 accessQuals.push_back(llvm::MDString::get(Context,
"write_only"));
698 else if (A && A->isReadWrite())
699 accessQuals.push_back(llvm::MDString::get(Context,
"read_write"));
701 accessQuals.push_back(llvm::MDString::get(Context,
"read_only"));
703 accessQuals.push_back(llvm::MDString::get(Context,
"none"));
706 argNames.push_back(llvm::MDString::get(Context, parm->
getName()));
709 Fn->setMetadata(
"kernel_arg_addr_space",
710 llvm::MDNode::get(Context, addressQuals));
711 Fn->setMetadata(
"kernel_arg_access_qual",
712 llvm::MDNode::get(Context, accessQuals));
713 Fn->setMetadata(
"kernel_arg_type",
714 llvm::MDNode::get(Context, argTypeNames));
715 Fn->setMetadata(
"kernel_arg_base_type",
716 llvm::MDNode::get(Context, argBaseTypeNames));
717 Fn->setMetadata(
"kernel_arg_type_qual",
718 llvm::MDNode::get(Context, argTypeQuals));
720 Fn->setMetadata(
"kernel_arg_name",
721 llvm::MDNode::get(Context, argNames));
724 void CodeGenFunction::EmitOpenCLKernelMetadata(
const FunctionDecl *FD,
727 if (!FD->
hasAttr<OpenCLKernelAttr>())
734 if (
const VecTypeHintAttr *A = FD->
getAttr<VecTypeHintAttr>()) {
735 QualType HintQTy = A->getTypeHint();
737 bool IsSignedInteger =
740 llvm::Metadata *AttrMDArgs[] = {
741 llvm::ConstantAsMetadata::get(llvm::UndefValue::get(
743 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
744 llvm::IntegerType::get(Context, 32),
745 llvm::APInt(32, (uint64_t)(IsSignedInteger ? 1 : 0))))};
746 Fn->setMetadata(
"vec_type_hint", llvm::MDNode::get(Context, AttrMDArgs));
749 if (
const WorkGroupSizeHintAttr *A = FD->
getAttr<WorkGroupSizeHintAttr>()) {
750 llvm::Metadata *AttrMDArgs[] = {
751 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getXDim())),
752 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getYDim())),
753 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getZDim()))};
754 Fn->setMetadata(
"work_group_size_hint", llvm::MDNode::get(Context, AttrMDArgs));
757 if (
const ReqdWorkGroupSizeAttr *A = FD->
getAttr<ReqdWorkGroupSizeAttr>()) {
758 llvm::Metadata *AttrMDArgs[] = {
759 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getXDim())),
760 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getYDim())),
761 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getZDim()))};
762 Fn->setMetadata(
"reqd_work_group_size", llvm::MDNode::get(Context, AttrMDArgs));
765 if (
const OpenCLIntelReqdSubGroupSizeAttr *A =
766 FD->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>()) {
767 llvm::Metadata *AttrMDArgs[] = {
768 llvm::ConstantAsMetadata::get(
Builder.getInt32(A->getSubGroupSize()))};
769 Fn->setMetadata(
"intel_reqd_sub_group_size",
770 llvm::MDNode::get(Context, AttrMDArgs));
776 const Stmt *Body =
nullptr;
777 if (
auto *FD = dyn_cast_or_null<FunctionDecl>(F))
779 else if (
auto *OMD = dyn_cast_or_null<ObjCMethodDecl>(F))
780 Body = OMD->getBody();
782 if (
auto *CS = dyn_cast_or_null<CompoundStmt>(Body)) {
783 auto LastStmt = CS->body_rbegin();
784 if (LastStmt != CS->body_rend())
785 return isa<ReturnStmt>(*LastStmt);
792 Fn->addFnAttr(
"sanitize_thread_no_checking_at_run_time");
793 Fn->removeFnAttr(llvm::Attribute::SanitizeThread);
798 auto *MD = dyn_cast_or_null<CXXMethodDecl>(D);
799 if (!MD || !MD->getDeclName().getAsIdentifierInfo() ||
800 !MD->getDeclName().getAsIdentifierInfo()->isStr(
"allocate") ||
801 (MD->getNumParams() != 1 && MD->getNumParams() != 2))
804 if (MD->parameters()[0]->getType().getCanonicalType() != Ctx.
getSizeType())
807 if (MD->getNumParams() == 2) {
808 auto *PT = MD->parameters()[1]->getType()->getAs<
PointerType>();
809 if (!PT || !PT->isVoidPointerType() ||
810 !PT->getPointeeType().isConstQualified())
820 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD))
834 "Do not use a CodeGenFunction object for more than one function");
838 DidCallStackSave =
false;
840 if (
const auto *FD = dyn_cast_or_null<FunctionDecl>(D))
847 assert(
CurFn->isDeclaration() &&
"Function already has body?");
852 #define SANITIZER(NAME, ID) \ 853 if (SanOpts.empty()) \ 855 if (SanOpts.has(SanitizerKind::ID)) \ 856 if (CGM.isInSanitizerBlacklist(SanitizerKind::ID, Fn, Loc)) \ 857 SanOpts.set(SanitizerKind::ID, false); 859 #include "clang/Basic/Sanitizers.def" 868 if (mask & SanitizerKind::Address)
869 SanOpts.
set(SanitizerKind::KernelAddress,
false);
870 if (mask & SanitizerKind::KernelAddress)
872 if (mask & SanitizerKind::HWAddress)
873 SanOpts.
set(SanitizerKind::KernelHWAddress,
false);
874 if (mask & SanitizerKind::KernelHWAddress)
880 if (
SanOpts.
hasOneOf(SanitizerKind::Address | SanitizerKind::KernelAddress))
881 Fn->addFnAttr(llvm::Attribute::SanitizeAddress);
882 if (
SanOpts.
hasOneOf(SanitizerKind::HWAddress | SanitizerKind::KernelHWAddress))
883 Fn->addFnAttr(llvm::Attribute::SanitizeHWAddress);
885 Fn->addFnAttr(llvm::Attribute::SanitizeThread);
886 if (
SanOpts.
hasOneOf(SanitizerKind::Memory | SanitizerKind::KernelMemory))
887 Fn->addFnAttr(llvm::Attribute::SanitizeMemory);
889 Fn->addFnAttr(llvm::Attribute::SafeStack);
890 if (
SanOpts.
has(SanitizerKind::ShadowCallStack))
891 Fn->addFnAttr(llvm::Attribute::ShadowCallStack);
894 if (
SanOpts.
hasOneOf(SanitizerKind::Fuzzer | SanitizerKind::FuzzerNoLink))
895 Fn->addFnAttr(llvm::Attribute::OptForFuzzing);
900 if (
const auto *OMD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
901 IdentifierInfo *II = OMD->getSelector().getIdentifierInfoForSlot(0);
904 (OMD->getSelector().isUnarySelector() && II->
isStr(
".cxx_destruct"))) {
913 if (D &&
SanOpts.
has(SanitizerKind::CFIUnrelatedCast)) {
920 if (
const auto *XRayAttr = D->
getAttr<XRayInstrumentAttr>()) {
924 Fn->addFnAttr(
"function-instrument",
"xray-always");
925 if (XRayAttr->neverXRayInstrument())
926 Fn->addFnAttr(
"function-instrument",
"xray-never");
927 if (
const auto *LogArgs = D->
getAttr<XRayLogArgsAttr>())
929 Fn->addFnAttr(
"xray-log-args",
930 llvm::utostr(LogArgs->getArgumentCount()));
935 "xray-instruction-threshold",
941 Fn->addFnAttr(
"no-jump-tables",
946 Fn->addFnAttr(
"profile-sample-accurate");
950 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
951 EmitOpenCLKernelMetadata(FD, Fn);
957 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
964 llvm::Constant *FTRTTIConst =
966 llvm::Constant *FTRTTIConstEncoded =
968 llvm::Constant *PrologueStructElems[] = {PrologueSig,
970 llvm::Constant *PrologueStructConst =
971 llvm::ConstantStruct::getAnon(PrologueStructElems,
true);
972 Fn->setPrologueData(PrologueStructConst);
979 if (
SanOpts.
has(SanitizerKind::NullabilityReturn)) {
982 if (!(
SanOpts.
has(SanitizerKind::ReturnsNonnullAttribute) &&
984 RetValNullabilityPrecondition =
993 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
995 Fn->addFnAttr(llvm::Attribute::NoRecurse);
999 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
1002 Fn->addFnAttr(
"stackrealign");
1014 Builder.SetInsertPoint(EntryBB);
1018 if (requiresReturnValueCheck()) {
1029 if (
auto *FD = dyn_cast_or_null<FunctionDecl>(D))
1031 CC = SrcFnTy->getCallConv();
1033 for (
const VarDecl *VD : Args)
1034 ArgTypes.push_back(VD->getType());
1043 CurFn->addFnAttr(
"instrument-function-entry",
"__cyg_profile_func_enter");
1045 CurFn->addFnAttr(
"instrument-function-entry-inlined",
1046 "__cyg_profile_func_enter");
1048 CurFn->addFnAttr(
"instrument-function-entry-inlined",
1049 "__cyg_profile_func_enter_bare");
1061 Fn->addFnAttr(
"fentry-call",
"true");
1063 Fn->addFnAttr(
"instrument-function-entry-inlined",
1079 auto AI =
CurFn->arg_begin();
1087 llvm::Function::arg_iterator EI =
CurFn->arg_end();
1114 if (D && isa<CXXMethodDecl>(D) && cast<CXXMethodDecl>(D)->isInstance()) {
1141 if (FD->hasCapturedVLAType()) {
1144 auto VAT = FD->getCapturedVLAType();
1145 VLASizeMap[VAT->getSizeExpr()] = ExprArg;
1152 CXXThisValue = CXXABIThisValue;
1156 if (CXXABIThisValue) {
1158 SkippedChecks.
set(SanitizerKind::ObjectSize,
true);
1166 SkippedChecks.
set(SanitizerKind::Null,
true);
1170 Loc, CXXABIThisValue, ThisTy,
1178 for (FunctionArgList::const_iterator i = Args.begin(), e = Args.end();
1186 if (
const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(VD))
1187 Ty = PVD->getOriginalType();
1196 DI->EmitLocation(
Builder, StartLoc);
1202 LargestVectorWidth = VecWidth->getVectorWidth();
1207 if (
const CompoundStmt *S = dyn_cast<CompoundStmt>(Body))
1219 llvm::BasicBlock *SkipCountBB =
nullptr;
1241 if (F->isInterposable())
return;
1243 for (llvm::BasicBlock &BB : *F)
1244 for (llvm::Instruction &I : BB)
1248 F->setDoesNotThrow();
1268 bool PassedParams =
true;
1270 if (
auto Inherited = CD->getInheritedConstructor())
1276 Args.push_back(Param);
1277 if (!Param->hasAttr<PassObjectSizeAttr>())
1281 getContext(), Param->getDeclContext(), Param->getLocation(),
1283 SizeArguments[Param] = Implicit;
1284 Args.push_back(Implicit);
1288 if (MD && (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)))
1301 if (
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl()))
1302 return !ClassDecl->hasTrivialDestructor();
1316 if (FD->
hasAttr<NoDebugAttr>())
1317 DebugInfo =
nullptr;
1323 BodyRange = Body->getSourceRange();
1326 CurEHLocation = BodyRange.
getEnd();
1338 if (SpecDecl->hasBody(SpecDecl))
1339 Loc = SpecDecl->getLocation();
1345 if (Body && ShouldEmitLifetimeMarkers)
1353 if (isa<CXXDestructorDecl>(FD))
1355 else if (isa<CXXConstructorDecl>(FD))
1359 FD->
hasAttr<CUDAGlobalAttr>())
1361 else if (isa<CXXMethodDecl>(FD) &&
1362 cast<CXXMethodDecl>(FD)->isLambdaStaticInvoker()) {
1366 }
else if (FD->
isDefaulted() && isa<CXXMethodDecl>(FD) &&
1367 (cast<CXXMethodDecl>(FD)->isCopyAssignmentOperator() ||
1368 cast<CXXMethodDecl>(FD)->isMoveAssignmentOperator())) {
1375 llvm_unreachable(
"no definition for emitted function");
1385 bool ShouldEmitUnreachable =
1391 EmitCheck(std::make_pair(IsFalse, SanitizerKind::Return),
1392 SanitizerHandler::MissingReturn,
1394 }
else if (ShouldEmitUnreachable) {
1398 if (
SanOpts.
has(SanitizerKind::Return) || ShouldEmitUnreachable) {
1400 Builder.ClearInsertionPoint();
1409 if (!
CurFn->doesNotThrow())
1418 if (!S)
return false;
1425 if (isa<LabelStmt>(S))
1430 if (isa<SwitchCase>(S) && !IgnoreCaseStmts)
1434 if (isa<SwitchStmt>(S))
1435 IgnoreCaseStmts =
true;
1450 if (!S)
return false;
1454 if (isa<SwitchStmt>(S) || isa<WhileStmt>(S) || isa<DoStmt>(S) ||
1458 if (isa<BreakStmt>(S))
1470 if (!S)
return false;
1476 if (isa<IfStmt>(S) || isa<SwitchStmt>(S) || isa<WhileStmt>(S) ||
1477 isa<DoStmt>(S) || isa<ForStmt>(S) || isa<CompoundStmt>(S) ||
1478 isa<CXXForRangeStmt>(S) || isa<CXXTryStmt>(S) ||
1479 isa<ObjCForCollectionStmt>(S) || isa<ObjCAtTryStmt>(S))
1482 if (isa<DeclStmt>(S))
1498 llvm::APSInt ResultInt;
1502 ResultBool = ResultInt.getBoolValue();
1510 llvm::APSInt &ResultInt,
1533 llvm::BasicBlock *TrueBlock,
1534 llvm::BasicBlock *FalseBlock,
1535 uint64_t TrueCount) {
1538 if (
const BinaryOperator *CondBOp = dyn_cast<BinaryOperator>(Cond)) {
1541 if (CondBOp->getOpcode() == BO_LAnd) {
1544 bool ConstantBool =
false;
1587 if (CondBOp->getOpcode() == BO_LOr) {
1590 bool ConstantBool =
false;
1616 uint64_t RHSCount = TrueCount - LHSCount;
1638 if (
const UnaryOperator *CondUOp = dyn_cast<UnaryOperator>(Cond)) {
1640 if (CondUOp->getOpcode() == UO_LNot) {
1663 uint64_t LHSScaledTrueCount = 0;
1667 LHSScaledTrueCount = TrueCount * LHSRatio;
1676 LHSScaledTrueCount);
1683 TrueCount - LHSScaledTrueCount);
1689 if (
const CXXThrowExpr *Throw = dyn_cast<CXXThrowExpr>(Cond)) {
1702 llvm::MDNode *Unpredictable =
nullptr;
1705 auto *FD = dyn_cast_or_null<FunctionDecl>(Call->getCalleeDecl());
1706 if (FD && FD->
getBuiltinID() == Builtin::BI__builtin_unpredictable) {
1708 Unpredictable = MDHelper.createUnpredictable();
1715 llvm::MDNode *Weights =
1716 createProfileWeights(TrueCount, CurrentCount - TrueCount);
1724 Builder.CreateCondBr(CondV, TrueBlock, FalseBlock, Weights, Unpredictable);
1752 Builder.CreateInBoundsGEP(begin.getPointer(), sizeInChars,
"vla.end");
1754 llvm::BasicBlock *originBB = CGF.
Builder.GetInsertBlock();
1762 llvm::PHINode *cur = Builder.CreatePHI(begin.getType(), 2,
"vla.cur");
1763 cur->addIncoming(begin.getPointer(), originBB);
1774 Builder.CreateInBoundsGEP(CGF.
Int8Ty, cur, baseSizeInChars,
"vla.next");
1777 llvm::Value *done = Builder.CreateICmpEQ(next, end,
"vla-init.isdone");
1778 Builder.CreateCondBr(done, contBB, loopBB);
1779 cur->addIncoming(next, loopBB);
1789 if (cast<CXXRecordDecl>(RT->getDecl())->isEmpty())
1808 dyn_cast_or_null<VariableArrayType>(
1811 SizeVal = VlaSize.NumElts;
1813 if (!eltSize.
isOne())
1834 llvm::GlobalVariable *NullVariable =
1835 new llvm::GlobalVariable(
CGM.
getModule(), NullConstant->getType(),
1837 llvm::GlobalVariable::PrivateLinkage,
1838 NullConstant, Twine());
1840 NullVariable->setAlignment(NullAlign.getQuantity());
1859 if (!IndirectBranch)
1865 IndirectBranch->addDestination(BB);
1866 return llvm::BlockAddress::get(
CurFn, BB);
1871 if (IndirectBranch)
return IndirectBranch->getParent();
1877 "indirect.goto.dest");
1880 IndirectBranch = TmpBuilder.CreateIndirectBr(DestVal);
1881 return IndirectBranch->getParent();
1894 if (isa<VariableArrayType>(arrayType)) {
1905 baseType = elementType;
1906 return numVLAElements;
1908 }
while (isa<VariableArrayType>(arrayType));
1920 llvm::ConstantInt *zero =
Builder.getInt32(0);
1921 gepIndices.push_back(zero);
1923 uint64_t countFromCLAs = 1;
1926 llvm::ArrayType *llvmArrayType =
1928 while (llvmArrayType) {
1929 assert(isa<ConstantArrayType>(arrayType));
1930 assert(cast<ConstantArrayType>(arrayType)->getSize().getZExtValue()
1931 == llvmArrayType->getNumElements());
1933 gepIndices.push_back(zero);
1934 countFromCLAs *= llvmArrayType->getNumElements();
1938 dyn_cast<llvm::ArrayType>(llvmArrayType->getElementType());
1940 assert((!llvmArrayType || arrayType) &&
1941 "LLVM and Clang types are out-of-synch");
1950 cast<ConstantArrayType>(
arrayType)->getSize().getZExtValue();
1960 gepIndices,
"array.begin"),
1967 = llvm::ConstantInt::get(
SizeTy, countFromCLAs);
1971 numElements =
Builder.CreateNUWMul(numVLAElements, numElements);
1978 assert(vla &&
"type was not a variable array type!");
1991 assert(vlaSize &&
"no size for VLA!");
1992 assert(vlaSize->getType() ==
SizeTy);
1995 numElements = vlaSize;
1999 numElements =
Builder.CreateNUWMul(numElements, vlaSize);
2001 }
while ((type =
getContext().getAsVariableArrayType(elementType)));
2003 return { numElements, elementType };
2009 assert(vla &&
"type was not a variable array type!");
2016 assert(VlaSize &&
"no size for VLA!");
2017 assert(VlaSize->getType() ==
SizeTy);
2023 "Must pass variably modified type to EmitVLASizes!");
2033 switch (ty->getTypeClass()) {
2035 #define TYPE(Class, Base) 2036 #define ABSTRACT_TYPE(Class, Base) 2037 #define NON_CANONICAL_TYPE(Class, Base) 2038 #define DEPENDENT_TYPE(Class, Base) case Type::Class: 2039 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) 2040 #include "clang/AST/TypeNodes.def" 2041 llvm_unreachable(
"unexpected dependent type!");
2047 case Type::ExtVector:
2050 case Type::Elaborated:
2051 case Type::TemplateSpecialization:
2052 case Type::ObjCTypeParam:
2053 case Type::ObjCObject:
2054 case Type::ObjCInterface:
2055 case Type::ObjCObjectPointer:
2056 llvm_unreachable(
"type class is never variably-modified!");
2058 case Type::Adjusted:
2059 type = cast<AdjustedType>(ty)->getAdjustedType();
2063 type = cast<DecayedType>(ty)->getPointeeType();
2067 type = cast<PointerType>(ty)->getPointeeType();
2070 case Type::BlockPointer:
2071 type = cast<BlockPointerType>(ty)->getPointeeType();
2074 case Type::LValueReference:
2075 case Type::RValueReference:
2076 type = cast<ReferenceType>(ty)->getPointeeType();
2079 case Type::MemberPointer:
2080 type = cast<MemberPointerType>(ty)->getPointeeType();
2083 case Type::ConstantArray:
2084 case Type::IncompleteArray:
2086 type = cast<ArrayType>(ty)->getElementType();
2089 case Type::VariableArray: {
2107 size->getType()->isSignedIntegerType()) {
2109 llvm::Value *Zero = llvm::Constant::getNullValue(Size->getType());
2110 llvm::Constant *StaticArgs[] = {
2114 SanitizerKind::VLABound),
2115 SanitizerHandler::VLABoundNotPositive, StaticArgs, Size);
2127 case Type::FunctionProto:
2128 case Type::FunctionNoProto:
2129 type = cast<FunctionType>(ty)->getReturnType();
2134 case Type::UnaryTransform:
2135 case Type::Attributed:
2136 case Type::SubstTemplateTypeParm:
2137 case Type::PackExpansion:
2143 case Type::Decltype:
2145 case Type::DeducedTemplateSpecialization:
2149 case Type::TypeOfExpr:
2155 type = cast<AtomicType>(ty)->getValueType();
2159 type = cast<PipeType>(ty)->getElementType();
2166 if (
getContext().getBuiltinVaListType()->isArrayType())
2177 assert(!Init.
isUninit() &&
"Invalid DeclRefExpr initializer!");
2180 Dbg->EmitGlobalVariable(E->
getDecl(), Init);
2195 llvm::Instruction *inst =
new llvm::BitCastInst(value, value->getType(),
"",
2199 protection.Inst = inst;
2204 if (!protection.Inst)
return;
2207 protection.Inst->eraseFromParent();
2216 llvm::Instruction *Assumption =
Builder.CreateAlignmentAssumption(
2220 OffsetValue, TheCheck, Assumption);
2230 llvm::Instruction *Assumption =
Builder.CreateAlignmentAssumption(
2235 OffsetValue, TheCheck, Assumption);
2244 if (
auto *CE = dyn_cast<CastExpr>(E))
2245 E = CE->getSubExprAsWritten();
2255 StringRef AnnotationStr,
2263 return Builder.CreateCall(AnnotationFn, Args);
2267 assert(D->
hasAttr<AnnotateAttr>() &&
"no annotate attribute");
2278 assert(D->
hasAttr<AnnotateAttr>() &&
"no annotate attribute");
2310 const llvm::Twine &Name,
2311 llvm::BasicBlock *BB,
2312 llvm::BasicBlock::iterator InsertPt)
const {
2319 llvm::Instruction *I,
const llvm::Twine &Name, llvm::BasicBlock *BB,
2320 llvm::BasicBlock::iterator InsertPt)
const {
2321 llvm::IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);
2328 std::string &FirstMissing) {
2330 if (ReqFeatures.empty())
2335 llvm::StringMap<bool> CallerFeatureMap;
2341 ReqFeatures.begin(), ReqFeatures.end(), [&](StringRef Feature) {
2343 Feature.split(OrFeatures,
'|');
2344 return llvm::any_of(OrFeatures, [&](StringRef Feature) {
2345 if (!CallerFeatureMap.lookup(Feature)) {
2346 FirstMissing = Feature.str();
2372 std::string MissingFeature;
2375 const char *FeatureList =
2378 if (!FeatureList || StringRef(FeatureList) ==
"")
2380 StringRef(FeatureList).split(ReqFeatures,
',');
2386 }
else if (TargetDecl->
hasAttr<TargetAttr>() ||
2387 TargetDecl->
hasAttr<CPUSpecificAttr>()) {
2390 const TargetAttr *TD = TargetDecl->
getAttr<TargetAttr>();
2394 llvm::StringMap<bool> CalleeFeatureMap;
2397 for (
const auto &F : ParsedAttr.Features) {
2398 if (F[0] ==
'+' && CalleeFeatureMap.lookup(F.substr(1)))
2399 ReqFeatures.push_back(StringRef(F).substr(1));
2402 for (
const auto &F : CalleeFeatureMap) {
2405 ReqFeatures.push_back(F.getKey());
2417 llvm::IRBuilder<> IRB(
Builder.GetInsertBlock(),
Builder.GetInsertPoint());
2418 IRB.SetCurrentDebugLocation(
Builder.getCurrentDebugLocation());
2432 Condition ?
Builder.CreateAnd(Condition, FeatureCond) : FeatureCond;
2438 llvm::Function *Resolver,
2440 llvm::Function *FuncToReturn,
2441 bool SupportsIFunc) {
2442 if (SupportsIFunc) {
2443 Builder.CreateRet(FuncToReturn);
2448 llvm::for_each(Resolver->args(),
2449 [&](llvm::Argument &Arg) { Args.push_back(&Arg); });
2451 llvm::CallInst *Result = Builder.CreateCall(FuncToReturn, Args);
2452 Result->setTailCallKind(llvm::CallInst::TCK_MustTail);
2454 if (Resolver->getReturnType()->isVoidTy())
2455 Builder.CreateRetVoid();
2457 Builder.CreateRet(Result);
2462 assert((
getContext().getTargetInfo().getTriple().getArch() ==
2463 llvm::Triple::x86 ||
2464 getContext().getTargetInfo().getTriple().getArch() ==
2465 llvm::Triple::x86_64) &&
2466 "Only implemented for x86 targets");
2472 Builder.SetInsertPoint(CurBlock);
2476 Builder.SetInsertPoint(CurBlock);
2477 llvm::Value *Condition = FormResolverCondition(RO);
2481 assert(&RO == Options.end() - 1 &&
2482 "Default or Generic case must be last");
2488 llvm::BasicBlock *RetBlock =
createBasicBlock(
"resolver_return", Resolver);
2493 Builder.CreateCondBr(Condition, RetBlock, CurBlock);
2497 Builder.SetInsertPoint(CurBlock);
2498 llvm::CallInst *TrapCall =
EmitTrapCall(llvm::Intrinsic::trap);
2499 TrapCall->setDoesNotReturn();
2500 TrapCall->setDoesNotThrow();
2502 Builder.ClearInsertionPoint();
2515 llvm::Instruction *Assumption) {
2516 assert(Assumption && isa<llvm::CallInst>(Assumption) &&
2517 cast<llvm::CallInst>(Assumption)->getCalledValue() ==
2518 llvm::Intrinsic::getDeclaration(
2519 Builder.GetInsertBlock()->getParent()->getParent(),
2520 llvm::Intrinsic::assume) &&
2521 "Assumption should be a call to llvm.assume().");
2522 assert(&(
Builder.GetInsertBlock()->back()) == Assumption &&
2523 "Assumption should be the last instruction of the basic block, " 2524 "since the basic block is still being generated.");
2536 Assumption->removeFromParent();
2542 OffsetValue =
Builder.getInt1(0);
2550 EmitCheck({std::make_pair(TheCheck, SanitizerKind::Alignment)},
2551 SanitizerHandler::AlignmentAssumption, StaticData, DynamicData);
2562 return DI->SourceLocToDebugLoc(Location);
2564 return llvm::DebugLoc();
llvm::PointerType * Int8PtrPtrTy
const llvm::DataLayout & getDataLayout() const
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.
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.
bool EvaluateAsInt(EvalResult &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...
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.
QualType getThisType() const
Returns the type of the this pointer.
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.
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...
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.
const TargetInfo & getTargetInfo() const
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...
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...
void markAsIgnoreThreadCheckingAtRuntime(llvm::Function *Fn)
Annotate the function with an attribute that disables TSan checking at runtime.
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]).
bool supportsIFunc() const
Identify whether this target supports IFuncs.
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...
Expr * IgnoreImpCasts() LLVM_READONLY
IgnoreImpCasts - Skip past any implicit casts which might surround this expression.
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.
void EmitAlignmentAssumptionCheck(llvm::Value *Ptr, QualType Ty, SourceLocation Loc, SourceLocation AssumptionLoc, llvm::Value *Alignment, llvm::Value *OffsetValue, llvm::Value *TheCheck, llvm::Instruction *Assumption)
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.
static void CreateMultiVersionResolverReturn(CodeGenModule &CGM, llvm::Function *Resolver, CGBuilderTy &Builder, llvm::Function *FuncToReturn, bool SupportsIFunc)
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.
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.
APValue Val
Val - This is the value the expression can be folded to.
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)
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)
llvm::Value * EmitCheckValue(llvm::Value *V)
Convert a value into a format suitable for passing to a runtime sanitizer handler.
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...
llvm::SmallVector< StringRef, 8 > Features
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.
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.
void getFunctionFeatureMap(llvm::StringMap< bool > &FeatureMap, GlobalDecl GD)
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.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
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.
EvalResult is a struct with detailed info about an evaluated expression.
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...
void EmitFunctionBody(const Stmt *Body)
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.
bool isMSVCRTEntryPoint() const
Determines whether this function is a MSVCRT user defined entry point.
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 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...
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.
llvm::Function * Function
Defines the clang::TargetInfo interface.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
void EmitMultiVersionResolver(llvm::Function *Resolver, ArrayRef< MultiVersionResolverOption > Options)
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.
struct clang::CodeGen::CodeGenFunction::MultiVersionResolverOption::Conds Conditions
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())
void EmitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty, SourceLocation Loc, SourceLocation AssumptionLoc, llvm::Value *Alignment, llvm::Value *OffsetValue=nullptr)
A trivial tuple used to represent a source range.
LValue - This represents an lvalue references.
llvm::BlockAddress * GetAddrOfLabel(const LabelDecl *L)
SourceLocation getBeginLoc() const LLVM_READONLY
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>.