[arm] Fix assembler option rewrite alphabetical comparison

Message ID 5A3BC93F.1020601@foss.arm.com
State New
Headers show
Series
  • [arm] Fix assembler option rewrite alphabetical comparison
Related show

Commit Message

Kyrill Tkachov Dec. 21, 2017, 2:46 p.m.
Hi all,

While doing some experimentation with options
in arm-cpus.in I hit an assembler error where
the alphabetical sorting in arm_rewrite_selected_arch
  would not sort the string "+simd+fp16" properly
into "+fp16+simd" like gas expects.

The way the comparator function compare_opt_names
is written it can never return false as the for-loop starts
from 0 and doesn't have an exit condition and its only
exit point is a "return true;".

I think it also hits undefined behaviour if the second string
is shorter than the first.

In any case, what we need is a strcmp to perform a normal
alphabetical comparison, which is what this patch does.

With this we canonicalise "+simd+fp16" to "+fp16+simd" as expected.

Bootstrapped and tested on arm-none-linux-gnueabihf.
Committed to trunk.

Thanks,
Kyrill

2017-12-21  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>

     * common/config/arm/arm-common.c (compare_opt_names): Add function
     comment.  Use strcmp instead of manual loop.

Patch

diff --git a/gcc/common/config/arm/arm-common.c b/gcc/common/config/arm/arm-common.c
index d6374276a109cb8bc0dbe8640af4accc57a81496..6a1683e38aef62ff197b64776483f1b0b70b08ef 100644
--- a/gcc/common/config/arm/arm-common.c
+++ b/gcc/common/config/arm/arm-common.c
@@ -116,14 +116,14 @@  arm_rewrite_mcpu (int argc, const char **argv)
   return arm_rewrite_selected_cpu (argv[argc - 1]);
 }
 
+/* Comparator for arm_rewrite_selected_arch.  Compare the two arch extension
+   strings FIRST and SECOND and return TRUE if FIRST is less than SECOND
+   alphabetically.  */
+
 static bool
 compare_opt_names (const char *first, const char *second)
 {
-  for (int i = 0; ; i++)
-    if (first[i] == 0
-	|| first[i] < second[i])
-      return true;
-  return false;
+  return strcmp (first, second) <= 0;
 }
 
 /* Rewrite the architecture string for passing to the assembler.