@@ -2848,17 +2848,13 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
28482848 // Skip available_externally functions. They won't be codegen'ed in the
28492849 // current module anyway.
28502850 if (getContext ().GetGVALinkageForFunction (FD) != GVA_AvailableExternally)
2851- createFunctionTypeMetadataForIcallForCFI (FD, F);
2851+ createFunctionTypeMetadataForIcall (FD, F);
28522852 }
28532853 }
28542854
28552855 if (CodeGenOpts.CallGraphSection ) {
2856- if (auto *FD = dyn_cast<FunctionDecl>(D)) {
2857- // Skip available_externally functions. They won't be codegen'ed in the
2858- // current module anyway.
2859- if (getContext ().GetGVALinkageForFunction (FD) != GVA_AvailableExternally)
2860- createFunctionTypeMDForIcallForCallGraph (FD, F);
2861- }
2856+ if (auto *FD = dyn_cast<FunctionDecl>(D))
2857+ createIndirectFunctionTypeMD (FD, F);
28622858 }
28632859
28642860 // Emit type metadata on member functions for member function pointer checks.
@@ -3069,22 +3065,22 @@ static bool hasExistingGeneralizedTypeMD(llvm::Function *F) {
30693065 return MD && MD->hasGeneralizedMDString ();
30703066}
30713067
3072- void CodeGenModule::createFunctionTypeMDForIcallForCallGraph (
3073- const FunctionDecl *FD, llvm::Function *F) {
3074- // Add additional metadata if we are emitting call graph section
3075- if (!CodeGenOpts. CallGraphSection )
3068+ void CodeGenModule::createIndirectFunctionTypeMD ( const FunctionDecl *FD,
3069+ llvm::Function *F) {
3070+ // Return if generalized type metadata is already attached.
3071+ if (hasExistingGeneralizedTypeMD (F) )
30763072 return ;
3077-
3078- if (! hasExistingGeneralizedTypeMD (F) &&
3079- (!F->hasLocalLinkage () ||
3080- F->getFunction ().hasAddressTaken (nullptr , /* IgnoreCallbackUses=*/ true ,
3081- /* IgnoreAssumeLikeCalls=*/ true ,
3082- /* IgnoreLLVMUsed=*/ false ) ))
3073+ // All functions which are not internal linkage could be indirect targets.
3074+ // Address taken functions with internal linkage could be indirect targets.
3075+ if (!F->hasLocalLinkage () &&
3076+ F->getFunction ().hasAddressTaken (nullptr , /* IgnoreCallbackUses=*/ true ,
3077+ /* IgnoreAssumeLikeCalls=*/ true ,
3078+ /* IgnoreLLVMUsed=*/ false ))
30833079 F->addTypeMetadata (0 , CreateMetadataIdentifierGeneralized (FD->getType ()));
30843080}
30853081
3086- void CodeGenModule::createFunctionTypeMetadataForIcallForCFI (
3087- const FunctionDecl *FD, llvm::Function *F) {
3082+ void CodeGenModule::createFunctionTypeMetadataForIcall ( const FunctionDecl *FD,
3083+ llvm::Function *F) {
30883084
30893085 // Only if we are checking indirect calls.
30903086 if (!LangOpts.Sanitize .has (SanitizerKind::CFIICall))
@@ -3260,7 +3256,7 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
32603256 // jump table.
32613257 if (!CodeGenOpts.SanitizeCfiCrossDso ||
32623258 !CodeGenOpts.SanitizeCfiCanonicalJumpTables )
3263- createFunctionTypeMetadataForIcallForCFI (FD, F);
3259+ createFunctionTypeMetadataForIcall (FD, F);
32643260
32653261 if (LangOpts.Sanitize .has (SanitizerKind::KCFI))
32663262 setKCFIType (FD, F);
0 commit comments