Skip to content

Commit 8b00c31

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.6
2 parents 0e3c556 + 0f34bbf commit 8b00c31

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6496,11 +6496,8 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType,
64966496
SanitizerDebugLocation SanScope(this, {CheckOrdinal}, CheckHandler);
64976497
EmitSanitizerStatReport(llvm::SanStat_CFI_ICall);
64986498

6499-
llvm::Metadata *MD;
6500-
if (CGM.getCodeGenOpts().SanitizeCfiICallGeneralizePointers)
6501-
MD = CGM.CreateMetadataIdentifierGeneralized(QualType(FnType, 0));
6502-
else
6503-
MD = CGM.CreateMetadataIdentifierForType(QualType(FnType, 0));
6499+
llvm::Metadata *MD =
6500+
CGM.CreateMetadataIdentifierForFnType(QualType(FnType, 0));
65046501

65056502
llvm::Value *TypeId = llvm::MetadataAsValue::get(getLLVMContext(), MD);
65066503

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,9 +3041,11 @@ void CodeGenModule::createFunctionTypeMetadataForIcall(const FunctionDecl *FD,
30413041
if (isa<CXXMethodDecl>(FD) && !cast<CXXMethodDecl>(FD)->isStatic())
30423042
return;
30433043

3044-
llvm::Metadata *MD = CreateMetadataIdentifierForType(FD->getType());
3044+
QualType FnType = FD->getType();
3045+
llvm::Metadata *MD = CreateMetadataIdentifierForType(FnType);
30453046
F->addTypeMetadata(0, MD);
3046-
F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(FD->getType()));
3047+
FnType = GeneralizeFunctionType(getContext(), FnType);
3048+
F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(FnType));
30473049

30483050
// Emit a hash-based bit set entry for cross-DSO calls.
30493051
if (CodeGenOpts.SanitizeCfiCrossDso)
@@ -7934,6 +7936,15 @@ CodeGenModule::CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
79347936
return InternalId;
79357937
}
79367938

7939+
llvm::Metadata *CodeGenModule::CreateMetadataIdentifierForFnType(QualType T) {
7940+
assert(isa<FunctionType>(T));
7941+
if (getCodeGenOpts().SanitizeCfiICallGeneralizePointers) {
7942+
T = GeneralizeFunctionType(getContext(), T);
7943+
return CreateMetadataIdentifierGeneralized(T);
7944+
}
7945+
return CreateMetadataIdentifierForType(T);
7946+
}
7947+
79377948
llvm::Metadata *CodeGenModule::CreateMetadataIdentifierForType(QualType T) {
79387949
return CreateMetadataIdentifierImpl(T, MetadataIdMap, "");
79397950
}
@@ -7944,8 +7955,8 @@ CodeGenModule::CreateMetadataIdentifierForVirtualMemPtrType(QualType T) {
79447955
}
79457956

79467957
llvm::Metadata *CodeGenModule::CreateMetadataIdentifierGeneralized(QualType T) {
7947-
return CreateMetadataIdentifierImpl(GeneralizeFunctionType(getContext(), T),
7948-
GeneralizedMetadataIdMap, ".generalized");
7958+
return CreateMetadataIdentifierImpl(T, GeneralizedMetadataIdMap,
7959+
".generalized");
79497960
}
79507961

79517962
/// Returns whether this module needs the "all-vtables" type identifier.

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,9 @@ class CodeGenModule : public CodeGenTypeCache {
16231623
/// Generate a KCFI type identifier for T.
16241624
llvm::ConstantInt *CreateKCFITypeId(QualType T, StringRef Salt);
16251625

1626+
/// Create a metadata identifier for the given function type.
1627+
llvm::Metadata *CreateMetadataIdentifierForFnType(QualType T);
1628+
16261629
/// Create a metadata identifier for the given type. This may either be an
16271630
/// MDString (for external identifiers) or a distinct unnamed MDNode (for
16281631
/// internal identifiers).

0 commit comments

Comments
 (0)