This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix undefined behavior breaking clang-compiled as


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.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]