Skip to content

Commit 781d112

Browse files
thurstondIanWood1
authored andcommitted
[cfi] Fix one -fno-sanitize-merge case, and add two TODOs (llvm#135438)
-fno-sanitize-merge (introduced in llvm#120464) nearly works for CFI: code that calls EmitCheck will already check the merge options. This patch fixes one EmitTrapCheck call, which did not check the merge options, and for two other EmitTrapChecks, adds two TODOs that explain why it is difficult to fix them.
1 parent 5ea7935 commit 781d112

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

clang/lib/CodeGen/CGClass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2895,7 +2895,8 @@ void CodeGenFunction::EmitVTablePtrCheck(const CXXRecordDecl *RD,
28952895
}
28962896

28972897
if (CGM.getCodeGenOpts().SanitizeTrap.has(M)) {
2898-
EmitTrapCheck(TypeTest, SanitizerHandler::CFICheckFail);
2898+
bool NoMerge = !CGM.getCodeGenOpts().SanitizeMergeHandlers.has(M);
2899+
EmitTrapCheck(TypeTest, SanitizerHandler::CFICheckFail, NoMerge);
28992900
return;
29002901
}
29012902

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3923,7 +3923,11 @@ void CodeGenFunction::EmitCfiCheckFail() {
39233923
// Data == nullptr means the calling module has trap behaviour for this check.
39243924
llvm::Value *DataIsNotNullPtr =
39253925
Builder.CreateICmpNE(Data, llvm::ConstantPointerNull::get(Int8PtrTy));
3926-
EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail);
3926+
// TODO: since there is no data, we don't know the CheckKind, and therefore
3927+
// cannot inspect CGM.getCodeGenOpts().SanitizeMergeHandlers. We default to
3928+
// NoMerge = false. Users can disable merging by disabling optimization.
3929+
EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail,
3930+
/*NoMerge=*/false);
39273931

39283932
llvm::StructType *SourceLocationTy =
39293933
llvm::StructType::get(VoidPtrTy, Int32Ty, Int32Ty);
@@ -3962,7 +3966,11 @@ void CodeGenFunction::EmitCfiCheckFail() {
39623966
EmitCheck(std::make_pair(Cond, Ordinal), SanitizerHandler::CFICheckFail,
39633967
{}, {Data, Addr, ValidVtable});
39643968
else
3965-
EmitTrapCheck(Cond, SanitizerHandler::CFICheckFail);
3969+
// TODO: we can't rely on CGM.getCodeGenOpts().SanitizeMergeHandlers.
3970+
// Although the compiler allows SanitizeMergeHandlers to be set
3971+
// independently of CGM.getLangOpts().Sanitize, Driver/SanitizerArgs.cpp
3972+
// requires that SanitizeMergeHandlers is a subset of Sanitize.
3973+
EmitTrapCheck(Cond, SanitizerHandler::CFICheckFail, /*NoMerge=*/false);
39663974
}
39673975

39683976
FinishFunction();

0 commit comments

Comments
 (0)