From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BF371385842A for ; Fri, 28 Jan 2022 15:01:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BF371385842A Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-359-pr2_NqJkNZyrHuUJz4Ngcw-1; Fri, 28 Jan 2022 10:01:42 -0500 X-MC-Unique: pr2_NqJkNZyrHuUJz4Ngcw-1 Received: by mail-wm1-f69.google.com with SMTP id 7-20020a1c1907000000b003471d9bbe8dso2566798wmz.0 for ; Fri, 28 Jan 2022 07:01:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:from:subject:content-transfer-encoding; bh=53CmsD+cHNcOB4Ghk932dMRZliesxH7IToeSky9e5qY=; b=UO12N09fmU4oVe1TTYiNDqMi7BxvLPBCPx8sGwLX2VlQ2CYjhVioqi561R2NqO2C/r EFOr6dJ3E/xiMIeU8OSUkXRGy2UjDbn5lnd+WvwTKdXlmq+VvL9kG/93qzoSrjnF1gjP TjGTuWS+yGAU4zAS3xYOEEAsUdwB/mdyBT7uK4DiKj4e+eo26Ac+y96giJlsuoYXW5Dp CChBmlhzoi/+UvVjC6e1eInOFByk6dr1vwLoAlk9lJbhRyB1gkvSy/MMKgGFinvqmGGI 0A8/0SMMGXRyyccoSVbMe75AWKXosTstULC1mZ7s9/LROirHLn+cZ5r//05SHPNRsGax IQqw== X-Gm-Message-State: AOAM530ownv5CXjg4QTQN1kugI8qU1dHkYxoKetWKRMHK46C0YzZjdEs 7aGePBY7a1ZlwnbhK8UTnmgmzGtKcQl0UkzrvsZsUeY6siVGbSOjm3LXFSvMXurESX11wCafEjS cnLrIssc1ZAc94NpBpMO3QjR9RW/XFS8sb7covQfsymxltVS6TzbZm2FPbbGclPs= X-Received: by 2002:adf:dc4e:: with SMTP id m14mr7549733wrj.134.1643382099483; Fri, 28 Jan 2022 07:01:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyOPeOhc0gViVHrYDtvViUh8MXJqiJoDZrsTW2jeLk5ygHUgWm4PWEKXL/CF3/dd21Jaj+1AQ== X-Received: by 2002:adf:dc4e:: with SMTP id m14mr7549701wrj.134.1643382098989; Fri, 28 Jan 2022 07:01:38 -0800 (PST) Received: from [192.168.101.16] (i87195.upc-i.chello.nl. [62.195.87.195]) by smtp.gmail.com with ESMTPSA id l11sm1309834wry.50.2022.01.28.07.01.37 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Jan 2022 07:01:38 -0800 (PST) Message-ID: <8d42151f-7be2-4d67-5b46-a83ba55d5c1c@redhat.com> Date: Fri, 28 Jan 2022 16:01:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 To: gcc-help@gcc.gnu.org From: Dumitru Ceara Subject: Potentially false-positive -Wstringop-overflow= warning with gcc >= 11.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no 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-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: Fri, 28 Jan 2022 15:01:46 -0000 Hi everyone, I think we've hit a false positive warning report when changing some of our code and using a relatively new gcc version (11.2). I tried to simplify the reproducer as much as possible and ended up with test.c below. With gcc 10.3 I don't see this warning, while with gcc 11.1 we seem to hit it. I can open a bug for this but I was wondering if it's maybe already known/reported. Thank you! Regards, Dumitru --- $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-11.2.1-20210728/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.2.1 20210728 (Red Hat 11.2.1-1) (GCC) $ cat test.c /* Compile with: * # gcc -g -O2 -c -o test.o test.c * test.c: In function ‘foo’: * test.c:47:5: warning: ‘memcpy’ writing 6 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=] * 47 | memcpy(h2 + 1, &somedata[0], 6); * | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * # gcc -v * [...] * gcc version 11.2.1 20210728 (Red Hat 11.2.1-1) (GCC) */ #include #include static char somedata[1024]; struct pkt { void *base_; uint16_t l4_ofs; }; struct hdr1 { uint32_t h11; }; struct hdr2 { uint32_t h21; }; extern void pkt_bar(struct pkt *); void foo(void) { uint64_t stub[1024 / 8]; struct pkt p; p.base_ = &stub[0]; p.l4_ofs = UINT16_MAX; size_t size = 8; /* If I comment the next line out the warning goes away. */ pkt_bar(&p); void *data = (char *) p.base_; memset(data, 0, size); struct hdr1 *h1 = data; p.l4_ofs = (uintptr_t)(h1 + 1) - (uintptr_t)p.base_; void *l4data = p.l4_ofs != UINT16_MAX ? (char *) p.base_ + p.l4_ofs : NULL; struct hdr2 *h2 = l4data; memcpy(h2 + 1, &somedata[0], 6); h2->h21 = 0; }