@@ -710,9 +710,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
710
710
711
711
DidCallStackSave = false ;
712
712
CurCodeDecl = D;
713
- if ( const auto *FD = dyn_cast_or_null<FunctionDecl>(D))
714
- if (FD->usesSEHTry ())
715
- CurSEHParent = FD;
713
+ const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
714
+ if (FD && FD->usesSEHTry ())
715
+ CurSEHParent = FD;
716
716
CurFuncDecl = (D ? D->getNonClosureContext () : nullptr );
717
717
FnRetTy = RetTy;
718
718
CurFn = Fn;
@@ -803,10 +803,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
803
803
// are not aware of how to move the extra UBSan instructions across the split
804
804
// coroutine boundaries.
805
805
if (D && SanOpts.has (SanitizerKind::Null))
806
- if (const auto *FD = dyn_cast<FunctionDecl>(D))
807
- if (FD->getBody () &&
808
- FD->getBody ()->getStmtClass () == Stmt::CoroutineBodyStmtClass)
809
- SanOpts.Mask &= ~SanitizerKind::Null;
806
+ if (FD && FD->getBody () &&
807
+ FD->getBody ()->getStmtClass () == Stmt::CoroutineBodyStmtClass)
808
+ SanOpts.Mask &= ~SanitizerKind::Null;
810
809
811
810
// Apply xray attributes to the function (as a string, for now)
812
811
bool AlwaysXRayAttr = false ;
@@ -896,32 +895,27 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
896
895
if (D && D->hasAttr <NoProfileFunctionAttr>())
897
896
Fn->addFnAttr (llvm::Attribute::NoProfile);
898
897
899
- if (getLangOpts ().OpenCL ) {
898
+ if (FD && getLangOpts ().OpenCL ) {
900
899
// Add metadata for a kernel function.
901
- if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
902
- EmitOpenCLKernelMetadata (FD, Fn);
900
+ EmitOpenCLKernelMetadata (FD, Fn);
903
901
}
904
902
905
903
// If we are checking function types, emit a function type signature as
906
904
// prologue data.
907
- if (getLangOpts ().CPlusPlus && SanOpts.has (SanitizerKind::Function)) {
908
- if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
909
- if (llvm::Constant *PrologueSig = getPrologueSignature (CGM, FD)) {
910
- // Remove any (C++17) exception specifications, to allow calling e.g. a
911
- // noexcept function through a non-noexcept pointer.
912
- auto ProtoTy =
913
- getContext ().getFunctionTypeWithExceptionSpec (FD->getType (),
914
- EST_None);
915
- llvm::Constant *FTRTTIConst =
916
- CGM.GetAddrOfRTTIDescriptor (ProtoTy, /* ForEH=*/ true );
917
- llvm::Constant *FTRTTIConstEncoded =
918
- EncodeAddrForUseInPrologue (Fn, FTRTTIConst);
919
- llvm::Constant *PrologueStructElems[] = {PrologueSig,
920
- FTRTTIConstEncoded};
921
- llvm::Constant *PrologueStructConst =
922
- llvm::ConstantStruct::getAnon (PrologueStructElems, /* Packed=*/ true );
923
- Fn->setPrologueData (PrologueStructConst);
924
- }
905
+ if (FD && getLangOpts ().CPlusPlus && SanOpts.has (SanitizerKind::Function)) {
906
+ if (llvm::Constant *PrologueSig = getPrologueSignature (CGM, FD)) {
907
+ // Remove any (C++17) exception specifications, to allow calling e.g. a
908
+ // noexcept function through a non-noexcept pointer.
909
+ auto ProtoTy = getContext ().getFunctionTypeWithExceptionSpec (
910
+ FD->getType (), EST_None);
911
+ llvm::Constant *FTRTTIConst =
912
+ CGM.GetAddrOfRTTIDescriptor (ProtoTy, /* ForEH=*/ true );
913
+ llvm::Constant *FTRTTIConstEncoded =
914
+ EncodeAddrForUseInPrologue (Fn, FTRTTIConst);
915
+ llvm::Constant *PrologueStructElems[] = {PrologueSig, FTRTTIConstEncoded};
916
+ llvm::Constant *PrologueStructConst =
917
+ llvm::ConstantStruct::getAnon (PrologueStructElems, /* Packed=*/ true );
918
+ Fn->setPrologueData (PrologueStructConst);
925
919
}
926
920
}
927
921
@@ -948,25 +942,22 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
948
942
// kernels cannot include RTTI information, exception classes,
949
943
// recursive code, virtual functions or make use of C++ libraries that
950
944
// are not compiled for the device.
951
- if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
952
- if ((getLangOpts ().CPlusPlus && FD->isMain ()) || getLangOpts ().OpenCL ||
953
- getLangOpts ().SYCLIsDevice ||
954
- (getLangOpts ().CUDA && FD->hasAttr <CUDAGlobalAttr>()))
955
- Fn->addFnAttr (llvm::Attribute::NoRecurse);
956
- }
945
+ if (FD && ((getLangOpts ().CPlusPlus && FD->isMain ()) ||
946
+ getLangOpts ().OpenCL || getLangOpts ().SYCLIsDevice ||
947
+ (getLangOpts ().CUDA && FD->hasAttr <CUDAGlobalAttr>())))
948
+ Fn->addFnAttr (llvm::Attribute::NoRecurse);
957
949
958
- if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D) ) {
950
+ if (FD ) {
959
951
Builder.setIsFPConstrained (FD->hasAttr <StrictFPAttr>());
960
952
if (FD->hasAttr <StrictFPAttr>())
961
953
Fn->addFnAttr (llvm::Attribute::StrictFP);
962
954
}
963
955
964
956
// If a custom alignment is used, force realigning to this alignment on
965
957
// any main function which certainly will need it.
966
- if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
967
- if ((FD->isMain () || FD->isMSVCRTEntryPoint ()) &&
968
- CGM.getCodeGenOpts ().StackAlignment )
969
- Fn->addFnAttr (" stackrealign" );
958
+ if (FD && ((FD->isMain () || FD->isMSVCRTEntryPoint ()) &&
959
+ CGM.getCodeGenOpts ().StackAlignment ))
960
+ Fn->addFnAttr (" stackrealign" );
970
961
971
962
llvm::BasicBlock *EntryBB = createBasicBlock (" entry" , CurFn);
972
963
@@ -993,7 +984,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
993
984
// such as 'this' and 'vtt', show up in the debug info. Preserve the calling
994
985
// convention.
995
986
CallingConv CC = CallingConv::CC_C;
996
- if (auto *FD = dyn_cast_or_null<FunctionDecl>(D) )
987
+ if (FD )
997
988
if (const auto *SrcFnTy = FD->getType ()->getAs <FunctionType>())
998
989
CC = SrcFnTy->getCallConv ();
999
990
SmallVector<QualType, 16 > ArgTypes;
0 commit comments