File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed
Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ add_header_library(
1616 .fx_rep
1717 libc.include .llvm-libc-macros .stdfix_macros
1818 libc.src.__support.macros .attributes
19+ libc.src.__support.macros .null_check
1920 libc.src.__support.macros .optimization
2021 libc.src.__support.CPP.type_traits
2122 libc.src.__support.CPP.bit
Original file line number Diff line number Diff line change 1515#include " src/__support/CPP/type_traits.h"
1616#include " src/__support/macros/attributes.h" // LIBC_INLINE
1717#include " src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
18+ #include " src/__support/macros/null_check.h" // LIBC_CRASH_ON_VALUE
1819#include " src/__support/macros/optimization.h" // LIBC_UNLIKELY
1920#include " src/__support/math_extras.h"
2021
@@ -209,11 +210,9 @@ idiv(T x, T y) {
209210 using FXRep = FXRep<T>;
210211 using CompType = typename FXRep::CompType;
211212
212- if (y == FXRep::ZERO ()) {
213- // If the value of the second operand of the / operator is zero, the
214- // behavior is undefined. Ref: ISO/IEC TR 18037:2008(E) p.g. 16
215- return static_cast <XType>(0 );
216- }
213+ // If the value of the second operand of the / operator is zero, the
214+ // behavior is undefined. Ref: ISO/IEC TR 18037:2008(E) p.g. 16
215+ LIBC_CRASH_ON_VALUE (y, FXRep::ZERO ());
217216
218217 CompType x_comp = static_cast <CompType>(FXBits (x).get_bits ());
219218 CompType y_comp = static_cast <CompType>(FXBits (y).get_bits ());
Original file line number Diff line number Diff line change 1919 if (LIBC_UNLIKELY ((ptr) == nullptr )) \
2020 __builtin_trap (); \
2121 } while (0 )
22+ #define LIBC_CRASH_ON_VALUE (var, value ) \
23+ do { \
24+ if (LIBC_UNLIKELY ((var) == (value))) \
25+ __builtin_trap (); \
26+ } while (0 )
27+
2228#else
2329#define LIBC_CRASH_ON_NULLPTR (ptr ) \
2430 do { \
2531 } while (0 )
32+ #define LIBC_CRASH_ON_VALUE (var, value ) \
33+ do { \
34+ } while (0 )
2635#endif
2736
2837#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_NULL_CHECK_H
You can’t perform that action at this time.
0 commit comments