From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8C284385782D; Thu, 25 Nov 2021 12:06:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C284385782D From: "tschwinge at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/46476] Missing Warning about unreachable code after return [-Wunreachable-code-return] Date: Thu, 25 Nov 2021 12:06:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.6.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: tschwinge at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc 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 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: Thu, 25 Nov 2021 12:06:18 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D46476 Thomas Schwinge changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |tschwinge at gcc dot gnu.o= rg --- Comment #20 from Thomas Schwinge --- (In reply to Richard Biener from comment #18) > /home/rguenther/src/trunk/libgomp/oacc-plugin.c: In function > 'GOMP_PLUGIN_acc_default_dim': > /home/rguenther/src/trunk/libgomp/oacc-plugin.c:65:7: error: statement is > not reachable [-Werror] > 65 | return -1; > | ^~~~~~ (That's correct, and you do address that in the patch posted.) It feels strange to not have a 'return' in a non-'void' function, but that's fine, given 'gomp_fatal' being 'noreturn'. For posterity (only; these "bad" cases have not made it into the patch post= ed): > /home/rguenther/src/trunk/libgomp/oacc-profiling.c: In function > 'acc_prof_register': > /home/rguenther/src/trunk/libgomp/oacc-profiling.c:354:7: error: statement > is not reachable [-Werror] > 354 | __builtin_unreachable (); > | ^~~~~~~~~~~~~~~~~~~~~ > /home/rguenther/src/trunk/libgomp/oacc-profiling.c: In function > 'acc_prof_unregister': > /home/rguenther/src/trunk/libgomp/oacc-profiling.c:475:7: error: statement > is not reachable [-Werror] > 475 | __builtin_unreachable (); > | ^~~~~~~~~~~~~~~~~~~~~ >=20 > the latter two are an issue with inital CFG construction I think, where > group_case_labels turns >=20 > void bar (foo x) > { > : > switch (x) , case 0: , case 1: > >=20 > : > : > goto ; >=20 > : > : > __builtin_unreachable (); >=20 > : > : > return; >=20 > into the following with BB 4 now unreachable. >=20 > void bar (foo x) > { > : > switch (x) , case 0: > >=20 > : > : > goto ; >=20 > : > : > __builtin_unreachable (); >=20 > : > : > return; The source-level situation here is: [...] 256 /* Special cases. */ 257 if (reg =3D=3D acc_toggle) [...] 274 else if (reg =3D=3D acc_toggle_per_thread) 275 { [...] 284 /* Silently ignore. */ 285 gomp_debug (0, " ignoring bogus request\n"); 286 return; 287 } [...] 302 switch (reg) 303 { [...] 353 case acc_toggle_per_thread: 354 __builtin_unreachable (); 355 } [...] ..., and similar for the other instance. Here, the point is to (a) enumerate all possible 'enum' values in the 'swit= ch (reg)', but (b) make it clear ('__builtin_unreachable') that we're not expecting 'acc_toggle_per_thread' here, as it has already been handled (plus early 'return') above. In my opinion, we shouldn't diagnose these cases (a= nd you don't, per the patch posted).=