ソースを参照

LibSanitizer+AK: Add float cast overflow handler

This is not enabled by default in GCC, but is in Clang.
Daniel Bertalan 3 年 前
コミット
653d22e21f
2 ファイル変更13 行追加0 行削除
  1. 6 0
      AK/UBSanitizer.h
  2. 7 0
      Userland/Libraries/LibSanitizer/UBSanitizer.cpp

+ 6 - 0
AK/UBSanitizer.h

@@ -117,4 +117,10 @@ struct PointerOverflowData {
     SourceLocation location;
 };
 
+struct FloatCastOverflowData {
+    SourceLocation location;
+    TypeDescriptor const& from_type;
+    TypeDescriptor const& to_type;
+};
+
 }

+ 7 - 0
Userland/Libraries/LibSanitizer/UBSanitizer.cpp

@@ -231,4 +231,11 @@ void __ubsan_handle_pointer_overflow(const PointerOverflowData& data, ValueHandl
     }
     print_location(data.location);
 }
+
+void __ubsan_handle_float_cast_overflow(const FloatCastOverflowData&, ValueHandle) __attribute__((used));
+void __ubsan_handle_float_cast_overflow(const FloatCastOverflowData& data, ValueHandle)
+{
+    WARNLN_AND_DBGLN("UBSAN: overflow when casting from {} to {}", data.from_type.name(), data.to_type.name());
+    print_location(data.location);
+}
 }