From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by sourceware.org (Postfix) with ESMTPS id C9B773858034 for ; Sun, 7 Mar 2021 15:31:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C9B773858034 Received: by mail-lj1-x236.google.com with SMTP id q14so11764488ljp.4 for ; Sun, 07 Mar 2021 07:31:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pEMKlAQuiNuwn+8fhINdoeHOn7VYM5F4J6qsIUvYEbA=; b=mfQL5QcsifVGMYazXlBZ18daF+J9F0e9uFE28JRTH43CoQmeuayu0/UAF6XzTqCto0 yjXM4iTcRTqDRwBZDl9mdgq2Zxg4DEsAoQQHanbpQRUPEqLDRYYHPS1pjE58rRpDTvnE Qg66LC5R+i/nJf6gIVwk7+HLYrRgws2DJ0FV0otN0WPc1qEchMNnXdgzwCAoQSV1VZkJ yA8LRGo6cA9etYO2np4FISBLrUOd7DkQB7sRTDOYUwJCyxMvKmjBRE0Yreyyzvdwxn8K MPBYvsyxGT74c4VJWmm3mWc3tn6xIQbT1Oi5p3cY30WboUeZXag3kDHZOskiJuLTUxGr Reug== X-Gm-Message-State: AOAM530hZt6il66bbOGUf05keMi1NfZG6CVqaBbZ9Pjb0DKgMMCrByYZ HMPR1NfhjLhvHkl1TOmXSaJM3ZCDaRCR8Jv8t6G/uQ== X-Google-Smtp-Source: ABdhPJyDSAeJGoht3dDXqpzKposHlEY6aBiuu3GLORSwiDsf715ddVjZqoQF0sDeE6MqA6k2Tsrn8vM4hT4qB7w76r0= X-Received: by 2002:a2e:544d:: with SMTP id y13mr11001268ljd.95.1615131079172; Sun, 07 Mar 2021 07:31:19 -0800 (PST) MIME-Version: 1.0 References: <73a14b39-fca0-0b2a-d31c-942658e8940a@redhat.com> <20210307140458.GA6897@platinum.motzkau> In-Reply-To: <20210307140458.GA6897@platinum.motzkau> From: Ian Lance Taylor Date: Sun, 7 Mar 2021 07:31:04 -0800 Message-ID: Subject: Re: Question about -Wstrict-overflow=2 To: Alexander Motzkau Cc: gcc-help X-Spam-Status: No, score=-17.7 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, HTML_MESSAGE, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Mar 2021 15:31:22 -0000 On Sun, Mar 7, 2021, 6:05 AM Alexander Motzkau via Gcc-help < gcc-help@gcc.gnu.org> wrote: > Andrew Haley wrote: > > -Wstrict-overflow=2 triggers when GCC encounters expressions that > > reduce to a constant, where that evaluation depends on overflow not > > occuring. In this case the expression is > > > > expbuf + 120 > get_buf() > > If this is the case I can see the merit of the warning, because that can be > reduced to 120 > 0, which is a constant. But my problem ist, that I don't > see where this expression comes from? The condition in question is > > argptr >= endbuf > > which can be written as > > expbuf + i >= expbuf + 120 > > which can be reduced to > > i >= 120 > > which is not a constant, and therefore not a cause for this warning. > As you said earlier, GCC turns the loop into one with exactly 120 iterations. That optimization assumes that expbuf + 120 does not overflow; if it did overflow the loop would not execute exactly 120 times. That is why you are getting the warning. It's not an error; it's GCC informing you that it is making as optimization decision based on the assumption that overflow does not occur. Ian >