-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFCI][cfi] Refactor into 'SanitizerInfoFromCFICheckKind' #140117
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
This refactors existing code into a 'ParseCFITypeCheckKind' helper function. This will be useful in future work to annotate CFI checks with debug info (llvm#139809).
@llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-clang Author: Thurston Dang (thurstond) ChangesThis refactors existing code into a 'ParseCFITypeCheckKind' helper function. This will be useful in future work to annotate CFI checks with debug info (#139809). Full diff: https://github.com/llvm/llvm-project/pull/140117.diff 2 Files Affected:
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index befbfc64a680c..3e2725ab06da7 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -2779,6 +2779,37 @@ void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD,
}
}
+std::pair<SanitizerKind::SanitizerOrdinal, llvm::SanitizerStatKind>
+CodeGenFunction::ParseCFITypeCheckKind(CFITypeCheckKind TCK) {
+ SanitizerKind::SanitizerOrdinal M;
+ llvm::SanitizerStatKind SSK;
+
+ switch (TCK) {
+ case CFITCK_VCall:
+ M = SanitizerKind::SO_CFIVCall;
+ SSK = llvm::SanStat_CFI_VCall;
+ break;
+ case CFITCK_NVCall:
+ M = SanitizerKind::SO_CFINVCall;
+ SSK = llvm::SanStat_CFI_NVCall;
+ break;
+ case CFITCK_DerivedCast:
+ M = SanitizerKind::SO_CFIDerivedCast;
+ SSK = llvm::SanStat_CFI_DerivedCast;
+ break;
+ case CFITCK_UnrelatedCast:
+ M = SanitizerKind::SO_CFIUnrelatedCast;
+ SSK = llvm::SanStat_CFI_UnrelatedCast;
+ break;
+ case CFITCK_ICall:
+ case CFITCK_NVMFCall:
+ case CFITCK_VMFCall:
+ llvm_unreachable("unexpected sanitizer kind");
+ }
+
+ return std::make_pair(M, SSK);
+}
+
void CodeGenFunction::EmitVTablePtrCheckForCall(const CXXRecordDecl *RD,
llvm::Value *VTable,
CFITypeCheckKind TCK,
@@ -2842,30 +2873,7 @@ void CodeGenFunction::EmitVTablePtrCheck(const CXXRecordDecl *RD,
!CGM.HasHiddenLTOVisibility(RD))
return;
- SanitizerKind::SanitizerOrdinal M;
- llvm::SanitizerStatKind SSK;
- switch (TCK) {
- case CFITCK_VCall:
- M = SanitizerKind::SO_CFIVCall;
- SSK = llvm::SanStat_CFI_VCall;
- break;
- case CFITCK_NVCall:
- M = SanitizerKind::SO_CFINVCall;
- SSK = llvm::SanStat_CFI_NVCall;
- break;
- case CFITCK_DerivedCast:
- M = SanitizerKind::SO_CFIDerivedCast;
- SSK = llvm::SanStat_CFI_DerivedCast;
- break;
- case CFITCK_UnrelatedCast:
- M = SanitizerKind::SO_CFIUnrelatedCast;
- SSK = llvm::SanStat_CFI_UnrelatedCast;
- break;
- case CFITCK_ICall:
- case CFITCK_NVMFCall:
- case CFITCK_VMFCall:
- llvm_unreachable("unexpected sanitizer kind");
- }
+ auto [M, SSK] = ParseCFITypeCheckKind(TCK);
std::string TypeName = RD->getQualifiedNameAsString();
if (getContext().getNoSanitizeList().containsType(
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 7104303cba50e..aac4f0664273e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -3358,6 +3358,11 @@ class CodeGenFunction : public CodeGenTypeCache {
SanitizerSet SkippedChecks = SanitizerSet(),
llvm::Value *ArraySize = nullptr);
+ /// Converts the CFITypeCheckKind into SanitizerKind::SanitizerOrdinal and
+ /// llvm::SanitizerStatKind.
+ static std::pair<SanitizerKind::SanitizerOrdinal, llvm::SanitizerStatKind>
+ ParseCFITypeCheckKind(CFITypeCheckKind TCK);
+
/// Emit a check that \p Base points into an array object, which
/// we can access at index \p Index. \p Accessed should be \c false if we
/// this expression is used as an lvalue, for instance in "&Arr[Idx]".
|
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.
lgtm with optional comment
SanitizerInfoFromCFICheckKind(CodeGenFunction::CFITypeCheckKind TCK) { | ||
switch (TCK) { | ||
case CodeGenFunction::CFITCK_VCall: | ||
return std::make_pair(SanitizerKind::SO_CFIVCall, llvm::SanStat_CFI_VCall); |
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.
Could be
return {SanitizerKind::SO_CFIVCall, llvm::SanStat_CFI_VCall};
LGTM |
…cks (#139809) This connects the -fsanitize-annotate-debug-info plumbing (#138577) to CFI check codegen, using SanitizerAnnotateDebugInfo() (#139965) and SanitizerInfoFromCFIKind (#140117). Note: SanitizerAnnotateDebugInfo() is updated to a public function because it is needed in ItaniumCXXABI. Updates the tests from #139149.
…for CFI checks (#139809) This connects the -fsanitize-annotate-debug-info plumbing (llvm/llvm-project#138577) to CFI check codegen, using SanitizerAnnotateDebugInfo() (llvm/llvm-project#139965) and SanitizerInfoFromCFIKind (llvm/llvm-project#140117). Note: SanitizerAnnotateDebugInfo() is updated to a public function because it is needed in ItaniumCXXABI. Updates the tests from llvm/llvm-project#139149.
…cks (llvm#139809) This connects the -fsanitize-annotate-debug-info plumbing (llvm#138577) to CFI check codegen, using SanitizerAnnotateDebugInfo() (llvm#139965) and SanitizerInfoFromCFIKind (llvm#140117). Note: SanitizerAnnotateDebugInfo() is updated to a public function because it is needed in ItaniumCXXABI. Updates the tests from llvm#139149.
…cks (llvm#139809) This connects the -fsanitize-annotate-debug-info plumbing (llvm#138577) to CFI check codegen, using SanitizerAnnotateDebugInfo() (llvm#139965) and SanitizerInfoFromCFIKind (llvm#140117). Note: SanitizerAnnotateDebugInfo() is updated to a public function because it is needed in ItaniumCXXABI. Updates the tests from llvm#139149.
This refactors existing code into a 'SanitizerInfoFromCFICheckKind' helper function. This will be useful in future work to annotate CFI checks with debug info (#139809).