From patchwork Wed May 4 00:29:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 53436 X-Patchwork-Delegate: dmalcolm@redhat.com 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 6EE0A3858427 for ; Wed, 4 May 2022 00:30:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id DE51D3858D3C for ; Wed, 4 May 2022 00:30:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DE51D3858D3C 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-pl1-x630.google.com with SMTP id k1so45511pll.4 for ; Tue, 03 May 2022 17:30:00 -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=Tv+laX7kHVn0VqbLMNaMv8vB3xU6HbYIUIv3pAxlOSc=; b=gMzCGKOj3k+e7bFFaUzffNTXIaXLfKltrYVih3+HqcO/P9InhTca9/B0PyBMtGY7En yXQmOAkS/v/R1T1LHVDjFnnr1IuUxnwSP3djknMAmAuIJ2C8z6T0vdETnVI4xxLGnPx9 fR6V6zLvspQq60luyCG1uX6Mee6JamYbjcXWddW9p9VRxJZL/AS/jfaKOvyu+gTs8e/r /CYONj+bQAp+wJMO5FbNnSdRZN5Lv6kIOkndScTt0c1CD9HyjDLhHiSiImKt2rg199cr lb1/qDT9IiX1+Rzv1opqqdbFn8JqoxFzl+20a4HVrwiZONL1sMhfHtKQKSUA1TbYnaZJ iM+g== 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=Tv+laX7kHVn0VqbLMNaMv8vB3xU6HbYIUIv3pAxlOSc=; b=rwWYeETf9eai5GPnnbAcxBJpPnXNSDLyIXpNENB+fRKnMvQ5xCk8P+cobmq709PwKe cGFoQQVe/5cA5/SJGcItCFysjC3uK84pytue0+/sehErGQJj+LB4DMXzt60EGDGb5HUB YeOcFOFtt9x2uh80stFKd76W0aEC8uLgQjyD9efgIcvZU52wP9XIIva7uy7UlgXtxpeo g8osQ9jzrtM9GL5Kxw8F9riEzVPN+ic1gjkoVLQXcmbvBq/KvXt1Yj+0EFZBX71UUHCL RjqOJKxBIlTcrd8UiaiW525Qfydi2MM8cCTo/d5agyMUA/9aJvBqpZEojcSrxdnt1vm+ F36A== X-Gm-Message-State: AOAM530Pd/tkmn1HlLoCSsP/TjdASWlGnmYFgdDjgfNMRntF3gxg6ek1 UEEb0/3cGACZ2h/aPmf1tUDfG/gABHjdNQ== X-Google-Smtp-Source: ABdhPJwg242iYuyTsXyxTOm5DIzgfcvqzW4N0OB5fx9+QaGtFyAAL/GokCSTeSXbu0BvcKIY87vCUg== X-Received: by 2002:a17:903:2312:b0:15e:a6c8:a313 with SMTP id d18-20020a170903231200b0015ea6c8a313mr11662804plh.122.1651624199913; Tue, 03 May 2022 17:29:59 -0700 (PDT) Received: from localhost ([12.3.194.138]) by smtp.gmail.com with ESMTPSA id e18-20020aa78c52000000b0050dc7628156sm6851123pfd.48.2022.05.03.17.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 17:29:59 -0700 (PDT) Subject: [PATCH] analyzer/pr104308.c: Avoid optimizing away the copies Date: Tue, 3 May 2022 17:29:39 -0700 Message-Id: <20220504002938.3011-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, 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" The test cases in analyzer/pr104308.c use uninitialized values in a way that doesn't plumb through to the return value of the function. This allows the accesses to be deleted, which can result in the diagnostic not firing. gcc/testsuite/ChangeLog * gcc.dg/analyzer/pr104308.c (test_memmove_within_uninit): Return the result of the copy. (test_memcpy_From_uninit): Likewise. --- I was worried this had something to do with this test failing on RISC-V. I don't think that's actually the case (IIUC we're just not inlining the memmove, which elides the diagnostic), but I'd already written it so I figured I'd send it along. --- gcc/testsuite/gcc.dg/analyzer/pr104308.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/analyzer/pr104308.c b/gcc/testsuite/gcc.dg/analyzer/pr104308.c index a3a0cbb7317..ae40e59c41c 100644 --- a/gcc/testsuite/gcc.dg/analyzer/pr104308.c +++ b/gcc/testsuite/gcc.dg/analyzer/pr104308.c @@ -8,12 +8,13 @@ int test_memmove_within_uninit (void) { char s[5]; /* { dg-message "region created on stack here" } */ memmove(s, s + 1, 2); /* { dg-warning "use of uninitialized value" } */ - return 0; + return s[0]; } int test_memcpy_from_uninit (void) { char a1[5]; char a2[5]; /* { dg-message "region created on stack here" } */ - return (memcpy(a1, a2, 5) == a1); /* { dg-warning "use of uninitialized value" } */ + memcpy(a1, a2, 5); /* { dg-warning "use of uninitialized value" } */ + return a1[0]; }