Skip to content

Commit 936a510

Browse files
committed
[cfi] Fix one -fno-sanitize-merge case, and add two TODOs
-fno-sanitize-merge (introduced in #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 c9ad5be commit 936a510

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

clang/lib/CodeGen/CGClass.cpp

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

29632963
if (CGM.getCodeGenOpts().SanitizeTrap.has(M)) {
2964-
EmitTrapCheck(TypeTest, SanitizerHandler::CFICheckFail);
2964+
bool NoMerge = !CGM.getCodeGenOpts().SanitizeMergeHandlers.has(M);
2965+
EmitTrapCheck(TypeTest, SanitizerHandler::CFICheckFail, NoMerge);
29652966
return;
29662967
}
29672968

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3887,7 +3887,10 @@ void CodeGenFunction::EmitCfiCheckFail() {
38873887
// Data == nullptr means the calling module has trap behaviour for this check.
38883888
llvm::Value *DataIsNotNullPtr =
38893889
Builder.CreateICmpNE(Data, llvm::ConstantPointerNull::get(Int8PtrTy));
3890-
EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail);
3890+
// TODO: since there is no data, we don't know the CheckKind, and therefore
3891+
// cannot inspect CGM.getCodeGenOpts().SanitizeMergeHandlers. We default to
3892+
// NoMerge = false. Users can disable merging by disabling optimization.
3893+
EmitTrapCheck(DataIsNotNullPtr, SanitizerHandler::CFICheckFail, /*NoMerge=*/ false);
38913894

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

39323939
FinishFunction();

0 commit comments

Comments
 (0)