Skip to content

Conversation

@thurstond
Copy link
Contributor

@thurstond thurstond commented Nov 27, 2025

I originally proposed this rewording when trap reasons were introduced in #145967 (comment). This was not adopted because there was a counter-proposal to split the enum; however, that work appears to have stalled (#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.

…, null and/or object-size error"

I originally proposed this rewording when trap reasons were introduced in llvm#145967 (comment). At the time, there was a counter-proposal to split the enum; however, that work appears to have stalled (llvm#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.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Nov 27, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 27, 2025

@llvm/pr-subscribers-clang

Author: Thurston Dang (thurstond)

Changes

I originally proposed this rewording when trap reasons were introduced in #145967 (comment). At the time, there was a counter-proposal to split the enum; however, that work appears to have stalled (#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.


Full diff: https://github.com/llvm/llvm-project/pull/169752.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/SanitizerHandler.h (+1-1)
  • (modified) clang/test/DebugInfo/Generic/ubsan-trap-reason-type-mismatch.c (+1-1)
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"

@llvmbot
Copy link
Member

llvmbot commented Nov 27, 2025

@llvm/pr-subscribers-clang-codegen

Author: Thurston Dang (thurstond)

Changes

I originally proposed this rewording when trap reasons were introduced in #145967 (comment). At the time, there was a counter-proposal to split the enum; however, that work appears to have stalled (#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.


Full diff: https://github.com/llvm/llvm-project/pull/169752.diff

2 Files Affected:

  • (modified) clang/lib/CodeGen/SanitizerHandler.h (+1-1)
  • (modified) clang/test/DebugInfo/Generic/ubsan-trap-reason-type-mismatch.c (+1-1)
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"

@thurstond
Copy link
Contributor Author

@anthonyhatran @alazarev FYI (GitHub won't let me add you as reviewers)

@EmployedRussian
Copy link
Contributor

Alignment, null and/or object-size error

May I suggest "Alignment, null, or object-size error" to make it clearer that this could be an error related to any of the three.

Copy link
Collaborator

@vitalybuka vitalybuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum is not split because we realized that it increases the binary size. These checks are most expensive, and it will make the impact even worse.

Maybe it's OK to split in "no-merge" mode.

Please wait for @delcypher

@thurstond
Copy link
Contributor Author

Alignment, null and/or object-size error

May I suggest "Alignment, null, or object-size error" to make it clearer that this could be an error related to any of the three.

Thanks for the suggestion, changed.

@thurstond thurstond changed the title [ubsan] Change "Type mismatch in operation" trap reason to "Alignment, null and/or object-size error" [ubsan] Change "Type mismatch in operation" trap reason to "Alignment, null, or object-size error" Nov 27, 2025
@thurstond
Copy link
Contributor Author

Please wait for @delcypher

Ack

@delcypher
Copy link
Contributor

LGTM. Thanks.

@thurstond thurstond merged commit 75e4438 into llvm:main Nov 27, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants