New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configure should probe for __builtin_add_overflow #16063
Comments
From @maukeCreated by @maukeI'd like to be able __builtin_add_overflow, __builtin_sub_overflow, It would be nice if Configure had checks for those (it already checks for Perl Info
|
From @maukeOn Sun, 02 Jul 2017 01:14:12 -0700, mauke- wrote:
I've attached patches to do that, but I'm not sure if this is the right way to do it (see bug #131688). The first patch extends Configure. The second patch extends config_h.SH, which contains a comment saying "THIS IS A GENERATED FILE. DO NOT HAND-EDIT. See Porting/config_h.pl", but I saw Porting/config_h.pl and it contains no useful information, so I hand-edited anyway. |
From @mauke0001-Configure-check-for-__builtin_add_overflow-and-frien.patchFrom 27f6a544755754ae61bcf02dfbff843a94c6eeb0 Mon Sep 17 00:00:00 2001
From: Lukas Mai <l.mai@web.de>
Date: Sun, 2 Jul 2017 09:35:59 +0200
Subject: [PATCH 1/2] Configure: check for __builtin_add_overflow and friends
---
Configure | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 117 insertions(+)
diff --git Configure Configure
index 3259249500..4d151d97de 100755
--- Configure
+++ Configure
@@ -398,6 +398,9 @@ d_bcmp=''
d_bcopy=''
d_builtin_choose_expr=''
d_builtin_expect=''
+d_builtin_add_overflow=''
+d_builtin_sub_overflow=''
+d_builtin_mul_overflow=''
d_bzero=''
d_c99_variadic_macros=''
d_casti32=''
@@ -11562,6 +11565,117 @@ set d_builtin_expect
eval $setvar
$rm_try
+: Look for GCC-style __builtin_add_overflow
+case "$d_builtin_add_overflow" in
+'')
+ echo " "
+ echo "Checking whether your compiler can handle __builtin_add_overflow ..." >&4
+ $cat >try.c <<'EOCP'
+int main(void) {
+ const unsigned int uint_max = ~0u;
+ int target_int = 0;
+ if (__builtin_add_overflow(1, 2, &target_int) || target_int != 3) {
+ return 1;
+ }
+ if (!__builtin_add_overflow((int)(uint_max >> 1), 1, &target_int)) {
+ return 1;
+ }
+ if (!__builtin_add_overflow(uint_max, -1, &target_int)) {
+ return 1;
+ }
+ return 0;
+}
+EOCP
+ set try
+ if eval $compile && $run ./try; then
+ echo "Your C compiler supports __builtin_add_overflow."
+ val="$define"
+ else
+ echo "Your C compiler doesn't seem to understand __builtin_add_overflow."
+ val="$undef"
+ fi
+ ;;
+*) val="$d_builtin_add_overflow" ;;
+esac
+
+set d_builtin_add_overflow
+eval $setvar
+$rm_try
+
+: Look for GCC-style __builtin_sub_overflow
+case "$d_builtin_sub_overflow" in
+'')
+ echo " "
+ echo "Checking whether your compiler can handle __builtin_sub_overflow ..." >&4
+ $cat >try.c <<'EOCP'
+int main(void) {
+ const unsigned int uint_max = ~0u;
+ int target_int = 0;
+ if (__builtin_sub_overflow(1, -2, &target_int) || target_int != 3) {
+ return 1;
+ }
+ if (!__builtin_sub_overflow(-(int)(uint_max >> 1), 2, &target_int)) {
+ return 1;
+ }
+ if (!__builtin_sub_overflow(uint_max, 1, &target_int)) {
+ return 1;
+ }
+ return 0;
+}
+EOCP
+ set try
+ if eval $compile && $run ./try; then
+ echo "Your C compiler supports __builtin_sub_overflow."
+ val="$define"
+ else
+ echo "Your C compiler doesn't seem to understand __builtin_sub_overflow."
+ val="$undef"
+ fi
+ ;;
+*) val="$d_builtin_sub_overflow" ;;
+esac
+
+set d_builtin_sub_overflow
+eval $setvar
+$rm_try
+
+: Look for GCC-style __builtin_mul_overflow
+case "$d_builtin_mul_overflow" in
+'')
+ echo " "
+ echo "Checking whether your compiler can handle __builtin_mul_overflow ..." >&4
+ $cat >try.c <<'EOCP'
+int main(void) {
+ const unsigned int uint_max = ~0u;
+ int target_int = 0;
+ if (__builtin_mul_overflow(2, 3, &target_int) || target_int != 6) {
+ return 1;
+ }
+ if (!__builtin_mul_overflow((int)(uint_max >> 1), 2, &target_int)) {
+ return 1;
+ }
+ if (!__builtin_mul_overflow(uint_max, 1, &target_int)) {
+ return 1;
+ }
+ return 0;
+}
+EOCP
+ set try
+ if eval $compile && $run ./try; then
+ echo "Your C compiler supports __builtin_mul_overflow."
+ val="$define"
+ else
+ echo "Your C compiler doesn't seem to understand __builtin_mul_overflow."
+ val="$undef"
+ fi
+ ;;
+*) val="$d_builtin_mul_overflow" ;;
+esac
+
+set d_builtin_mul_overflow
+eval $setvar
+$rm_try
+
: see if bzero exists
set bzero d_bzero
eval $inlibc
@@ -24463,6 +24577,9 @@ d_bsdgetpgrp='$d_bsdgetpgrp'
d_bsdsetpgrp='$d_bsdsetpgrp'
d_builtin_choose_expr='$d_builtin_choose_expr'
d_builtin_expect='$d_builtin_expect'
+d_builtin_add_overflow='$d_builtin_add_overflow'
+d_builtin_sub_overflow='$d_builtin_sub_overflow'
+d_builtin_mul_overflow='$d_builtin_mul_overflow'
d_bzero='$d_bzero'
d_c99_variadic_macros='$d_c99_variadic_macros'
d_casti32='$d_casti32'
--
2.13.2
|
From @mauke0002-provide-guard-macros-for-__builtin_add_overflow-and-.patchFrom 0c07092cb3bd0b47e475f702566aaab2ffbd257b Mon Sep 17 00:00:00 2001
From: Lukas Mai <l.mai@web.de>
Date: Sun, 2 Jul 2017 09:51:57 +0200
Subject: [PATCH 2/2] provide guard macros for __builtin_add_overflow and
friends
---
config_h.SH | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git config_h.SH config_h.SH
index e9b144f02b..d35163f0e0 100755
--- config_h.SH
+++ config_h.SH
@@ -2586,6 +2586,24 @@ sed <<!GROK!THIS! >$CONFIG_H -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un
#$d_builtin_expect HAS_BUILTIN_EXPECT /**/
#$d_builtin_choose_expr HAS_BUILTIN_CHOOSE_EXPR /**/
+/* HAS_BUILTIN_ADD_OVERFLOW:
+ * This symbol, if defined, indicates that the compiler supports
+ * __builtin_add_overflow for adding integers with overflow checks.
+ */
+#$d_builtin_add_overflow HAS_BUILTIN_ADD_OVERFLOW /**/
+
+/* HAS_BUILTIN_SUB_OVERFLOW:
+ * This symbol, if defined, indicates that the compiler supports
+ * __builtin_sub_overflow for subtracting integers with overflow checks.
+ */
+#$d_builtin_sub_overflow HAS_BUILTIN_SUB_OVERFLOW /**/
+
+/* HAS_BUILTIN_MUL_OVERFLOW:
+ * This symbol, if defined, indicates that the compiler supports
+ * __builtin_mul_overflow for multiplying integers with overflow checks.
+ */
+#$d_builtin_mul_overflow HAS_BUILTIN_MUL_OVERFLOW /**/
+
/* HAS_C99_VARIADIC_MACROS:
* If defined, the compiler supports C99 variadic macros.
*/
--
2.13.2
|
From @jkeenanOn Sun, 02 Jul 2017 08:19:31 GMT, mauke- wrote:
Now that metaconfig has its repository on github.com, should this RT be re-formulated as an issue at that location? https://github.com/perl5-metaconfig/metaconfig/issues?q=is%3Aopen+is%3Aissue Thank you very much. -- |
The RT System itself - Status changed from 'new' to 'open' |
From @TuxOn Sat, 28 Oct 2017 13:46:58 -0700, "James E Keenan via RT"
As these have already been merged into Configure, this ticket should
-- |
@jkeenan - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#131689 (status was 'resolved')
Searchable as RT131689$
The text was updated successfully, but these errors were encountered: