[Bug c++/86943] [8/9 Regression] Wrong code when converting stateless generic lambda to function pointer

2018-11-23 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86943

--- Comment #4 from Jonathan Wakely  ---
I haven't analyzed the code to say what it should do, but EDG agrees with
Clang.

[Bug c++/86943] [8/9 Regression] Wrong code when converting stateless generic lambda to function pointer

2018-11-23 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86943

--- Comment #3 from Jakub Jelinek  ---
And, note that clang 5/6 don't call the move ctor at all and only one dtor. 
What is correct?

[Bug c++/86943] [8/9 Regression] Wrong code when converting stateless generic lambda to function pointer

2018-11-23 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86943

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org,
   ||nathan at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek  ---
extern "C" int printf (const char *fmt, ...);

struct S
{
  S () { printf ("default-construct %p\n", this); }
  S (const S ) { printf ("copy-construct %p from %p\n", this, ); }
  S (S &) noexcept { printf ("move-construct %p from %p\n", this, ); }
  ~S () { printf ("destroy %p\n", this); }
};

using F = void (*) (S);

F
foo ()
{
  return [] (auto val) { printf ("called %p\n", ); };
}

int
main ()
{
  volatile F cb = foo ();
  cb ({});
  return 0;
}

The extra indirection is because in _FUN we have:
<::operator() (0B, _EXPR >>
  (struct S &)  ) >;
return;
and CALL_FROM_THUNK_P is set on the operator() call.
cp_genericize on _FUN changes the D.2160 argument, originally with type S, is
changed to S & and the PARM_DECL turned into DECL_BY_REFERENCE one, but because
the call is CALL_FROM_THUNK_P, no adjustment of the arguments is done:
  /* Don't dereference parms in a thunk, pass the references through. */
  if ((TREE_CODE (stmt) == CALL_EXPR && CALL_FROM_THUNK_P (stmt))
  || (TREE_CODE (stmt) == AGGR_INIT_EXPR && AGGR_INIT_FROM_THUNK_P (stmt)))
{
  *walk_subtrees = 0;
  return NULL;
}
Do we want to just prevent changing the direct PARM_DECL arguments of such
calls, but still recurse into more complex arguments?  Or is it incorrect that
CALL_FROM_THUNK_P is set here?

[Bug c++/86943] [8/9 Regression] Wrong code when converting stateless generic lambda to function pointer

2018-08-21 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86943

Richard Biener  changed:

   What|Removed |Added

   Keywords||wrong-code
   Target Milestone|9.0 |8.3

[Bug c++/86943] [8/9 Regression] Wrong code when converting stateless generic lambda to function pointer

2018-08-14 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86943

Martin Liška  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2018-08-14
 CC||jason at gcc dot gnu.org,
   ||marxin at gcc dot gnu.org
  Known to work||7.3.0
   Target Milestone|--- |9.0
Summary|[8 Regression] Wrong code   |[8/9 Regression] Wrong code
   |when converting stateless   |when converting stateless
   |generic lambda to function  |generic lambda to function
   |pointer |pointer
 Ever confirmed|0   |1
  Known to fail||8.2.0, 9.0

--- Comment #1 from Martin Liška  ---
Confirmed, started with r239268.