From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 67B453858C62; Wed, 3 Jan 2024 11:46:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67B453858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704282377; bh=I/AYZLd09OEUctY+G294Mmb3QwO71jLFfEA8ykhfFGw=; h=From:To:Subject:Date:From; b=bVPTvfS/FLJQih4D5ZfUr9gegTTLuUx4nvDkW4cyFRVEI1ldYEG6EYPc9CMkVV/Oh 4xifdGPdAxA4eh2EZfTNKnkXsA6PtaAf72WyvrPsmQt20wr3zZ5D7LX6lQ8UVt9ZIF 2fhyg/75LLl9/iKJFzL+EWPMNVK0ULsFMJ92IF9U= From: "arnd at linaro dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/113214] New: false-positive -Wstringop-overflow warning with thread sanitizer Date: Wed, 03 Jan 2024 11:46:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: arnd at linaro dot org 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 cc 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=3D113214 Bug ID: 113214 Summary: false-positive -Wstringop-overflow warning with thread sanitizer Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: arnd at linaro dot org CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxi= n at gcc dot gnu.org Target Milestone: --- I came across another -Wstringop-overflow warning while building the kernel= in a newly added device driver, when the thread sanitizer is enabled. Reduced = my test case to void _dev_warn(const void *dev, ...); struct xe_uc { int guc; }; struct xe_gt {=20 struct xe_tile *tile; struct pf_queue { unsigned int data[128]; unsigned int tail; } pf_queue[4]; struct xe_uc uc; }; #define container_of(ptr, type, member) ({ \ void *__mptr =3D (void *)(ptr); \ ((type *)(__mptr - __builtin_offsetof(type, member))); }) void xe_guc_pagefault_handler(struct xe_uc *uc, int asid, void *msg, int le= n) { struct xe_gt *gt =3D container_of(uc, struct xe_gt, uc); void *xe =3D gt->tile; struct pf_queue *pf_queue; if (len !=3D 4) return; pf_queue =3D >->pf_queue[asid % 4]; __builtin_memcpy(pf_queue->data + pf_queue->tail, msg, len * sizeof(unsigned int)); _dev_warn(xe); } Original source code at https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/dr= ivers/gpu/drm/xe/xe_gt_pagefault.c?h=3Dnext-20240103#n322 Reproducer at https://godbolt.org/z/MMaz8rqcj aarch64-linux-gcc-13.2 -Wall -O2 -fsanitize=3Dthread -Werror=3Dstringop-ove= rflow -Wall -c xe_gt_pagefault.c=20 xe_gt_pagefault.c: In function 'xe_guc_pagefault_handler': xe_gt_pagefault.c:26:9: error: writing 16 bytes into a region of size 0 [-Werror=3Dstringop-overflow=3D] 26 | __builtin_memcpy(pf_queue->data + pf_queue->tail, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 27 | msg, len * sizeof(unsigned int)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ xe_gt_pagefault.c:6:25: note: at offset 8 into destination object 'tile' of size 8 6 | struct xe_tile *tile; | ^~~~ cc1: some warnings being treated as errors Currently I see this with gcc-13.x and gcc-14.0 but not gcc-12.=