]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
stmt: Handle %cc[name] in resolve_asm_operand_names [PR122133]
authorJakub Jelinek <jakub@redhat.com>
Mon, 6 Oct 2025 07:46:48 +0000 (09:46 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 6 Oct 2025 07:46:48 +0000 (09:46 +0200)
Last year I've extended the asm template syntax in inline asm to support
%cc0 etc., apparently the first 2 letter generic operand modifier.
As the following testcase shows, I forgot to tweak the [foo] handling
for it though.  As final.cc will error on any % ISALPHA not followed by
digit (with the exception of % c c digit), I think we can safely handle
this for any 2 letters in between % and [, instead of hardcoding it for
now only for %cc[ and changing it again next time we add something
two-letter.

2025-10-06  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/122133
* stmt.cc (resolve_asm_operand_names): Handle % and 2 letters followed
by open square.

* c-c++-common/toplevel-asm-9.c: New test.

gcc/stmt.cc
gcc/testsuite/c-c++-common/toplevel-asm-9.c [new file with mode: 0644]

index 7942aa3e4848b03b2e9a42e3e5131679675f930f..f42878ae2077d0652f2f1f4b902524a9ff455e07 100644 (file)
@@ -849,7 +849,8 @@ resolve_asm_operand_names (tree string, tree outputs, tree inputs, tree labels)
     {
       if (c[1] == '[')
        break;
-      else if (ISALPHA (c[1]) && c[2] == '[')
+      else if (ISALPHA (c[1])
+              && (c[2] == '[' || (ISALPHA (c[2]) && c[3] == '[')))
        break;
       else
        {
@@ -873,6 +874,8 @@ resolve_asm_operand_names (tree string, tree outputs, tree inputs, tree labels)
            p += 1;
          else if (ISALPHA (p[1]) && p[2] == '[')
            p += 2;
+         else if (ISALPHA (p[1]) && ISALPHA (p[2]) && p[3] == '[')
+           p += 3;
          else
            {
              p += 1 + (p[1] == '%');
diff --git a/gcc/testsuite/c-c++-common/toplevel-asm-9.c b/gcc/testsuite/c-c++-common/toplevel-asm-9.c
new file mode 100644 (file)
index 0000000..a321878
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR middle-end/122133 */
+/* { dg-do compile } */
+/* { dg-options "-O0" } */
+
+extern int v[42], w;
+int x[42], y;
+void foo (void);
+void bar (void) {}
+
+asm ("# %cc[foo]: %cc[v]: %cc[w]: %cc[bar] %cc[x] %cc[y]"
+     :: [foo] ":" (foo), [v] ":" (v), [w] ":" (&w),
+       [bar] "-i" (bar), [x] "-s" (x), [y] "-s" (&y));