public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "slyfox at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/107661] [13 Regression] lambdas get merged incorrectly in tempaltes, cause llvm-12 miscompilation since r13-3358-ge0403e95689af7
Date: Fri, 18 Nov 2022 08:42:41 +0000	[thread overview]
Message-ID: <bug-107661-4-oGwPqiWQ5h@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107661-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #8 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
(In reply to Sergei Trofimovich from comment #7)
> When debug reports unqualified `Aggregate replacements: 1[0]=callback_fn`
> does it mean ipa-cp does not distinguish between:
>   * static void function_ref::callback_fn(void*) [with Callable =
> seemingly_unused_foo(int)::L]/30.
>   * static void function_ref::callback_fn(void*) [with Callable = void()]/29.
> ?
> 
> I suspect it does not and that results in a wrong callback_fn inline.

That was not it. Identical names is a printing artifact.

I shrunk example a bit more to avoid any overloads and crashes. Now example
just prints different things.

// How to break:
// $ ./gcc-13-snap/bin/gcc -O1 -fipa-cp -fipa-cp-clone                 a.cc -o
a && ./a
// GOOD
// BAD
// $ ./gcc-13-snap/bin/gcc -O1 -fipa-cp -fipa-cp-clone -DDISABLE_HACK a.cc -o a
&& ./a
// GOOD
// GOOD

// #define DISABLE_HACK 1

#include <stdio.h>

struct R {} RGood;
struct L {} LBad;

static void L_run(void) { fprintf(stderr, "BAD\n"); }
static void callback_fn_L(void) { L_run(); }
static void callback_fn_R(void) { fprintf(stderr, "GOOD\n"); }

struct function_ref {
  void (*callback)(void) = nullptr;

  function_ref(L * pl) { callback = callback_fn_L; }
  function_ref(R * pr) { callback = callback_fn_R; }
};

// allow one level of recursion to call callback twice
static int is_recur(void) {
    static int n = 0;
    switch (n++) {
      case 0: return 1;
      default: return 0;
    }
}

static void do3(volatile int * punused, function_ref Expired) {
  Expired.callback();

  if (is_recur())
      do3(punused, Expired);
}

static void do1(function_ref Expired) {
  volatile int unused = 42;

  do3(&unused, Expired);
}

int main(void) { do1(&RGood); }

#if defined(DISABLE_HACK)
#else
void seemingly_unused_foo(void) { do1(&LBad); }
#endif

  parent reply	other threads:[~2022-11-18  8:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-12 18:06 [Bug middle-end/107661] New: [13 Regression] lambdas get merged incorrectly in tempaltes, cause llvm-12 miscompilation slyfox at gcc dot gnu.org
2022-11-12 18:13 ` [Bug middle-end/107661] " pinskia at gcc dot gnu.org
2022-11-12 18:21 ` slyfox at gcc dot gnu.org
2022-11-12 20:16 ` slyfox at gcc dot gnu.org
2022-11-12 22:47 ` slyfox at gcc dot gnu.org
2022-11-13 14:23 ` [Bug middle-end/107661] [13 Regression] lambdas get merged incorrectly in tempaltes, cause llvm-12 miscompilation since r13-3358-ge0403e95689af7 slyfox at gcc dot gnu.org
2022-11-13 14:57 ` jamborm at gcc dot gnu.org
2022-11-14 13:55 ` rguenth at gcc dot gnu.org
2022-11-15 23:21 ` slyfox at gcc dot gnu.org
2022-11-18  8:42 ` slyfox at gcc dot gnu.org [this message]
2022-11-18  8:43 ` slyfox at gcc dot gnu.org
2022-11-18  8:54 ` slyfox at gcc dot gnu.org
2022-11-19 20:11 ` slyfox at gcc dot gnu.org
2022-11-19 20:29 ` slyfox at gcc dot gnu.org
2022-11-20 21:26 ` slyfox at gcc dot gnu.org
2022-11-21 22:52 ` jamborm at gcc dot gnu.org
2022-11-22 14:13 ` [Bug ipa/107661] " jamborm at gcc dot gnu.org
2022-11-22 17:30 ` cvs-commit at gcc dot gnu.org
2022-11-22 17:33 ` jamborm at gcc dot gnu.org
2022-11-24 22:46 ` slyfox at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-107661-4-oGwPqiWQ5h@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).