From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 897F13858D39; Mon, 6 Mar 2023 11:16:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 897F13858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678101400; bh=dWDmQMifcUK0F0VVm8Z7K7msklnSHnzJ9dg53Qz9Q1Q=; h=From:To:Subject:Date:From; b=dUfqU+nScW8aZbHXkdC5+ZEw4GBI5IWf80bC9uHeU+WUOsJogJNkEUnrMCkFRe5ha 1dG0qwwU7GEhjGYfs5PJQqFshIeZD7nhU5SzZ8a9O+FkQoDhS1R9eZHWeV3E2TB7Zt S0sGyDghDQnAGzdJg95GVcDV6+yIPU3+Zx9aqN4Q= From: "ishikawa at yk dot rim.or.jp" To: gcc-bugs@gcc.gnu.org Subject: =?UTF-8?B?W0J1ZyBjLzEwOTA0MV0gTmV3OiBCb2d1cyBjb21waWxlIHRpbWUg?= =?UTF-8?B?Y2hlY2sgYnkgX19idWlsdGluX21lbXNldD8gZXJyb3I6IOKAmF9fYnVpbHRp?= =?UTF-8?B?bl9tZW1zZXTigJkgd3JpdGluZyA0IGJ5dGVzIGludG8gYSByZWdpb24gb2Yg?= =?UTF-8?B?c2l6ZSAwIG92ZXJmbG93cyB0aGUgZGVzdGluYXRpb24gWy1XZXJyb3I9c3Ry?= =?UTF-8?B?aW5nb3Atb3ZlcmZsb3c9XQ==?= Date: Mon, 06 Mar 2023 11:16:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ishikawa at yk dot rim.or.jp X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109041 Bug ID: 109041 Summary: Bogus compile time check by __builtin_memset? error: =E2=80=98__builtin_memset=E2=80=99 writing 4 bytes into= a region of size 0 overflows the destination [-Werror=3Dstringop-overflow=3D] Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ishikawa at yk dot rim.or.jp Target Milestone: --- I am compiling sqlite3.c included in mozilla firefox source tree with gcc -Werror and -Wall flag (with some exclusion of certain warnings). Then the compiler spewed out the following warning treated as error, which,= I think, is bogus, but not so sure. Since the code works without the compile time check, I suppose it works :-) Gcc version is 11.3. I am compiling under Debian GNU/Linux. ishikawa@ip030:/NREF-COMM-CENTRAL/mozilla$ gcc-11 --version gcc-11 (Debian 11.3.0-12) 11.3.0 Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You see, a region of size 0 looks obviously bogus. When I look at the original code that references a character pointer with negative index (-4), I am tempted to think that a bug is triggered by the negative index. The line 32113 is memset(&zSuper[-4], 0, 4); The error printed: In function =E2=80=98memset=E2=80=99, inlined from =E2=80=98pager_playback=E2=80=99 at /tmp/sqlite3-preproces= sed-2.c:32113:5: /tmp/sqlite3-preprocessed-2.c:4273:10: error: =E2=80=98__builtin_memset=E2= =80=99 writing 4 bytes into a region of size 0 overflows the destination [-Werror=3Dstringop-overflow=3D] 4273 | return __builtin___memset_chk (__dest, __ch, __len, __builtin_object_size (__dest, 0)); |=20=20=20=20=20=20=20=20=20 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~ /tmp/sqlite3-preprocessed-2.c: In function =E2=80=98pager_playback=E2=80=99: /tmp/sqlite3-preprocessed-2.c:32089:21: note: destination object =E2=80=98*pPager.pTmpSpace=E2=80=99 of size [0, 9223372036854775807] 32089 | zSuper =3D &pPager->pTmpSpace[4]; | ~~~~~~^~~~~~~~~~~ /tmp/sqlite3-preprocessed-2.c:32089:21: note: destination object =E2=80=98*pPager.pTmpSpace=E2=80=99 of size [0, 9223372036854775807] cc1: all warnings being treated as errors I am attaching the preprocessed file which needs to be stored into /tmp/sqlite3-preprocessed-2.c, and the following script was used to compile= it. (I have removed the file line number directive because it was so confusing = to=20 figure out where the error occurs. But if someone needs to track down which header files to blame, etc., I can upload the original preprocessed file.) /usr/bin/gcc-11 -o /tmp/sqlite3-preprocessed-2.o -c -fstack-protector-st= rong -ldl -fno-builtin-strlen -g -Werror=3Dsign-compare -Werror=3Dunused-result -Werror=3Dunused-variable -Werror=3Dformat -fuse-ld=3Dgold -ldl -fno-builti= n-strlen -g -Werror -Wmaybe-uninitialized -Wsign-compare -Wunused-result -Wunused-variable -Wformat -Wno-unknown-pragmas -Wno-switch -Wno-address-of-packed-member -fuse-ld=3Dgold -fPIC -ffunction-sections -fdata-sections -fno-math-errno -pthread -pipe -g -g -Og -fvar-tracking -gdwarf-4 -fvar-tracking-assignments -freorder-blocks -fno-omit-frame-point= er -funwind-tables -Wall -Wempty-body -Wignored-qualifiers -Wpointer-arith -Wsign-compare -Wtype-limits -Wunreachable-code -Wduplicated-cond -Wlogical= -op -Wno-error=3Dmaybe-uninitialized -Wno-error=3Ddeprecated-declarations -Wno-error=3Darray-bounds -Wno-error=3Dfree-nonheap-object -Wno-multistatement-macros -Wno-error=3Dclass-memaccess -Wformat -Wformat-overflow=3D2 -Werror=3Dimplicit-function-declaration -Wno-psabi -Wno-sign-compare -Wno-type-limits -fno-strict-aliasing -ffp-contract=3Doff= =20 -fdiagnostics-color /tmp/sqlite3-preprocessed-2.c Actually there is another error printed, but that is an internal integrity check which holds, and that must be taken care of by the developer somehow. I.e., this must be ignored. /tmp/sqlite3-preprocessed-2.c: In function =E2=80=98posixUnlock=E2=80=99: /tmp/sqlite3-preprocessed-2.c:22632:42: error: self-comparison always evalu= ates to true [-Werror=3Dtautological-compare] 22632 | sqlite3PendingByte+1=3D=3D(sqlite3PendingByte+= 1) | ^~ Thank you in advance for your attention.=