This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] Fix undefined behavior breaking clang-compiled as
- From: Joerg Sonnenberger <joerg at britannica dot bec dot de>
- To: binutils at sourceware dot org
- Date: Thu, 20 Nov 2014 00:11:28 +0100
- Subject: [PATCH] Fix undefined behavior breaking clang-compiled as
- Authentication-results: sourceware.org; auth=none
Hi all,
can someone please commit one of the attached patchies. The macro
currently triggers undefined behavior for n == 0, since the right shift
by 32 is not defined. Clang does effectively remove the first iteration
based on that and as a result, "cmp r0, #99" fails to assemble.
Regards,
Joerg
Index: tc-arm.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/external/gpl3/binutils/dist/gas/config/tc-arm.c,v
retrieving revision 1.6
diff -u -p -r1.6 tc-arm.c
--- tc-arm.c 29 Sep 2013 14:03:30 -0000 1.6
+++ tc-arm.c 19 Nov 2014 22:33:03 -0000
@@ -6936,7 +6936,7 @@ parse_operands (char *str, const unsigne
/* Functions for operand encoding. ARM, then Thumb. */
-#define rotate_left(v, n) (v << n | v >> (32 - n))
+#define rotate_left(v, n) (v << (n % 32) | v >> ((32 - n) % 32))
/* If VAL can be encoded in the immediate field of an ARM instruction,
return the encoded form. Otherwise, return FAIL. */
Index: tc-arm.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/external/gpl3/binutils/dist/gas/config/tc-arm.c,v
retrieving revision 1.6
diff -u -p -r1.6 tc-arm.c
--- tc-arm.c 29 Sep 2013 14:03:30 -0000 1.6
+++ tc-arm.c 19 Nov 2014 23:09:33 -0000
@@ -6936,7 +6936,7 @@ parse_operands (char *str, const unsigne
/* Functions for operand encoding. ARM, then Thumb. */
-#define rotate_left(v, n) (v << n | v >> (32 - n))
+#define rotate_left(v, n) (n == 0 ? v : (v << n | v >> (32 - n)))
/* If VAL can be encoded in the immediate field of an ARM instruction,
return the encoded form. Otherwise, return FAIL. */