From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id CC9473858C74 for ; Fri, 26 Aug 2022 05:55:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CC9473858C74 Received: by mail-pj1-x1031.google.com with SMTP id ds12-20020a17090b08cc00b001fae6343d9fso7145088pjb.0 for ; Thu, 25 Aug 2022 22:55:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc; bh=OVhaEIYbYsM5ekNXjFrfjMelrFVzjMrhZOW6hPDLIBo=; b=LxerGEJs1MMInhKk466tCPBe07OCYtQRfv6/xl+klVrYeZVFn1cZ91uFTsdFFeP+KA pMuJElPl9HR/yZrvNpAb1Vrty2wXm3PMKl/nyyqLJPsSESJ0TOx9WlCOkRtsgEHXnBf8 mBJI4TfOzCgiKiBNDkM0XkmrNv93D859R41ikPf2Nnx3dL5MoOaE0Qh48dxNjahso+0O JwN0eUKX/L9gk8T6ruby8YFcLuQxUs8C/y7LgMSniscLs03+DHfF1y27Ndu1DyDB1CNy D4qPx5I8d2cllFqrTPZWLDTV6CSA0gzxaLibaivino95J7lH8bJnlfrH488aFX/9G+d1 kojQ== X-Gm-Message-State: ACgBeo2qyIiZ2bMKQQCVO0FlDuONsGvuShTxIBIRedTMfuR74npahZRg cuecR94t+iAyGbQOKX7xpUy5iDot+5v6OzkVcwi5DhblW9FYjQ== X-Google-Smtp-Source: AA6agR52DxQxPRRVzLloXnxLMkdUZGokcHe84S6rBQSmQ+/HkjkbSfe4YRq71/5fHzjNmmHt0XoiXjyVjK3fkk1KsSQ= X-Received: by 2002:a17:90a:670c:b0:1fb:c11c:4d90 with SMTP id n12-20020a17090a670c00b001fbc11c4d90mr2646509pjj.126.1661493331889; Thu, 25 Aug 2022 22:55:31 -0700 (PDT) MIME-Version: 1.0 From: Rebecca Ribas Date: Fri, 26 Aug 2022 01:55:20 -0400 Message-ID: Subject: Confused about coroutine behavior To: gcc@gcc.gnu.org X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, 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 Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Aug 2022 05:55:35 -0000 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. 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! From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id CC9473858C74 for ; Fri, 26 Aug 2022 05:55:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CC9473858C74 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-pj1-x1031.google.com with SMTP id ds12-20020a17090b08cc00b001fae6343d9fso7145088pjb.0 for ; Thu, 25 Aug 2022 22:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc; bh=OVhaEIYbYsM5ekNXjFrfjMelrFVzjMrhZOW6hPDLIBo=; b=C6POv/eIxKTg9ZfSK7nEcbxlqxIs3AhhGmf5o0wC+0Hxkjajo/nq42SZpoRacXV2mY T+GLs7t91p2tMk0fTky0OYEoYP0HINJzH+mqsr20Cn/4X95CECds1CvYSvfT+g7M1EMm Uq2FbzAcO5x9+DF7ii3+Fp0QJPF6647iWMDp9QyZ4AtpknO4/2hOVRdlJ7ITzk4LZb4k UfMzTy/McPKuwBbpN2PW/G0Q84+t8CD3f6JF/z/cDJAIs6o0GD6ojCPSbmdI+deDV+0y jWp40P4YeX8lVV/dA3Z2ueaiRD1Dlqz7nk9fw2U59DHeTt0JnctdZ4AGoM3ZZPMyR6+4 387A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc; bh=OVhaEIYbYsM5ekNXjFrfjMelrFVzjMrhZOW6hPDLIBo=; b=LxerGEJs1MMInhKk466tCPBe07OCYtQRfv6/xl+klVrYeZVFn1cZ91uFTsdFFeP+KA pMuJElPl9HR/yZrvNpAb1Vrty2wXm3PMKl/nyyqLJPsSESJ0TOx9WlCOkRtsgEHXnBf8 mBJI4TfOzCgiKiBNDkM0XkmrNv93D859R41ikPf2Nnx3dL5MoOaE0Qh48dxNjahso+0O JwN0eUKX/L9gk8T6ruby8YFcLuQxUs8C/y7LgMSniscLs03+DHfF1y27Ndu1DyDB1CNy D4qPx5I8d2cllFqrTPZWLDTV6CSA0gzxaLibaivino95J7lH8bJnlfrH488aFX/9G+d1 kojQ== X-Gm-Message-State: ACgBeo2qyIiZ2bMKQQCVO0FlDuONsGvuShTxIBIRedTMfuR74npahZRg cuecR94t+iAyGbQOKX7xpUy5iDot+5v6OzkVcwi5DhblW9FYjQ== X-Google-Smtp-Source: AA6agR52DxQxPRRVzLloXnxLMkdUZGokcHe84S6rBQSmQ+/HkjkbSfe4YRq71/5fHzjNmmHt0XoiXjyVjK3fkk1KsSQ= X-Received: by 2002:a17:90a:670c:b0:1fb:c11c:4d90 with SMTP id n12-20020a17090a670c00b001fbc11c4d90mr2646509pjj.126.1661493331889; Thu, 25 Aug 2022 22:55:31 -0700 (PDT) MIME-Version: 1.0 From: Rebecca Ribas Date: Fri, 26 Aug 2022 01:55:20 -0400 Message-ID: Subject: Confused about coroutine behavior To: gcc@gcc.gnu.org Content-Type: multipart/alternative; boundary="000000000000d813de05e71e8fd1" X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,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: Message-ID: <20220826055520.wV5Y8fRYfQpwonH0x14eMmeFqu2i7MY8Lpdyxq4kdIw@z> --000000000000d813de05e71e8fd1 Content-Type: text/plain; charset="UTF-8" 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. 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! --000000000000d813de05e71e8fd1--