Skip to content

[cfi] Fix one -fno-sanitize-merge case, and add two TODOs #135438

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

Merged
merged 2 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/CGClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2961,7 +2961,8 @@ void CodeGenFunction::EmitVTablePtrCheck(const CXXRecordDecl *RD,
}

if (CGM.getCodeGenOpts().SanitizeTrap.has(M)) {
EmitTrapCheck(TypeTest, SanitizerHandler::CFICheckFail);
bool NoMerge = !CGM.getCodeGenOpts().SanitizeMergeHandlers.has(M);
EmitTrapCheck(TypeTest, SanitizerHandler::CFICheckFail, NoMerge);
return;
}

Expand Down
12 changes: 10 additions & 2 deletions clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3887,7 +3887,11 @@ void CodeGenFunction::EmitCfiCheckFail() {
// Data == nullptr means the calling module has trap behaviour for this check.
llvm::Value *DataIsNotNullPtr =
Builder.CreateICmpNE(Data, llvm::ConstantPointerNull::get(Int8PtrTy));
EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail);
// TODO: since there is no data, we don't know the CheckKind, and therefore
// cannot inspect CGM.getCodeGenOpts().SanitizeMergeHandlers. We default to
// NoMerge = false. Users can disable merging by disabling optimization.
EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail,
/*NoMerge=*/false);

llvm::StructType *SourceLocationTy =
llvm::StructType::get(VoidPtrTy, Int32Ty, Int32Ty);
Expand Down Expand Up @@ -3926,7 +3930,11 @@ void CodeGenFunction::EmitCfiCheckFail() {
EmitCheck(std::make_pair(Cond, Ordinal), SanitizerHandler::CFICheckFail,
{}, {Data, Addr, ValidVtable});
else
EmitTrapCheck(Cond, SanitizerHandler::CFICheckFail);
// TODO: we can't rely on CGM.getCodeGenOpts().SanitizeMergeHandlers.
// Although the compiler allows SanitizeMergeHandlers to be set
// independently of CGM.getLangOpts().Sanitize, Driver/SanitizerArgs.cpp
// requires that SanitizeMergeHandlers is a subset of Sanitize.
EmitTrapCheck(Cond, SanitizerHandler::CFICheckFail, /*NoMerge=*/false);
}

FinishFunction();
Expand Down