From patchwork Wed May 4 00:46:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 53437 Return-Path: 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 ; 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 ; 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 ; 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 From: Palmer Dabbelt 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 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])