From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9EF963858C53; Wed, 27 Apr 2022 02:03:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9EF963858C53 From: "egallager at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/105401] New: Improved diagnostics for code from "Labels as Values" documentation Date: Wed, 27 Apr 2022 02:03:59 +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: 12.0 X-Bugzilla-Keywords: diagnostic, documentation X-Bugzilla-Severity: normal X-Bugzilla-Who: egallager at gcc dot gnu.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 keywords 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Apr 2022 02:03:59 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105401 Bug ID: 105401 Summary: Improved diagnostics for code from "Labels as Values" documentation Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: diagnostic, documentation Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: egallager at gcc dot gnu.org Target Milestone: --- Continuing my GCC documentation readthrough, I'm now up to the description = of the "Labels as Values" extension: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html#Labels-as-Values I pulled together this code from the examples on the page: $ cat labels_as_values.c void unsafe(void *); static inline int asdf(void) { bar: void *ptr0; static void *ptr1 =3D &&bar; /* ... */ foo: ptr0 =3D &&foo; goto *ptr0; goto *ptr1; unsafe(ptr0); unsafe(ptr1); return (sizeof(ptr0) + sizeof(ptr1)); } static inline int zxcv(int i) { foo: static void *array[] =3D { &&foo, &&bar, &&hack }; bar: goto *array[i]; hack: return sizeof(array[i]); } int qwerty(int i) { foo: static const int array[] =3D { &&foo - &&foo, &&bar - &&foo, &&hack - &&foo }; bar: goto *(&&foo + array[i]); hack: return (zxcv(array[i]) + asdf()); } $ Compiling the code with "-Wall -Wextra -Wc++-compat -Winline" produces no warnings (-pedantic, on the other hand, produces plenty of warnings, but th= at's to be expected, since this is an extension). To match this back to things t= he documentation says: 1. "Note that this does not check whether the subscript is in bounds=E2=80= =94array indexing in C never does that." ...ok, but we have -Warray-bounds now; maybe the documentation could be updated to mention that, or would -Warray-bounds have to be updated to handle cases like this first? 2. "You may not use this mechanism to jump to code in a different function.= If you do that, totally unpredictable things happen. The best way to avoid thi= s is to store the label address only in automatic variables and never pass it as= an argument." ...ok well I store label addresses in non-automatic variables, a= nd pass them as arguments in my example code, and I don't get any warnings; co= uld those be added? 3. "The &&foo expressions for the same label might have different values if= the containing function is inlined or cloned. If a program relies on them being always the same, __attribute__((__noinline__,__noclone__)) should be used to prevent inlining and cloning. If &&foo is used in a static variable initializer, inlining and cloning is forbidden." ...ok, so shouldn't -Winli= ne say something about my example code, then? But, it doesn't...=