www.digitalmars.com         C & C++   DMDScript  

D.gnu - [Bug 227] New: Spurious warning: function returns address of local

http://bugzilla.gdcproject.org/show_bug.cgi?id=227

            Bug ID: 227
           Summary: Spurious warning: function returns address of local
                    variable [-Wreturn-local-addr]
           Product: GDC
           Version: development
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: Normal
         Component: gdc
          Assignee: ibuclaw gdcproject.org
          Reporter: ibuclaw gdcproject.org

When compiled with -O2 -Wall -Werror, this program causes the following error.

uni.d: In function ‘intersect’:
uni.d:10:23: error: function returns address of local variable
[-Werror=return-local-addr]
         return this = typeof(this).init.add;
                       ^
cc1d: note: declared here
---
struct InversionList
{   
    ref add()
    {
        return this;
    }

    ref intersect()
    {
        return this = typeof(this).init.add;
    }
    CowArray data;
}

struct CowArray
{
    ~this()
    {
    }
}
---


Worse still, with a slight adjustment we loose all line information!

uni.d: In function ‘intersect’:
cc1d: error: function may return address of local variable
[-Werror=return-local-addr]
cc1d: note: declared here
---
struct InversionList
{   
    ref add()
    {
        return this;
    }

    ref intersect(bool may)
    {       
        if(may)
            return this = typeof(this).init.add;
        return this;
    }
    CowArray data;
}

struct CowArray
{
    ~this()
    {
    }
}
---

It may be the codegen we produce that causes it (taking the address of a
TRY_FINALLY_EXPR)?
This is the tree-original dump (demangled):
---
;; Function add (uni.InversionList.add())
{
  return <retval> = (struct InversionList *) this;
}

;; Function intersect (uni.InversionList.intersect())
{
  struct InversionList __slInver51;

  return <retval> = &(try
    {
      SAVE_EXPR <*(SAVE_EXPR <*(SAVE_EXPR <&(__slInver51 = {.data={}};,
__slInver51)>;, add (SAVE_EXPR <&(__slInver51 = {.data={}};, __slInver51)>););,
{}>;, opAssign ((struct InversionList *) this, SAVE_EXPR <*(SAVE_EXPR
<&(__slInver51 = {.data={}};, __slInver51)>;, add (SAVE_EXPR <&(__slInver51 =
{.data={}};, __slInver51)>););, {}>);)>;
    }
  finally
    {
      __fieldDtor (&__slInver51);
    }, SAVE_EXPR <*(SAVE_EXPR <*(SAVE_EXPR <&(__slInver51 = {.data={}};,
__slInver51)>;, add (SAVE_EXPR <&(__slInver51 = {.data={}};, __slInver51)>););,
{}>;, opAssign ((struct InversionList *) this, SAVE_EXPR <*(SAVE_EXPR
<&(__slInver51 = {.data={}};, __slInver51)>;, add (SAVE_EXPR <&(__slInver51 =
{.data={}};, __slInver51)>););, {}>);)>;);
}

;; Function __fieldDtor (uni.InversionList.__fieldDtor())
{
  __dtor (&this->data);
}

;; Function opAssign (uni.InversionList.opAssign(uni.InversionList))
{
  struct InversionList __swap50;

  (void) 0;, __swap50 = *this;;, *this = p;;, __fieldDtor (&__swap50);;
  return <retval> = (struct InversionList *) this;
}

;; Function __dtor (uni.CowArray.~this())
{
  return;
}

;; Function opAssign (uni.CowArray.opAssign(uni.CowArray))
{
  struct CowArray __swap49;

  (void) 0;, __swap49 = *this;;, *this = p;;, __dtor (&__swap49);;
  return <retval> = (struct CowArray *) this;
}

-- 
You are receiving this mail because:
You are watching all bug changes.
May 24 2016