Bug 98096 - Inconsistent operand numbering for asm goto with in-out operands
Summary: Inconsistent operand numbering for asm goto with in-out operands
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: inline-asm (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: 11.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, documentation, inline-asm
: 103640 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-12-02 13:43 UTC by jwjagersma
Modified: 2022-10-17 00:53 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jwjagersma 2020-12-02 13:43:38 UTC
For the following code:

    asm goto ("# %0 %1 %2" : "+r" (i) ::: jmp);

Two registers are printed before the label name, because the in-out operand is
split internally.  This is somewhat surprising from a user perspective.

But then:

    asm goto ("# %l[jmp]" : "+r" (i) ::: jmp);

Produces an error: '%l' operand isn't a label.

So label operands are numbered after the in-out operand is split, but %l is
evaluated without this split taken into account.  Docs suggest it should be
possible to use asm goto with both in-outs and %l operands simultaneously.
Comment 1 Andrew Pinski 2020-12-02 23:37:26 UTC
This only matters now because output for assembly goto was only added for GCC 11.
Which was introduced with:
https://gcc.gnu.org/pipermail/gcc-patches/2020-November/558870.html
Comment 2 GCC Commits 2021-02-16 15:30:44 UTC
The master branch has been updated by Vladimir Makarov <vmakarov@gcc.gnu.org>:

https://gcc.gnu.org/g:72d78655a91bb2f89ac4432cfd6374380d6f9987

commit r11-7256-g72d78655a91bb2f89ac4432cfd6374380d6f9987
Author: Vladimir N. Makarov <vmakarov@redhat.com>
Date:   Tue Feb 16 10:27:56 2021 -0500

    [PR98096] inline-asm: Take inout operands into account for access to labels by names.
    
    GCC splits inout operands into output and new matched input operands
    during gimplfication.  Addressing operands by name or number is not
    problem as the new input operands are added at the end of existing
    input operands.  However it became a problem for labels in asm goto
    with output reloads.  Addressing labels should take into account the
    new input operands.  The patch solves the problem.
    
    gcc/ChangeLog:
    
            PR inline-asm/98096
            * stmt.c (resolve_operand_name_1): Take inout operands into account
            for access to labels by names.
            * doc/extend.texi: Describe counting operands for accessing labels.
    
    gcc/testsuite/ChangeLog:
    
            PR inline-asm/98096
            * gcc.c-torture/compile/pr98096.c: New.
Comment 3 Andrew Pinski 2021-09-14 07:48:36 UTC
Fixed.
Comment 4 Andrew Pinski 2021-12-10 01:46:56 UTC
*** Bug 103640 has been marked as a duplicate of this bug. ***
Comment 5 Nick Desaulniers 2021-12-10 23:33:35 UTC
While the changes to gcc/stmt.c and the second asm goto statement in gcc/testsuite/gcc.c-torture/compile/pr98096.c in https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=72d78655a91bb2f89ac4432cfd6374380d6f9987 LGTM (they fix an actual bug with symbolic references), the changes to gcc/doc/extend.texi and the first asm goto statement in gcc/testsuite/gcc.c-torture/compile/pr98096.c seemed to have conflated the label bug with documenting curious behavior.

Was it ever consider that the behavior should be changed, rather than documented?
Comment 6 Andrew Pinski 2021-12-11 00:13:27 UTC
(In reply to Nick Desaulniers from comment #5)
> Was it ever consider that the behavior should be changed, rather than
> documented?

Seems like changing an already documented and released feature seems wrong. Gcc 11 was released back in April. Clang never documented this feature as far as I can tell. Plus it would be very inconsistent with the way the inout feature was handled without asm goto. That is all input constraints are grouped together, having the asm goto label in between the inputs seems wrong.
Comment 7 James Y Knight 2022-01-05 17:50:10 UTC
Previously, you never needed to care about the numbering of the extra hidden input constraints generated for an in-out constraints, because they were _last_. Their existence previously only mattered in that you needed to count them as part of the "max 30" constraint limit.

That's why it is sensible to _keep_ these internal constraints last -- after ALL user-specified constraints, including asm-goto labels. Putting in the middle, and forcing users to count them just adds extra unnecessary complexity to the user-facing API.

It appears to me that the GCC decision here was accidental, and that when pointed out, the bug was simply documented rather than fixed. That's unfortunate.
Comment 8 Jakub Jelinek 2022-01-05 17:54:24 UTC
That isn't easibly possible, the labels are really significantly different from the implementation POV, so having them intermixed with inputs is hard.
If you don't want to count on those extra inputs, name the labels...