From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 25C1D3858D3C; Thu, 10 Nov 2022 17:45:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 25C1D3858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668102322; bh=yGcHWwkxECcUSoQAqH2HqIZHreCcZ/w+hbs60woLkr4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gGiTigrtczFYwxqGbLmrxQRhPlHREVVEHZ/nBpVfgiVeNZ3g6wiMCq1kApzWdR7J5 XsH0dzB+ZsUe9P61K03etHJjcfJmNEsJRjEJLAkr3fREV9GnhBpftEYYae3lRp1TvC w1KALwpUJ8kUa3+H5W+Rm09z5NZDGMNJSgqiNL78= From: "yann at droneaud dot fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/107618] Incorrect diagnostics when using -Og, builtin_expect(), and function attribute "warning" or "error" Date: Thu, 10 Nov 2022 17:45:21 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: yann at droneaud dot fr 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: Message-ID: In-Reply-To: References: 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=3D107618 --- Comment #2 from Yann Droneaud --- I was wondering what GCC expects __builtin_object_size(0, 0) to be, and used the following: void a_1 (void) __attribute__((__warning__("-1"))); void a0 (void) __attribute__((__warning__("0"))); void a1 (void) __attribute__((__warning__("1"))); void a2 (void) __attribute__((__warning__("2"))); void a3 (void) __attribute__((__warning__("3"))); void a4 (void) __attribute__((__warning__("4"))); int main(void) { unsigned long b =3D __builtin_object_size(0, 0); if (__builtin_expect(b =3D=3D (unsigned long)-1, 0)) a_1(); if (__builtin_expect(b =3D=3D 0, 0)) a0(); if (__builtin_expect(b =3D=3D 1, 0)) a1(); if (__builtin_expect(b =3D=3D 2, 0)) a2(); if (__builtin_expect(b =3D=3D 3, 0)) a3(); if (__builtin_expect(b =3D=3D 4, 0)) a4(); } It works as expected for any level above 0, except -Og: $ gcc -O1 -S warning.c warning.c: In function =E2=80=98main=E2=80=99: warning.c:11:5: warning: call to =E2=80=98a_1=E2=80=99 declared with at= tribute warning: -1 [-Wattribute-warning] 11 | a_1(); | ^~~~~ It's quite reassuring that __builtin_object_size(0, 0) returns -1, hence the emitted call to a_1(): $ cat warning.s .file "warning.c" .text .globl main .type main, @function main: endbr64 subq $8, %rsp call a_1@PLT movl $0, %eax addq $8, %rsp ret For -Og, there's a firework of warnings (shockingly they're the same than -= O0 level): $ gcc -Og -S warning.c warning.c: In function =E2=80=98main=E2=80=99: warning.c:11:5: warning: call to =E2=80=98a_1=E2=80=99 declared with at= tribute warning: -1 [-Wattribute-warning] 11 | a_1(); | ^~~~~ warning.c:13:5: warning: call to =E2=80=98a0=E2=80=99 declared with att= ribute warning: 0 [-Wattribute-warning] 13 | a0(); | ^~~~ warning.c:15:5: warning: call to =E2=80=98a1=E2=80=99 declared with att= ribute warning: 1 [-Wattribute-warning] 15 | a1(); | ^~~~ warning.c:17:5: warning: call to =E2=80=98a2=E2=80=99 declared with att= ribute warning: 2 [-Wattribute-warning] 17 | a2(); | ^~~~ warning.c:19:5: warning: call to =E2=80=98a3=E2=80=99 declared with att= ribute warning: 3 [-Wattribute-warning] 19 | a3(); | ^~~~ warning.c:21:5: warning: call to =E2=80=98a4=E2=80=99 declared with att= ribute warning: 4 [-Wattribute-warning] 21 | a4(); | ^~~~ Generated assembly for -Og is the same than for levels above 0: a call to a= _1() function is emitted, which mean GCC, at some point, knows __builtin_object_size(0, 0) is -1 here. Thus most of the warnings are not v= ery useful. $ cat warning.s .file "warning.c" .text .globl main .type main, @function main: endbr64 subq $8, %rsp call a_1@PLT movl $0, %eax addq $8, %rsp ret=