When running the testsute with non-default RUNTESTFLAGS,
arm_fp16_ok_nocache may insert -mfpu=vfpv4 if needed.

However, if RUNTESTFLAGS uses an incompatible -mcpu, we can end up
generating invalid code.

For instance, if RUNTESTFLAGS uses
-mthumb/-mcpu=cortex-m33/-mfloat-abi=hard/-march=unset,
we compile gcc.target/arm/aapcs/vfp19.c with
-mthumb -mcpu=cortex-m33 -mfloat-abi=hard -march=unset [...] -mfpu=vfpv4 
-mfp16-format=ieee
and this enables GCC to generate instructions such as
vmov    d17, r0, r1
which is incorrect because cortex-m33 supports only 16 D registers.

This patch avoid this by not adding -mfpu=vfpv4 to the list if the
user forced a -mcpu flag.  This is conservative, but there is no way
to reliably detect whether -mfpu=vfpv4 is compatible with the current
flags.

With the patch, vfp18.c, vfp19.c, vfp22.c and vfp23.c are now
UNSUPPORTED in this configuration, instead of failing at execution
time.

gcc/testsuite/ChangeLog:

        PR testsuite/126082
        * lib/target-supports.exp (arm_fp16_ok_nocache): Try -mfpu=vfpv4
        only if -mcpu is not overridden.
---
 gcc/testsuite/lib/target-supports.exp | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/lib/target-supports.exp 
b/gcc/testsuite/lib/target-supports.exp
index 3ce06189d2e..1f61da72aea 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -6481,14 +6481,19 @@ proc check_effective_target_arm_fp16_ok_nocache { } {
     }
     global et_arm_fp16_flags
     set et_arm_fp16_flags ""
-    foreach flags {
+    set flags_list {
        ""
        "-mfloat-abi=softfp"
        "-mfpu=auto"
        "-mfloat-abi=softfp -mfpu=auto"
-       "-mfpu=vfpv4"
-       "-mfloat-abi=softfp -mfpu=vfpv4"
-    } {
+    }
+
+    if { ![check-flags [list "" { *-*-* } { "-mcpu=*" } { "" } ]] } {
+       lappend flags_list "-mfpu=vfpv4"
+       lappend flags_list "-mfloat-abi=softfp -mfpu=vfpv4"
+    }
+    
+    foreach flags $flags_list {
        if { [check_no_compiler_messages_nocache arm_fp16_ok assembly {
            #ifndef __ARM_FP
            #error __ARM_FP not defined
-- 
2.43.0

Reply via email to