[clang] [Clang][CodeGen] Emit “trap reasons” on UBSan traps (PR #145967)
Vitaly Buka via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 11 11:23:20 PDT 2025
================
@@ -85,6 +85,96 @@ enum VariableTypeDescriptorKind : uint16_t {
// Miscellaneous Helper Methods
//===--------------------------------------------------------------------===//
+static llvm::StringRef GetUBSanTrapForHandler(SanitizerHandler ID) {
+ switch (ID) {
+ case SanitizerHandler::AddOverflow:
+ return "Signed integer addition overflowed";
+
+ case SanitizerHandler::BuiltinUnreachable:
+ return "_builtin_unreachable(), execution reached an unreachable program "
+ "point";
+
+ case SanitizerHandler::CFICheckFail:
+ return "Control flow integrity check failed";
+
+ case SanitizerHandler::DivremOverflow:
+ return "Signed integer divide or remainder overflowed";
+
+ case SanitizerHandler::DynamicTypeCacheMiss:
+ return "Dynamic type cache miss, member call made on an object whose "
+ "dynamic type differs from the expected type";
+
+ case SanitizerHandler::FloatCastOverflow:
+ return "Floating-point to integer conversion overflowed";
+
+ case SanitizerHandler::FunctionTypeMismatch:
+ return "Function called with mismatched signature";
+
+ case SanitizerHandler::ImplicitConversion:
+ return "Implicit integer conversion overflowed or lost data";
+
+ case SanitizerHandler::InvalidBuiltin:
+ return "Invalid use of builtin function";
+
+ case SanitizerHandler::InvalidObjCCast:
+ return "Invalid Objective-C cast";
+
+ case SanitizerHandler::LoadInvalidValue:
+ return "Loaded an invalid or uninitialized value for the type";
+
+ case SanitizerHandler::MissingReturn:
+ return "Execution reached the end of a value-returning function without "
+ "returning a value";
+
+ case SanitizerHandler::MulOverflow:
+ return "Signed integer multiplication overflowed";
+
+ case SanitizerHandler::NegateOverflow:
+ return "Signed integer negation overflowed";
+
+ case SanitizerHandler::NullabilityArg:
+ return "Passing null as an argument which is annotated with "
+ "_Nonnull";
+
+ case SanitizerHandler::NullabilityReturn:
+ return "Returning null from a function with a return type annotated with "
+ "_Nonnull";
+
+ case SanitizerHandler::NonnullArg:
+ return "Passing null pointer as an argument which is declared to never be "
+ "null";
+
+ case SanitizerHandler::NonnullReturn:
+ return "Returning null pointer from a function which is declared to never "
+ "return null";
+
+ case SanitizerHandler::OutOfBounds:
+ return "Array index out of bounds";
+
+ case SanitizerHandler::PointerOverflow:
+ return "Pointer arithmetic overflowed bounds";
+
+ case SanitizerHandler::ShiftOutOfBounds:
+ return "Shift exponent is too large for the type";
+
+ case SanitizerHandler::SubOverflow:
+ return "Signed integer subtraction overflowed";
+
+ case SanitizerHandler::TypeMismatch:
+ return "Type mismatch in operation";
----------------
vitalybuka wrote:
Let's not do that and instead fix ambiguity by splitting enum
https://github.com/llvm/llvm-project/pull/145967
More information about the cfe-commits
mailing list