https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119699

            Bug ID: 119699
           Summary: fnspec for constructors/deconstructors don't say they
                    return this when targetm.cxx.cdtor_returns_this ()
                    returns true
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---
            Target: arm-*-*eabi

>From PR 101995:
```
class x
{
public:
  x ();
  int func ();
private:
  int a;
};

int g ()
{
  x b;
  return b.func();
}
```

For the above call we should get:
```
        add     r0, sp, #4
        bl      _ZN1xC1Ev
        bl      _ZN1x4funcEv
```

Since the constructor of class x, returns this (which is also the first
argument).

But currently there is an extra instruction:

        add     r0, sp, #4

fnspec is what explains this to the middle-end now:
```
/* Parse string of attribute "fn spec".  This is an internal attribute
   describing side effects of a function as follows:

   character 0  specifies properties of return values as follows:
     '1'...'4'  specifies number of argument function returns (as in memset)
```

I think the easy way of doing this is call set_call_expr_flags with decl and
ECF_RET1 but I could be wrong.

Reply via email to