Message ID | 20220504004650.5199-1-palmer@rivosinc.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B55D2385742F for <patchwork@sourceware.org>; Wed, 4 May 2022 00:47:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by sourceware.org (Postfix) with ESMTPS id 1C12D3858C52 for <gcc-patches@gcc.gnu.org>; Wed, 4 May 2022 00:47:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1C12D3858C52 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pj1-x1033.google.com with SMTP id cq17-20020a17090af99100b001dc0386cd8fso3389265pjb.5 for <gcc-patches@gcc.gnu.org>; Tue, 03 May 2022 17:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=subject:date:message-id:mime-version:content-transfer-encoding:cc :from:to; bh=1KgJuH8dZ/LQw/jFbY7ELMq+hOw3vNCMn8UZQGJd69c=; b=ewaJL/ViZ3nEKEihl0SuTRfC1oTEF2+h3vCcySktpaYMr7Duzw5Wzyjjf9xZFaq/8E xnpc4gGqRYxajEOTy1qhztT0TxtKVD3dgOdaWW4o+crtPok85GT5e3cBFNDxQqHp79Hg NTFKZUct53L7JobZ3C5OmeAewybyhLgD3B2cw5XQjfqt55BmV0d58t1WNUzwILCV/KnV r3Q/NKcmC9yGn+sFIJEwgJqqD4s12BSTjUzSb/5njUe60xfVGPD4NWQPhuHHCoDM8Ka8 Kod0BGcM1vgrbqSFfh5OXCgm/NgdzrHYOsLQWV9h8+/Lna31HAvyRR0GFyeGVzgDp9Nw G0Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:date:message-id:mime-version :content-transfer-encoding:cc:from:to; bh=1KgJuH8dZ/LQw/jFbY7ELMq+hOw3vNCMn8UZQGJd69c=; b=gkr0oiluD2KsrOfsI1vfZ8PwuXuFvmAgUiB4LleS9yG5UPC/5hRrRZwdJno/vZ6Zl9 W0/OB8edOVRMo/5Nm/bxSbpl4Q7GA/WfdxusLi8pFXkDm7NKWncXXdheMrMDMRGJdV3U 63X98RkoZxYYOaisM3Zyky3GaB2BBTlhebBUUBGol7QrS+j9ajDMRQgr3IR2nhUSvrWF 7Q3XtOWQ3JBXf1lKEAg0Hp0Iu+VXzEYSG0U1CYaqDM27neIRyMPTIxEhfOK4aASOrTTs DTlC5njQUO5gnWzgdujC6JLphk4nghFdwvyLAsmK2c3vVKO+HyeNKj7MQeXfclR5HQaV mAPg== X-Gm-Message-State: AOAM532urQwi9SFNtQHHMClbnoEjzDCWukvRWwBbci72dCDE3BU0aRv8 Ob50kAfsNgeTvGW8vXcLv+4uaQ== X-Google-Smtp-Source: ABdhPJxrJu7kNPeifhk+8VnXcoUAMt/gkbhtW3ddOuo7iYpuxIpdtYrigaXoankbVhDF81isL+teHA== X-Received: by 2002:a17:903:2446:b0:15e:ab0e:559 with SMTP id l6-20020a170903244600b0015eab0e0559mr10560067pls.83.1651625247017; Tue, 03 May 2022 17:47:27 -0700 (PDT) Received: from localhost ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id kp12-20020a17090ae94c00b001d81a30c437sm1930699pjb.50.2022.05.03.17.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 17:47:26 -0700 (PDT) Subject: [PATCH] tustsuite: pr102892: Avoid undefined behavior Date: Tue, 3 May 2022 17:46:50 -0700 Message-Id: <20220504004650.5199-1-palmer@rivosinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Palmer Dabbelt <palmer@rivosinc.com> To: gcc-patches@gcc.gnu.org X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
tustsuite: pr102892: Avoid undefined behavior
|
|
Commit Message
Palmer Dabbelt
May 4, 2022, 12:46 a.m. UTC
This test was relying on undefined behavior, with -Wundef I get gcc/testsuite/gcc.dg/pr102892-1.c: In function 'main': cc/testsuite/gcc.dg/pr102892-1.c:14:18: warning: 'a' is used uninitialized [-Wuninitialized] 14 | for (long a; a < 1; ++a) | ~~^~~ gcc/testsuite/gcc.dg/pr102892-1.c:14:13: note: 'a' was declared here 14 | for (long a; a < 1; ++a) | ^ gcc/testsuite/ChangeLog: * gcc.dg/pr102892-1.c (main): Avoid undefined behavior. --- The discussion on bug 102892 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102892> suggests this may always have been a result of undefined behavior, but with these simple changes the test passes for me. No idea why we're hitting this in RISC-V (and SPARC) and not elsewhere, and I also haven't gone back and checked the original fix to see if it was always just UB causing the issue. Happy to look at this further, but one suggestion on bugzilla was to just drop the test as invalid so I didn't want to chase something that didn't matter. --- gcc/testsuite/gcc.dg/pr102892-1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Wed, May 4, 2022 at 2:47 AM Palmer Dabbelt <palmer@rivosinc.com> wrote: > > This test was relying on undefined behavior, with -Wundef I get > > gcc/testsuite/gcc.dg/pr102892-1.c: In function 'main': > cc/testsuite/gcc.dg/pr102892-1.c:14:18: warning: 'a' is used uninitialized [-Wuninitialized] > 14 | for (long a; a < 1; ++a) > | ~~^~~ > gcc/testsuite/gcc.dg/pr102892-1.c:14:13: note: 'a' was declared here > 14 | for (long a; a < 1; ++a) > | ^ > > gcc/testsuite/ChangeLog: Please verify if the testcase then still reproduces the missed DCE before the fix. An alternative solution might be to make a initialized from a global variable. > * gcc.dg/pr102892-1.c (main): Avoid undefined behavior. > --- > The discussion on bug 102892 > <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102892> suggests this may > always have been a result of undefined behavior, but with these simple > changes the test passes for me. No idea why we're hitting this in > RISC-V (and SPARC) and not elsewhere, and I also haven't gone back and > checked the original fix to see if it was always just UB causing the > issue. Happy to look at this further, but one suggestion on bugzilla > was to just drop the test as invalid so I didn't want to chase something > that didn't matter. > --- > gcc/testsuite/gcc.dg/pr102892-1.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gcc/testsuite/gcc.dg/pr102892-1.c b/gcc/testsuite/gcc.dg/pr102892-1.c > index a9302b536df..b13f94d2a87 100644 > --- a/gcc/testsuite/gcc.dg/pr102892-1.c > +++ b/gcc/testsuite/gcc.dg/pr102892-1.c > @@ -11,7 +11,7 @@ int > main () > { > long c = 0; > - for (long a; a < 1; ++a) > + for (long a = 0; a < 2; ++a) > for (; c <= 1; c++) { > bar(); > if (1 == b[c][0]) > -- > 2.34.1 >
On Tue, May 03, 2022 at 05:46:50PM -0700, Palmer Dabbelt wrote: > This test was relying on undefined behavior, with -Wundef I get > > gcc/testsuite/gcc.dg/pr102892-1.c: In function 'main': > cc/testsuite/gcc.dg/pr102892-1.c:14:18: warning: 'a' is used uninitialized [-Wuninitialized] > 14 | for (long a; a < 1; ++a) > | ~~^~~ > gcc/testsuite/gcc.dg/pr102892-1.c:14:13: note: 'a' was declared here > 14 | for (long a; a < 1; ++a) > | ^ > > gcc/testsuite/ChangeLog: > > * gcc.dg/pr102892-1.c (main): Avoid undefined behavior. > --- > The discussion on bug 102892 > <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102892> suggests this may > always have been a result of undefined behavior, but with these simple > changes the test passes for me. No idea why we're hitting this in > RISC-V (and SPARC) and not elsewhere, and I also haven't gone back and > checked the original fix to see if it was always just UB causing the > issue. Happy to look at this further, but one suggestion on bugzilla > was to just drop the test as invalid so I didn't want to chase something > that didn't matter. It is a dg-do link testcase, so it certainly can contain UB in it (similarly, dg-do run testcase could contain UB as long as it isn't encountered during runtime). The important question is if whatever this has been reduced from had that UB in it or if it has been introduced during the reduction (the reporter didn't answer this) and whether the testcase with the " = 0" added behaved the same (11.2.0 can optimize foo away even in that case, r12-4790-g4b3a325f07acebf4^ can't and r12-4790-g4b3a325f07acebf4 can again). I'd say if the latter is true we probably should change it even if the reporter doesn't respond. > gcc/testsuite/gcc.dg/pr102892-1.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gcc/testsuite/gcc.dg/pr102892-1.c b/gcc/testsuite/gcc.dg/pr102892-1.c > index a9302b536df..b13f94d2a87 100644 > --- a/gcc/testsuite/gcc.dg/pr102892-1.c > +++ b/gcc/testsuite/gcc.dg/pr102892-1.c > @@ -11,7 +11,7 @@ int > main () > { > long c = 0; > - for (long a; a < 1; ++a) > + for (long a = 0; a < 2; ++a) > for (; c <= 1; c++) { > bar(); > if (1 == b[c][0]) > -- > 2.34.1 Jakub
diff --git a/gcc/testsuite/gcc.dg/pr102892-1.c b/gcc/testsuite/gcc.dg/pr102892-1.c index a9302b536df..b13f94d2a87 100644 --- a/gcc/testsuite/gcc.dg/pr102892-1.c +++ b/gcc/testsuite/gcc.dg/pr102892-1.c @@ -11,7 +11,7 @@ int main () { long c = 0; - for (long a; a < 1; ++a) + for (long a = 0; a < 2; ++a) for (; c <= 1; c++) { bar(); if (1 == b[c][0])