From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id B81003858D39 for ; Fri, 26 Aug 2022 09:12:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B81003858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x530.google.com with SMTP id b16so1339740edd.4 for ; Fri, 26 Aug 2022 02:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=MDPCp9GxvDbkP5NdEFhj540UFw+aW/jev/TsX+D23Tc=; b=Rtn/Od6wvcMbVpwSR2wVWrR03toJXeHzsXwlbAKaKuUVLAWfLURiEf5Pd26SaHqbXY mnlW8d0AJUx8jVuihg9GcsFzeYh+3yUGOaddibS2xDV/HbuZEwJ9dFHaLAhle7elp3Vs g9bPCa0By2Iplo9ZeHrNAR6Ii2S6X6cs5Lewq0nm8tcn3wsFMHwgq6gGQLrpZEOS1lxo EWloTbOaQBns0vsJ9BRvAQkda8caOz4XjysXfOlHV0D5cXEo7yI4d8Llr8mrD3zk+Ap8 BG9vXxWlG3+Oye2gM9xVHcPvClQrDYaXGK0wprPP07LeSAUOvVvW9dwO+7Ov9G5CUdyD 1GdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=MDPCp9GxvDbkP5NdEFhj540UFw+aW/jev/TsX+D23Tc=; b=FWEhrnbn3gdySw1UyU0Nsk5nki58GgjJwC7Ne03EXtXz6vHHePjMg1GJ85QoZlN5LD Ekgn30MU0DQGTcxNdqidUg3yO6OObdlTlInocYDa9OudsurhV8t1JReAqtTPdR35DHEx /HNA1Ikwv53x6Mj7lSxo7BwvmQWJVt4XAUOm+pqDf8HOKfnPfGx4ARU/O54f35l8eYzy /LYPnzRrwYN+ZWOEUBw6XYt8C6n+P4AXZHfswdgze6JHAX9R5UiSyye363rADERUMCqp jl0WmcpR8XHNWcz2B9ZNDQIEQwfm08MKwKSb6s+jLvxEmrA93kmAJ0PipjHPscFlnfxO tz3Q== X-Gm-Message-State: ACgBeo0f17fgoxXAh9afrk3YYa64ejtZuN0ejYMEtg2Pm0VnYezzdVTf 3omFK2J+OJ6J5yJmmu27XHNx2/XIMjsC85oGKTmI9jsYt9I= X-Google-Smtp-Source: AA6agR7Q4E5e2aimQouNCClHchlQqFvsNsQebdr8KHPQQIXBej+FY93hj0RJ5U2Sgm/V5Jv1bYAzQP7YfKKY4uwCr94= X-Received: by 2002:a05:6402:3590:b0:447:a871:c48a with SMTP id y16-20020a056402359000b00447a871c48amr5975579edc.356.1661505133613; Fri, 26 Aug 2022 02:12:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Fri, 26 Aug 2022 10:12:02 +0100 Message-ID: Subject: Re: Confused about coroutine behavior To: Rebecca Ribas Cc: "gcc@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, 26 Aug 2022 at 06:56, Rebecca Ribas via Gcc wrote: > > Hi gcc list, > > I'm learning c++ coroutines but I ran into a behavior that I can't make > sense of. > > Here is the godbolt link: https://godbolt.org/z/rdPo8ceKP > > In some cases, it appears that temporaries are incorrectly freed, the code > shows test1 and test2 that works as expected, but test3 raises a "used > after free" error from address sanitizer that doesn't make sense to me. > > I'm aware that there are some potential caveats with passing references to > a coroutine, so I'm possibly missing some subtle detail. But it looks like > it might be a gcc bug since the same doesn't happen with clang. Yes, it's probably a bug. There have been a few bugs with temporaries and coroutines, e.g. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98401 If yours is different to that one, please file a new bug in bugzilla. If you need an account, please email the address given when trying to sign up for an account and we'll create one promptly. Thanks! > > I tested a few different versions of g++ available on ubuntu and godbolt > but got the same result. > > The compilations flags I used were: -ggdb3 -Og -std=c++20 -Wall -Wextra > -Werror -D_GLIBCXX_DEBUG -fsanitize=address > > Cheers!