authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-16 14:30:28-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-05-16 14:30:28-07:00
logf33b3fc3eae54b9d1159fc5a7a69a4b0e4aceca6
tree30541782615edb604ecdbc1c5205b7e9caf54131
parenta0de0adb8e22222716d4d42b26490461ecd67de3

zig.h: add casts for overflow arithmetic operations

This avoids the following error: ``` error: incompatible pointer types passing 'int64_t *' (aka 'long long *') to parameter of type 'long *' overflow = __builtin_saddl_overflow(lhs, rhs, res); ^~~ ``` My previous understanding was that this error would not occur because prior to this line we check that int64_t is equivalent to long, like this: ```c ``` However, it appears that this is still a warning in C if int64_t is primarily aliased to `long long`, even though `long` and `long long` are the same thing.

1 files changed, 81 insertions(+), 81 deletions(-)

src/link/C/zig.h+81-81
......@@ -415,15 +415,15 @@ static inline long long zig_subw_longlong(long long lhs, long long rhs, long lon
415415static inline bool zig_addo_i8(int8_t lhs, int8_t rhs, int8_t *res, int8_t min, int8_t max) {
416416#if defined(__GNUC__) && INT8_MAX == INT_MAX
417417 if (min == INT8_MIN && max == INT8_MAX) {
418 return __builtin_sadd_overflow(lhs, rhs, res);
418 return __builtin_sadd_overflow(lhs, rhs, (int*)res);
419419 }
420420#elif defined(__GNUC__) && INT8_MAX == LONG_MAX
421421 if (min == INT8_MIN && max == INT8_MAX) {
422 return __builtin_saddl_overflow(lhs, rhs, res);
422 return __builtin_saddl_overflow(lhs, rhs, (long*)res);
423423 }
424424#elif defined(__GNUC__) && INT8_MAX == LLONG_MAX
425425 if (min == INT8_MIN && max == INT8_MAX) {
426 return __builtin_saddll_overflow(lhs, rhs, res);
426 return __builtin_saddll_overflow(lhs, rhs, (long long*)res);
427427 }
428428#endif
429429 int16_t big_result = (int16_t)lhs + (int16_t)rhs;
......@@ -442,15 +442,15 @@ static inline bool zig_addo_i8(int8_t lhs, int8_t rhs, int8_t *res, int8_t min,
442442static inline bool zig_addo_i16(int16_t lhs, int16_t rhs, int16_t *res, int16_t min, int16_t max) {
443443#if defined(__GNUC__) && INT16_MAX == INT_MAX
444444 if (min == INT16_MIN && max == INT16_MAX) {
445 return __builtin_sadd_overflow(lhs, rhs, res);
445 return __builtin_sadd_overflow(lhs, rhs, (int*)res);
446446 }
447447#elif defined(__GNUC__) && INT16_MAX == LONG_MAX
448448 if (min == INT16_MIN && max == INT16_MAX) {
449 return __builtin_saddl_overflow(lhs, rhs, res);
449 return __builtin_saddl_overflow(lhs, rhs, (long*)res);
450450 }
451451#elif defined(__GNUC__) && INT16_MAX == LLONG_MAX
452452 if (min == INT16_MIN && max == INT16_MAX) {
453 return __builtin_saddll_overflow(lhs, rhs, res);
453 return __builtin_saddll_overflow(lhs, rhs, (long long*)res);
454454 }
455455#endif
456456 int32_t big_result = (int32_t)lhs + (int32_t)rhs;
......@@ -469,15 +469,15 @@ static inline bool zig_addo_i16(int16_t lhs, int16_t rhs, int16_t *res, int16_t
469469static inline bool zig_addo_i32(int32_t lhs, int32_t rhs, int32_t *res, int32_t min, int32_t max) {
470470#if defined(__GNUC__) && INT32_MAX == INT_MAX
471471 if (min == INT32_MIN && max == INT32_MAX) {
472 return __builtin_sadd_overflow(lhs, rhs, res);
472 return __builtin_sadd_overflow(lhs, rhs, (int*)res);
473473 }
474474#elif defined(__GNUC__) && INT32_MAX == LONG_MAX
475475 if (min == INT32_MIN && max == INT32_MAX) {
476 return __builtin_saddl_overflow(lhs, rhs, res);
476 return __builtin_saddl_overflow(lhs, rhs, (long*)res);
477477 }
478478#elif defined(__GNUC__) && INT32_MAX == LLONG_MAX
479479 if (min == INT32_MIN && max == INT32_MAX) {
480 return __builtin_saddll_overflow(lhs, rhs, res);
480 return __builtin_saddll_overflow(lhs, rhs, (long long*)res);
481481 }
482482#endif
483483 int64_t big_result = (int64_t)lhs + (int64_t)rhs;
......@@ -496,11 +496,11 @@ static inline bool zig_addo_i32(int32_t lhs, int32_t rhs, int32_t *res, int32_t
496496static inline bool zig_addo_i64(int64_t lhs, int64_t rhs, int64_t *res, int64_t min, int64_t max) {
497497 bool overflow;
498498#if defined(__GNUC__) && INT64_MAX == INT_MAX
499 overflow = __builtin_sadd_overflow(lhs, rhs, res);
499 overflow = __builtin_sadd_overflow(lhs, rhs, (int*)res);
500500#elif defined(__GNUC__) && INT64_MAX == LONG_MAX
501 overflow = __builtin_saddl_overflow(lhs, rhs, res);
501 overflow = __builtin_saddl_overflow(lhs, rhs, (long*)res);
502502#elif defined(__GNUC__) && INT64_MAX == LLONG_MAX
503 overflow = __builtin_saddll_overflow(lhs, rhs, res);
503 overflow = __builtin_saddll_overflow(lhs, rhs, (long long*)res);
504504#else
505505 int int_overflow;
506506 *res = __addodi4(lhs, rhs, &int_overflow);
......@@ -521,11 +521,11 @@ static inline bool zig_addo_i64(int64_t lhs, int64_t rhs, int64_t *res, int64_t
521521static inline bool zig_addo_i128(int128_t lhs, int128_t rhs, int128_t *res, int128_t min, int128_t max) {
522522 bool overflow;
523523#if defined(__GNUC__) && INT128_MAX == INT_MAX
524 overflow = __builtin_sadd_overflow(lhs, rhs, res);
524 overflow = __builtin_sadd_overflow(lhs, rhs, (int*)res);
525525#elif defined(__GNUC__) && INT128_MAX == LONG_MAX
526 overflow = __builtin_saddl_overflow(lhs, rhs, res);
526 overflow = __builtin_saddl_overflow(lhs, rhs, (long*)res);
527527#elif defined(__GNUC__) && INT128_MAX == LLONG_MAX
528 overflow = __builtin_saddll_overflow(lhs, rhs, res);
528 overflow = __builtin_saddll_overflow(lhs, rhs, (long long*)res);
529529#else
530530 int int_overflow;
531531 *res = __addoti4(lhs, rhs, &int_overflow);
......@@ -546,15 +546,15 @@ static inline bool zig_addo_i128(int128_t lhs, int128_t rhs, int128_t *res, int1
546546static inline bool zig_addo_u8(uint8_t lhs, uint8_t rhs, uint8_t *res, uint8_t max) {
547547#if defined(__GNUC__) && UINT8_MAX == UINT_MAX
548548 if (max == UINT8_MAX) {
549 return __builtin_uadd_overflow(lhs, rhs, res);
549 return __builtin_uadd_overflow(lhs, rhs, (unsigned int*)res);
550550 }
551551#elif defined(__GNUC__) && UINT8_MAX == ULONG_MAX
552552 if (max == UINT8_MAX) {
553 return __builtin_uaddl_overflow(lhs, rhs, res);
553 return __builtin_uaddl_overflow(lhs, rhs, (unsigned long*)res);
554554 }
555555#elif defined(__GNUC__) && UINT8_MAX == ULLONG_MAX
556556 if (max == UINT8_MAX) {
557 return __builtin_uaddll_overflow(lhs, rhs, res);
557 return __builtin_uaddll_overflow(lhs, rhs, (unsigned long long*)res);
558558 }
559559#endif
560560 uint16_t big_result = (uint16_t)lhs + (uint16_t)rhs;
......@@ -569,15 +569,15 @@ static inline bool zig_addo_u8(uint8_t lhs, uint8_t rhs, uint8_t *res, uint8_t m
569569static inline uint16_t zig_addo_u16(uint16_t lhs, uint16_t rhs, uint16_t *res, uint16_t max) {
570570#if defined(__GNUC__) && UINT16_MAX == UINT_MAX
571571 if (max == UINT16_MAX) {
572 return __builtin_uadd_overflow(lhs, rhs, res);
572 return __builtin_uadd_overflow(lhs, rhs, (unsigned int*)res);
573573 }
574574#elif defined(__GNUC__) && UINT16_MAX == ULONG_MAX
575575 if (max == UINT16_MAX) {
576 return __builtin_uaddl_overflow(lhs, rhs, res);
576 return __builtin_uaddl_overflow(lhs, rhs, (unsigned long*)res);
577577 }
578578#elif defined(__GNUC__) && UINT16_MAX == ULLONG_MAX
579579 if (max == UINT16_MAX) {
580 return __builtin_uaddll_overflow(lhs, rhs, res);
580 return __builtin_uaddll_overflow(lhs, rhs, (unsigned long long*)res);
581581 }
582582#endif
583583 uint32_t big_result = (uint32_t)lhs + (uint32_t)rhs;
......@@ -592,15 +592,15 @@ static inline uint16_t zig_addo_u16(uint16_t lhs, uint16_t rhs, uint16_t *res, u
592592static inline uint32_t zig_addo_u32(uint32_t lhs, uint32_t rhs, uint32_t *res, uint32_t max) {
593593#if defined(__GNUC__) && UINT32_MAX == UINT_MAX
594594 if (max == UINT32_MAX) {
595 return __builtin_uadd_overflow(lhs, rhs, res);
595 return __builtin_uadd_overflow(lhs, rhs, (unsigned int*)res);
596596 }
597597#elif defined(__GNUC__) && UINT32_MAX == ULONG_MAX
598598 if (max == UINT32_MAX) {
599 return __builtin_uaddl_overflow(lhs, rhs, res);
599 return __builtin_uaddl_overflow(lhs, rhs, (unsigned long*)res);
600600 }
601601#elif defined(__GNUC__) && UINT32_MAX == ULLONG_MAX
602602 if (max == UINT32_MAX) {
603 return __builtin_uaddll_overflow(lhs, rhs, res);
603 return __builtin_uaddll_overflow(lhs, rhs, (unsigned long long*)res);
604604 }
605605#endif
606606 uint64_t big_result = (uint64_t)lhs + (uint64_t)rhs;
......@@ -615,11 +615,11 @@ static inline uint32_t zig_addo_u32(uint32_t lhs, uint32_t rhs, uint32_t *res, u
615615static inline uint64_t zig_addo_u64(uint64_t lhs, uint64_t rhs, uint64_t *res, uint64_t max) {
616616 bool overflow;
617617#if defined(__GNUC__) && UINT64_MAX == UINT_MAX
618 overflow = __builtin_uadd_overflow(lhs, rhs, res);
618 overflow = __builtin_uadd_overflow(lhs, rhs, (unsigned int*)res);
619619#elif defined(__GNUC__) && UINT64_MAX == ULONG_MAX
620 overflow = __builtin_uaddl_overflow(lhs, rhs, res);
620 overflow = __builtin_uaddl_overflow(lhs, rhs, (unsigned long*)res);
621621#elif defined(__GNUC__) && UINT64_MAX == ULLONG_MAX
622 overflow = __builtin_uaddll_overflow(lhs, rhs, res);
622 overflow = __builtin_uaddll_overflow(lhs, rhs, (unsigned long long*)res);
623623#else
624624 int int_overflow;
625625 *res = __uaddodi4(lhs, rhs, &int_overflow);
......@@ -645,15 +645,15 @@ static inline uint128_t zig_addo_u128(uint128_t lhs, uint128_t rhs, uint128_t *r
645645static inline bool zig_subo_i8(int8_t lhs, int8_t rhs, int8_t *res, int8_t min, int8_t max) {
646646#if defined(__GNUC__) && INT8_MAX == INT_MAX
647647 if (min == INT8_MIN && max == INT8_MAX) {
648 return __builtin_ssub_overflow(lhs, rhs, res);
648 return __builtin_ssub_overflow(lhs, rhs, (int*)res);
649649 }
650650#elif defined(__GNUC__) && INT8_MAX == LONG_MAX
651651 if (min == INT8_MIN && max == INT8_MAX) {
652 return __builtin_ssubl_overflow(lhs, rhs, res);
652 return __builtin_ssubl_overflow(lhs, rhs, (long*)res);
653653 }
654654#elif defined(__GNUC__) && INT8_MAX == LLONG_MAX
655655 if (min == INT8_MIN && max == INT8_MAX) {
656 return __builtin_ssubll_overflow(lhs, rhs, res);
656 return __builtin_ssubll_overflow(lhs, rhs, (long long*)res);
657657 }
658658#endif
659659 int16_t big_result = (int16_t)lhs - (int16_t)rhs;
......@@ -672,15 +672,15 @@ static inline bool zig_subo_i8(int8_t lhs, int8_t rhs, int8_t *res, int8_t min,
672672static inline bool zig_subo_i16(int16_t lhs, int16_t rhs, int16_t *res, int16_t min, int16_t max) {
673673#if defined(__GNUC__) && INT16_MAX == INT_MAX
674674 if (min == INT16_MIN && max == INT16_MAX) {
675 return __builtin_ssub_overflow(lhs, rhs, res);
675 return __builtin_ssub_overflow(lhs, rhs, (int*)res);
676676 }
677677#elif defined(__GNUC__) && INT16_MAX == LONG_MAX
678678 if (min == INT16_MIN && max == INT16_MAX) {
679 return __builtin_ssubl_overflow(lhs, rhs, res);
679 return __builtin_ssubl_overflow(lhs, rhs, (long*)res);
680680 }
681681#elif defined(__GNUC__) && INT16_MAX == LLONG_MAX
682682 if (min == INT16_MIN && max == INT16_MAX) {
683 return __builtin_ssubll_overflow(lhs, rhs, res);
683 return __builtin_ssubll_overflow(lhs, rhs, (long long*)res);
684684 }
685685#endif
686686 int32_t big_result = (int32_t)lhs - (int32_t)rhs;
......@@ -699,15 +699,15 @@ static inline bool zig_subo_i16(int16_t lhs, int16_t rhs, int16_t *res, int16_t
699699static inline bool zig_subo_i32(int32_t lhs, int32_t rhs, int32_t *res, int32_t min, int32_t max) {
700700#if defined(__GNUC__) && INT32_MAX == INT_MAX
701701 if (min == INT32_MIN && max == INT32_MAX) {
702 return __builtin_ssub_overflow(lhs, rhs, res);
702 return __builtin_ssub_overflow(lhs, rhs, (int*)res);
703703 }
704704#elif defined(__GNUC__) && INT32_MAX == LONG_MAX
705705 if (min == INT32_MIN && max == INT32_MAX) {
706 return __builtin_ssubl_overflow(lhs, rhs, res);
706 return __builtin_ssubl_overflow(lhs, rhs, (long*)res);
707707 }
708708#elif defined(__GNUC__) && INT32_MAX == LLONG_MAX
709709 if (min == INT32_MIN && max == INT32_MAX) {
710 return __builtin_ssubll_overflow(lhs, rhs, res);
710 return __builtin_ssubll_overflow(lhs, rhs, (long long*)res);
711711 }
712712#endif
713713 int64_t big_result = (int64_t)lhs - (int64_t)rhs;
......@@ -726,11 +726,11 @@ static inline bool zig_subo_i32(int32_t lhs, int32_t rhs, int32_t *res, int32_t
726726static inline bool zig_subo_i64(int64_t lhs, int64_t rhs, int64_t *res, int64_t min, int64_t max) {
727727 bool overflow;
728728#if defined(__GNUC__) && INT64_MAX == INT_MAX
729 overflow = __builtin_ssub_overflow(lhs, rhs, res);
729 overflow = __builtin_ssub_overflow(lhs, rhs, (int*)res);
730730#elif defined(__GNUC__) && INT64_MAX == LONG_MAX
731 overflow = __builtin_ssubl_overflow(lhs, rhs, res);
731 overflow = __builtin_ssubl_overflow(lhs, rhs, (long*)res);
732732#elif defined(__GNUC__) && INT64_MAX == LLONG_MAX
733 overflow = __builtin_ssubll_overflow(lhs, rhs, res);
733 overflow = __builtin_ssubll_overflow(lhs, rhs, (long long*)res);
734734#else
735735 int int_overflow;
736736 *res = __subodi4(lhs, rhs, &int_overflow);
......@@ -751,11 +751,11 @@ static inline bool zig_subo_i64(int64_t lhs, int64_t rhs, int64_t *res, int64_t
751751static inline bool zig_subo_i128(int128_t lhs, int128_t rhs, int128_t *res, int128_t min, int128_t max) {
752752 bool overflow;
753753#if defined(__GNUC__) && INT128_MAX == INT_MAX
754 overflow = __builtin_ssub_overflow(lhs, rhs, res);
754 overflow = __builtin_ssub_overflow(lhs, rhs, (int*)res);
755755#elif defined(__GNUC__) && INT128_MAX == LONG_MAX
756 overflow = __builtin_ssubl_overflow(lhs, rhs, res);
756 overflow = __builtin_ssubl_overflow(lhs, rhs, (long*)res);
757757#elif defined(__GNUC__) && INT128_MAX == LLONG_MAX
758 overflow = __builtin_ssubll_overflow(lhs, rhs, res);
758 overflow = __builtin_ssubll_overflow(lhs, rhs, (long long*)res);
759759#else
760760 int int_overflow;
761761 *res = __suboti4(lhs, rhs, &int_overflow);
......@@ -775,11 +775,11 @@ static inline bool zig_subo_i128(int128_t lhs, int128_t rhs, int128_t *res, int1
775775
776776static inline bool zig_subo_u8(uint8_t lhs, uint8_t rhs, uint8_t *res, uint8_t max) {
777777#if defined(__GNUC__) && UINT8_MAX == UINT_MAX
778 return __builtin_usub_overflow(lhs, rhs, res);
778 return __builtin_usub_overflow(lhs, rhs, (unsigned int*)res);
779779#elif defined(__GNUC__) && UINT8_MAX == ULONG_MAX
780 return __builtin_usubl_overflow(lhs, rhs, res);
780 return __builtin_usubl_overflow(lhs, rhs, (unsigned long*)res);
781781#elif defined(__GNUC__) && UINT8_MAX == ULLONG_MAX
782 return __builtin_usubll_overflow(lhs, rhs, res);
782 return __builtin_usubll_overflow(lhs, rhs, (unsigned long long*)res);
783783#endif
784784 if (rhs > lhs) {
785785 *res = max - (rhs - lhs - 1);
......@@ -791,11 +791,11 @@ static inline bool zig_subo_u8(uint8_t lhs, uint8_t rhs, uint8_t *res, uint8_t m
791791
792792static inline uint16_t zig_subo_u16(uint16_t lhs, uint16_t rhs, uint16_t *res, uint16_t max) {
793793#if defined(__GNUC__) && UINT16_MAX == UINT_MAX
794 return __builtin_usub_overflow(lhs, rhs, res);
794 return __builtin_usub_overflow(lhs, rhs, (unsigned int*)res);
795795#elif defined(__GNUC__) && UINT16_MAX == ULONG_MAX
796 return __builtin_usubl_overflow(lhs, rhs, res);
796 return __builtin_usubl_overflow(lhs, rhs, (unsigned long*)res);
797797#elif defined(__GNUC__) && UINT16_MAX == ULLONG_MAX
798 return __builtin_usubll_overflow(lhs, rhs, res);
798 return __builtin_usubll_overflow(lhs, rhs, (unsigned long long*)res);
799799#endif
800800 if (rhs > lhs) {
801801 *res = max - (rhs - lhs - 1);
......@@ -808,11 +808,11 @@ static inline uint16_t zig_subo_u16(uint16_t lhs, uint16_t rhs, uint16_t *res, u
808808static inline uint32_t zig_subo_u32(uint32_t lhs, uint32_t rhs, uint32_t *res, uint32_t max) {
809809 if (max == UINT32_MAX) {
810810#if defined(__GNUC__) && UINT32_MAX == UINT_MAX
811 return __builtin_usub_overflow(lhs, rhs, res);
811 return __builtin_usub_overflow(lhs, rhs, (unsigned int*)res);
812812#elif defined(__GNUC__) && UINT32_MAX == ULONG_MAX
813 return __builtin_usubl_overflow(lhs, rhs, res);
813 return __builtin_usubl_overflow(lhs, rhs, (unsigned long*)res);
814814#elif defined(__GNUC__) && UINT32_MAX == ULLONG_MAX
815 return __builtin_usubll_overflow(lhs, rhs, res);
815 return __builtin_usubll_overflow(lhs, rhs, (unsigned long long*)res);
816816#endif
817817 int int_overflow;
818818 *res = __usubosi4(lhs, rhs, &int_overflow);
......@@ -830,11 +830,11 @@ static inline uint32_t zig_subo_u32(uint32_t lhs, uint32_t rhs, uint32_t *res, u
830830static inline uint64_t zig_subo_u64(uint64_t lhs, uint64_t rhs, uint64_t *res, uint64_t max) {
831831 if (max == UINT64_MAX) {
832832#if defined(__GNUC__) && UINT64_MAX == UINT_MAX
833 return __builtin_usub_overflow(lhs, rhs, res);
833 return __builtin_usub_overflow(lhs, rhs, (unsigned int*)res);
834834#elif defined(__GNUC__) && UINT64_MAX == ULONG_MAX
835 return __builtin_usubl_overflow(lhs, rhs, res);
835 return __builtin_usubl_overflow(lhs, rhs, (unsigned long*)res);
836836#elif defined(__GNUC__) && UINT64_MAX == ULLONG_MAX
837 return __builtin_usubll_overflow(lhs, rhs, res);
837 return __builtin_usubll_overflow(lhs, rhs, (unsigned long long*)res);
838838#else
839839 int int_overflow;
840840 *res = __usubodi4(lhs, rhs, &int_overflow);
......@@ -868,15 +868,15 @@ static inline uint128_t zig_subo_u128(uint128_t lhs, uint128_t rhs, uint128_t *r
868868static inline bool zig_mulo_i8(int8_t lhs, int8_t rhs, int8_t *res, int8_t min, int8_t max) {
869869#if defined(__GNUC__) && INT8_MAX == INT_MAX
870870 if (min == INT8_MIN && max == INT8_MAX) {
871 return __builtin_smul_overflow(lhs, rhs, res);
871 return __builtin_smul_overflow(lhs, rhs, (int*)res);
872872 }
873873#elif defined(__GNUC__) && INT8_MAX == LONG_MAX
874874 if (min == INT8_MIN && max == INT8_MAX) {
875 return __builtin_smull_overflow(lhs, rhs, res);
875 return __builtin_smull_overflow(lhs, rhs, (long*)res);
876876 }
877877#elif defined(__GNUC__) && INT8_MAX == LLONG_MAX
878878 if (min == INT8_MIN && max == INT8_MAX) {
879 return __builtin_smulll_overflow(lhs, rhs, res);
879 return __builtin_smulll_overflow(lhs, rhs, (long long*)res);
880880 }
881881#endif
882882 int16_t big_result = (int16_t)lhs * (int16_t)rhs;
......@@ -895,15 +895,15 @@ static inline bool zig_mulo_i8(int8_t lhs, int8_t rhs, int8_t *res, int8_t min,
895895static inline bool zig_mulo_i16(int16_t lhs, int16_t rhs, int16_t *res, int16_t min, int16_t max) {
896896#if defined(__GNUC__) && INT16_MAX == INT_MAX
897897 if (min == INT16_MIN && max == INT16_MAX) {
898 return __builtin_smul_overflow(lhs, rhs, res);
898 return __builtin_smul_overflow(lhs, rhs, (int*)res);
899899 }
900900#elif defined(__GNUC__) && INT16_MAX == LONG_MAX
901901 if (min == INT16_MIN && max == INT16_MAX) {
902 return __builtin_smull_overflow(lhs, rhs, res);
902 return __builtin_smull_overflow(lhs, rhs, (long*)res);
903903 }
904904#elif defined(__GNUC__) && INT16_MAX == LLONG_MAX
905905 if (min == INT16_MIN && max == INT16_MAX) {
906 return __builtin_smulll_overflow(lhs, rhs, res);
906 return __builtin_smulll_overflow(lhs, rhs, (long long*)res);
907907 }
908908#endif
909909 int32_t big_result = (int32_t)lhs * (int32_t)rhs;
......@@ -922,15 +922,15 @@ static inline bool zig_mulo_i16(int16_t lhs, int16_t rhs, int16_t *res, int16_t
922922static inline bool zig_mulo_i32(int32_t lhs, int32_t rhs, int32_t *res, int32_t min, int32_t max) {
923923#if defined(__GNUC__) && INT32_MAX == INT_MAX
924924 if (min == INT32_MIN && max == INT32_MAX) {
925 return __builtin_smul_overflow(lhs, rhs, res);
925 return __builtin_smul_overflow(lhs, rhs, (int*)res);
926926 }
927927#elif defined(__GNUC__) && INT32_MAX == LONG_MAX
928928 if (min == INT32_MIN && max == INT32_MAX) {
929 return __builtin_smull_overflow(lhs, rhs, res);
929 return __builtin_smull_overflow(lhs, rhs, (long*)res);
930930 }
931931#elif defined(__GNUC__) && INT32_MAX == LLONG_MAX
932932 if (min == INT32_MIN && max == INT32_MAX) {
933 return __builtin_smulll_overflow(lhs, rhs, res);
933 return __builtin_smulll_overflow(lhs, rhs, (long long*)res);
934934 }
935935#endif
936936 int64_t big_result = (int64_t)lhs * (int64_t)rhs;
......@@ -949,11 +949,11 @@ static inline bool zig_mulo_i32(int32_t lhs, int32_t rhs, int32_t *res, int32_t
949949static inline bool zig_mulo_i64(int64_t lhs, int64_t rhs, int64_t *res, int64_t min, int64_t max) {
950950 bool overflow;
951951#if defined(__GNUC__) && INT64_MAX == INT_MAX
952 overflow = __builtin_smul_overflow(lhs, rhs, res);
952 overflow = __builtin_smul_overflow(lhs, rhs, (int*)res);
953953#elif defined(__GNUC__) && INT64_MAX == LONG_MAX
954 overflow = __builtin_smull_overflow(lhs, rhs, res);
954 overflow = __builtin_smull_overflow(lhs, rhs, (long*)res);
955955#elif defined(__GNUC__) && INT64_MAX == LLONG_MAX
956 overflow = __builtin_smulll_overflow(lhs, rhs, res);
956 overflow = __builtin_smulll_overflow(lhs, rhs, (long long*)res);
957957#else
958958 int int_overflow;
959959 *res = __mulodi4(lhs, rhs, &int_overflow);
......@@ -974,11 +974,11 @@ static inline bool zig_mulo_i64(int64_t lhs, int64_t rhs, int64_t *res, int64_t
974974static inline bool zig_mulo_i128(int128_t lhs, int128_t rhs, int128_t *res, int128_t min, int128_t max) {
975975 bool overflow;
976976#if defined(__GNUC__) && INT128_MAX == INT_MAX
977 overflow = __builtin_smul_overflow(lhs, rhs, res);
977 overflow = __builtin_smul_overflow(lhs, rhs, (int*)res);
978978#elif defined(__GNUC__) && INT128_MAX == LONG_MAX
979 overflow = __builtin_smull_overflow(lhs, rhs, res);
979 overflow = __builtin_smull_overflow(lhs, rhs, (long*)res);
980980#elif defined(__GNUC__) && INT128_MAX == LLONG_MAX
981 overflow = __builtin_smulll_overflow(lhs, rhs, res);
981 overflow = __builtin_smulll_overflow(lhs, rhs, (long long*)res);
982982#else
983983 int int_overflow;
984984 *res = __muloti4(lhs, rhs, &int_overflow);
......@@ -999,15 +999,15 @@ static inline bool zig_mulo_i128(int128_t lhs, int128_t rhs, int128_t *res, int1
999999static inline bool zig_mulo_u8(uint8_t lhs, uint8_t rhs, uint8_t *res, uint8_t max) {
10001000#if defined(__GNUC__) && UINT8_MAX == UINT_MAX
10011001 if (max == UINT8_MAX) {
1002 return __builtin_umul_overflow(lhs, rhs, res);
1002 return __builtin_umul_overflow(lhs, rhs, (unsigned int*)res);
10031003 }
10041004#elif defined(__GNUC__) && UINT8_MAX == ULONG_MAX
10051005 if (max == UINT8_MAX) {
1006 return __builtin_umull_overflow(lhs, rhs, res);
1006 return __builtin_umull_overflow(lhs, rhs, (unsigned long*)res);
10071007 }
10081008#elif defined(__GNUC__) && UINT8_MAX == ULLONG_MAX
10091009 if (max == UINT8_MAX) {
1010 return __builtin_umulll_overflow(lhs, rhs, res);
1010 return __builtin_umulll_overflow(lhs, rhs, (unsigned long long*)res);
10111011 }
10121012#endif
10131013 uint16_t big_result = (uint16_t)lhs * (uint16_t)rhs;
......@@ -1022,15 +1022,15 @@ static inline bool zig_mulo_u8(uint8_t lhs, uint8_t rhs, uint8_t *res, uint8_t m
10221022static inline uint16_t zig_mulo_u16(uint16_t lhs, uint16_t rhs, uint16_t *res, uint16_t max) {
10231023#if defined(__GNUC__) && UINT16_MAX == UINT_MAX
10241024 if (max == UINT16_MAX) {
1025 return __builtin_umul_overflow(lhs, rhs, res);
1025 return __builtin_umul_overflow(lhs, rhs, (unsigned int*)res);
10261026 }
10271027#elif defined(__GNUC__) && UINT16_MAX == ULONG_MAX
10281028 if (max == UINT16_MAX) {
1029 return __builtin_umull_overflow(lhs, rhs, res);
1029 return __builtin_umull_overflow(lhs, rhs, (unsigned long*)res);
10301030 }
10311031#elif defined(__GNUC__) && UINT16_MAX == ULLONG_MAX
10321032 if (max == UINT16_MAX) {
1033 return __builtin_umulll_overflow(lhs, rhs, res);
1033 return __builtin_umulll_overflow(lhs, rhs, (unsigned long long*)res);
10341034 }
10351035#endif
10361036 uint32_t big_result = (uint32_t)lhs * (uint32_t)rhs;
......@@ -1045,15 +1045,15 @@ static inline uint16_t zig_mulo_u16(uint16_t lhs, uint16_t rhs, uint16_t *res, u
10451045static inline uint32_t zig_mulo_u32(uint32_t lhs, uint32_t rhs, uint32_t *res, uint32_t max) {
10461046#if defined(__GNUC__) && UINT32_MAX == UINT_MAX
10471047 if (max == UINT32_MAX) {
1048 return __builtin_umul_overflow(lhs, rhs, res);
1048 return __builtin_umul_overflow(lhs, rhs, (unsigned int*)res);
10491049 }
10501050#elif defined(__GNUC__) && UINT32_MAX == ULONG_MAX
10511051 if (max == UINT32_MAX) {
1052 return __builtin_umull_overflow(lhs, rhs, res);
1052 return __builtin_umull_overflow(lhs, rhs, (unsigned long*)res);
10531053 }
10541054#elif defined(__GNUC__) && UINT32_MAX == ULLONG_MAX
10551055 if (max == UINT32_MAX) {
1056 return __builtin_umulll_overflow(lhs, rhs, res);
1056 return __builtin_umulll_overflow(lhs, rhs, (unsigned long long*)res);
10571057 }
10581058#endif
10591059 uint64_t big_result = (uint64_t)lhs * (uint64_t)rhs;
......@@ -1068,11 +1068,11 @@ static inline uint32_t zig_mulo_u32(uint32_t lhs, uint32_t rhs, uint32_t *res, u
10681068static inline uint64_t zig_mulo_u64(uint64_t lhs, uint64_t rhs, uint64_t *res, uint64_t max) {
10691069 bool overflow;
10701070#if defined(__GNUC__) && UINT64_MAX == UINT_MAX
1071 overflow = __builtin_umul_overflow(lhs, rhs, res);
1071 overflow = __builtin_umul_overflow(lhs, rhs, (unsigned int*)res);
10721072#elif defined(__GNUC__) && UINT64_MAX == ULONG_MAX
1073 overflow = __builtin_umull_overflow(lhs, rhs, res);
1073 overflow = __builtin_umull_overflow(lhs, rhs, (unsigned long*)res);
10741074#elif defined(__GNUC__) && UINT64_MAX == ULLONG_MAX
1075 overflow = __builtin_umulll_overflow(lhs, rhs, res);
1075 overflow = __builtin_umulll_overflow(lhs, rhs, (unsigned long long*)res);
10761076#else
10771077 int int_overflow;
10781078 *res = __umulodi4(lhs, rhs, &int_overflow);