-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[NFC][CFI][CodeGen] Move GeneralizeFunctionType out of CreateMetadataIdentifierGeneralized #158190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Created using spr 1.3.6 [skip ci]
Created using spr 1.3.6
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Vitaly Buka (vitalybuka) ChangesFull diff: https://github.com/llvm/llvm-project/pull/158190.diff 1 Files Affected:
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index d45fb823d4c35..acd77c5aca89c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3041,9 +3041,11 @@ void CodeGenModule::createFunctionTypeMetadataForIcall(const FunctionDecl *FD,
if (isa<CXXMethodDecl>(FD) && !cast<CXXMethodDecl>(FD)->isStatic())
return;
- llvm::Metadata *MD = CreateMetadataIdentifierForType(FD->getType());
+ QualType FnType = FD->getType();
+ llvm::Metadata *MD = CreateMetadataIdentifierForType(FnType);
F->addTypeMetadata(0, MD);
- F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(FD->getType()));
+ FnType = GeneralizeFunctionType(getContext(), FnType);
+ F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(FnType));
// Emit a hash-based bit set entry for cross-DSO calls.
if (CodeGenOpts.SanitizeCfiCrossDso)
@@ -7936,8 +7938,10 @@ CodeGenModule::CreateMetadataIdentifierImpl(QualType T, MetadataTypeMap &Map,
llvm::Metadata *CodeGenModule::CreateMetadataIdentifierForFnType(QualType T) {
assert(isa<FunctionType>(T));
- if (getCodeGenOpts().SanitizeCfiICallGeneralizePointers)
+ if (getCodeGenOpts().SanitizeCfiICallGeneralizePointers) {
+ T = GeneralizeFunctionType(getContext(), T);
return CreateMetadataIdentifierGeneralized(T);
+ }
return CreateMetadataIdentifierForType(T);
}
@@ -7951,8 +7955,8 @@ CodeGenModule::CreateMetadataIdentifierForVirtualMemPtrType(QualType T) {
}
llvm::Metadata *CodeGenModule::CreateMetadataIdentifierGeneralized(QualType T) {
- return CreateMetadataIdentifierImpl(GeneralizeFunctionType(getContext(), T),
- GeneralizedMetadataIdMap, ".generalized");
+ return CreateMetadataIdentifierImpl(T, GeneralizedMetadataIdMap,
+ ".generalized");
}
/// Returns whether this module needs the "all-vtables" type identifier.
|
Created using spr 1.3.6 [skip ci]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the CFI (Control Flow Integrity) metadata generation code by moving the GeneralizeFunctionType function call out of CreateMetadataIdentifierGeneralized and into the callers. This change makes the generalization logic more explicit and clarifies the separation of concerns between metadata creation and type generalization.
Key changes:
- Extract
GeneralizeFunctionTypecalls to calling sites for better clarity - Update
CreateMetadataIdentifierForFnTypeto handle generalization before callingCreateMetadataIdentifierGeneralized - Modify
createFunctionTypeMetadataForIcallto explicitly generalize the function type before creating generalized metadata
Created using spr 1.3.6 [skip ci]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Created using spr 1.3.6 [skip ci]
For #158193