The attached patch allows the case of register names used in an asm statement clobber list to be disregarded when checking the validity of the register names.
Currently, the register name used in asm statement clobber list must exactly match those defined in the targets REGISTER_NAMES macro. This means that, for example, for msp430-elf the following code emits an ambiguous error: > void > foo (void) > { > __asm__ ("" : : : "r4", "R6"); > } > asm-register-names.c:8:3: error: unknown register name 'r4' in 'asm' All the register names defined in the msp430 REGISTER_NAMES macro use an upper case 'R', so use of lower case 'r' gets rejected. I guess this could also be fixed by defining all the registers in ADDITIONAL_REGISTER_NAMES using a lower case r, but I prefer this generic solution and I cannot think of any negative side effects to what is proposed. Using the wrong case of a register name does not make its use ambiguous, and allows users to stylize the clobber list with upper/lower case register names as they wish. Successfully bootstrapped and regtested for x86_64-pc-linux-gnu, and regtested for msp430-elf. Ok for trunk?
>From 6275eb1c915b574f415c4adaf241d2d200c42cce Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz <joze...@mittosystems.com> Date: Thu, 4 Jul 2019 11:25:04 +0100 Subject: [PATCH] Perform case-insensitive comparison when decoding register names gcc/ChangeLog: 2019-07-04 Jozef Lawrynowicz <joze...@mittosystems.com> PR target/70320 * varasm.c (decode_reg_name_and_count): Use strcasecmp when comparing register names with asmspec. gcc/testsuite/ChangeLog: 2019-07-04 Jozef Lawrynowicz <joze...@mittosystems.com> PR target/70320 * gcc.target/msp430/asm-register-names.c: New test. --- .../gcc.target/msp430/asm-register-names.c | 13 +++++++++++++ gcc/varasm.c | 10 +++++----- 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/msp430/asm-register-names.c diff --git a/gcc/testsuite/gcc.target/msp430/asm-register-names.c b/gcc/testsuite/gcc.target/msp430/asm-register-names.c new file mode 100644 index 00000000000..5c31c23d9db --- /dev/null +++ b/gcc/testsuite/gcc.target/msp430/asm-register-names.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-final { scan-assembler "PUSH.*R4" } } */ +/* { dg-final { scan-assembler "PUSH.*R6" } } */ + +/* PR target/70320 + Check that both lower and upper case "r" is accepted in asm statement + clobber list. */ + +void +foo (void) +{ + __asm__ ("" : : : "r4", "R6"); +} diff --git a/gcc/varasm.c b/gcc/varasm.c index 626a4c9f9a0..892f678e9e9 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -947,7 +947,7 @@ decode_reg_name_and_count (const char *asmspec, int *pnregs) for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) if (reg_names[i][0] - && ! strcmp (asmspec, strip_reg_name (reg_names[i]))) + && ! strcasecmp (asmspec, strip_reg_name (reg_names[i]))) return i; #ifdef OVERLAPPING_REGISTER_NAMES @@ -961,7 +961,7 @@ decode_reg_name_and_count (const char *asmspec, int *pnregs) for (i = 0; i < (int) ARRAY_SIZE (table); i++) if (table[i].name[0] - && ! strcmp (asmspec, table[i].name)) + && ! strcasecmp (asmspec, table[i].name)) { *pnregs = table[i].nregs; return table[i].number; @@ -976,16 +976,16 @@ decode_reg_name_and_count (const char *asmspec, int *pnregs) for (i = 0; i < (int) ARRAY_SIZE (table); i++) if (table[i].name[0] - && ! strcmp (asmspec, table[i].name) + && ! strcasecmp (asmspec, table[i].name) && reg_names[table[i].number][0]) return table[i].number; } #endif /* ADDITIONAL_REGISTER_NAMES */ - if (!strcmp (asmspec, "memory")) + if (!strcasecmp (asmspec, "memory")) return -4; - if (!strcmp (asmspec, "cc")) + if (!strcasecmp (asmspec, "cc")) return -3; return -2; -- 2.17.1