Author: Vitaly Buka Date: 2026-11-12T18:05:48-08:00 New Revision: e8c5b667a571d71d79a591ef16dad7c08bd0c5ec
URL: https://github.com/llvm/llvm-project/commit/e8c5b667a571d71d79a591ef16dad7c08bd0c5ec DIFF: https://github.com/llvm/llvm-project/commit/e8c5b667a571d71d79a591ef16dad7c08bd0c5ec.diff LOG: [Clang][CFI] Don't report sanitizer stats for unchecked VFE loads (#241641) With virtual function elimination (3b598b9c867a), `EmitVTableTypeCheckedLoad` is also used for calls that have no `cfi-vcall` check, such as calls in `no_sanitize("cfi-vcall")` functions or on ignorelisted classes. It reported `-fsanitize-stats` for these calls anyway, so the stats counted checks that were never performed. Report stats only when the check is emitted. Assisted-by: Gemini Added: Modified: clang/lib/CodeGen/CGClass.cpp clang/test/CodeGenCXX/cfi-stats.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index 4c57f92cf84ae..00bc1eb0848d4 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -3004,8 +3004,6 @@ llvm::Value *CodeGenFunction::EmitVTableTypeCheckedLoad( auto CheckHandler = SanitizerHandler::CFICheckFail; SanitizerDebugLocation SanScope(this, {CheckOrdinal}, CheckHandler); - EmitSanitizerStatReport(llvm::SanStat_CFI_VCall); - CanQualType T = CGM.getContext().getCanonicalTagType(RD); llvm::Metadata *MD = CGM.CreateMetadataIdentifierForType(T); llvm::Value *TypeId = llvm::MetadataAsValue::get(CGM.getLLVMContext(), MD); @@ -3023,6 +3021,7 @@ llvm::Value *CodeGenFunction::EmitVTableTypeCheckedLoad( if (SanOpts.has(SanitizerKind::CFIVCall) && !getContext().getNoSanitizeList().containsType(SanitizerKind::CFIVCall, TypeName)) { + EmitSanitizerStatReport(llvm::SanStat_CFI_VCall); EmitCheck(std::make_pair(CheckResult, CheckOrdinal), CheckHandler, {}, {}); } diff --git a/clang/test/CodeGenCXX/cfi-stats.cpp b/clang/test/CodeGenCXX/cfi-stats.cpp index f3690e41945a7..261092984fa2b 100644 --- a/clang/test/CodeGenCXX/cfi-stats.cpp +++ b/clang/test/CodeGenCXX/cfi-stats.cpp @@ -3,7 +3,7 @@ // RUN: %clang_cc1 -triple x86_64-unknown-linux -flto -flto-unit -fvisibility=hidden -fsanitize=cfi-vcall,cfi-nvcall,cfi-derived-cast,cfi-unrelated-cast,cfi-icall -fwhole-program-vtables -fvirtual-function-elimination -fsanitize-stats -emit-llvm -o - %s | FileCheck --check-prefix=VFE %s // CHECK: [[STATS:@[^ ]*]] = internal global { ptr, i32, [5 x [2 x ptr]] } { ptr null, i32 5, [5 x [2 x ptr]] -// VFE: [[STATS:@[^ ]*]] = internal global { ptr, i32, [6 x [2 x ptr]] } { ptr null, i32 6, [6 x [2 x ptr]] +// VFE: [[STATS:@[^ ]*]] = internal global { ptr, i32, [5 x [2 x ptr]] } { ptr null, i32 5, [5 x [2 x ptr]] // CHECK: {{\[\[}}2 x ptr] zeroinitializer, // CHECK: [2 x ptr] [ptr null, ptr inttoptr (i64 2305843009213693952 to ptr)], // CHECK: [2 x ptr] [ptr null, ptr inttoptr (i64 4611686018427387904 to ptr)], @@ -54,7 +54,7 @@ extern "C" void icall(void (*p)()) { // VFE-LABEL: @vcall_unsanitized( extern "C" __attribute__((no_sanitize("cfi-vcall"))) void vcall_unsanitized(A *a) { // CHECK-NOT: @__sanitizer_stat_report - // VFE: call void @__sanitizer_stat_report({{.*}}[[STATS]]{{.*}}i64 96) + // VFE-NOT: @__sanitizer_stat_report a->vf(); // CHECK: ret void // VFE: ret void _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
