From 4c599e3c7fa6ecdda8319970ea8e42ba30bc1a35 Mon Sep 17 00:00:00 2001 From: Thurston Dang Date: Thu, 27 Nov 2025 00:51:25 +0000 Subject: [PATCH 1/2] [ubsan] Change "Type mismatch in operation" trap reason to "Alignment, null and/or object-size error" I originally proposed this rewording when trap reasons were introduced in https://github.com/llvm/llvm-project/pull/145967#discussion_r2196212344. At the time, there was a counter-proposal to split the enum; however, that work appears to have stalled (https://github.com/llvm/llvm-project/pull/151243). In the meantime, there has been an additional datapoint that the current wording is confusing to users. Thus, let's reword it now to prevent further confusion. --- clang/lib/CodeGen/SanitizerHandler.h | 2 +- clang/test/DebugInfo/Generic/ubsan-trap-reason-type-mismatch.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/SanitizerHandler.h b/clang/lib/CodeGen/SanitizerHandler.h index a66e7ab354eb2..ff932a9c452e1 100644 --- a/clang/lib/CodeGen/SanitizerHandler.h +++ b/clang/lib/CodeGen/SanitizerHandler.h @@ -64,7 +64,7 @@ SANITIZER_CHECK(SubOverflow, sub_overflow, 0, \ "Integer subtraction overflowed") \ SANITIZER_CHECK(TypeMismatch, type_mismatch, 1, \ - "Type mismatch in operation") \ + "Alignment, null and/or object-size error") \ SANITIZER_CHECK(AlignmentAssumption, alignment_assumption, 0, \ "Alignment assumption violated") \ SANITIZER_CHECK( \ diff --git a/clang/test/DebugInfo/Generic/ubsan-trap-reason-type-mismatch.c b/clang/test/DebugInfo/Generic/ubsan-trap-reason-type-mismatch.c index 802ec91b53a0d..a4c4c8cd8db2f 100644 --- a/clang/test/DebugInfo/Generic/ubsan-trap-reason-type-mismatch.c +++ b/clang/test/DebugInfo/Generic/ubsan-trap-reason-type-mismatch.c @@ -6,4 +6,4 @@ int type_mismatch(int *p) { return *p; } // CHECK-LABEL: @type_mismatch // CHECK: call void @llvm.ubsantrap(i8 22) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: [[MSG]] = distinct !DISubprogram(name: "__clang_trap_msg$Undefined Behavior Sanitizer$Type mismatch in operation" +// CHECK: [[MSG]] = distinct !DISubprogram(name: "__clang_trap_msg$Undefined Behavior Sanitizer$Alignment, null and/or object-size error" From 479acb218637e0889adc3024e676d32dd41a0e00 Mon Sep 17 00:00:00 2001 From: Thurston Dang Date: Thu, 27 Nov 2025 01:40:21 +0000 Subject: [PATCH 2/2] Wording suggestion from EmployedRussian --- clang/lib/CodeGen/SanitizerHandler.h | 2 +- clang/test/DebugInfo/Generic/ubsan-trap-reason-type-mismatch.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/SanitizerHandler.h b/clang/lib/CodeGen/SanitizerHandler.h index ff932a9c452e1..871e17c22d3fa 100644 --- a/clang/lib/CodeGen/SanitizerHandler.h +++ b/clang/lib/CodeGen/SanitizerHandler.h @@ -64,7 +64,7 @@ SANITIZER_CHECK(SubOverflow, sub_overflow, 0, \ "Integer subtraction overflowed") \ SANITIZER_CHECK(TypeMismatch, type_mismatch, 1, \ - "Alignment, null and/or object-size error") \ + "Alignment, null, or object-size error") \ SANITIZER_CHECK(AlignmentAssumption, alignment_assumption, 0, \ "Alignment assumption violated") \ SANITIZER_CHECK( \ diff --git a/clang/test/DebugInfo/Generic/ubsan-trap-reason-type-mismatch.c b/clang/test/DebugInfo/Generic/ubsan-trap-reason-type-mismatch.c index a4c4c8cd8db2f..5960930c04171 100644 --- a/clang/test/DebugInfo/Generic/ubsan-trap-reason-type-mismatch.c +++ b/clang/test/DebugInfo/Generic/ubsan-trap-reason-type-mismatch.c @@ -6,4 +6,4 @@ int type_mismatch(int *p) { return *p; } // CHECK-LABEL: @type_mismatch // CHECK: call void @llvm.ubsantrap(i8 22) {{.*}}!dbg [[LOC:![0-9]+]] // CHECK: [[LOC]] = !DILocation(line: 0, scope: [[MSG:![0-9]+]], {{.+}}) -// CHECK: [[MSG]] = distinct !DISubprogram(name: "__clang_trap_msg$Undefined Behavior Sanitizer$Alignment, null and/or object-size error" +// CHECK: [[MSG]] = distinct !DISubprogram(name: "__clang_trap_msg$Undefined Behavior Sanitizer$Alignment, null, or object-size error"