From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mengyan1223.wang (unknown [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id AB22F384B821 for ; Thu, 9 Jul 2020 15:00:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AB22F384B821 Received: from xry111-X57S1 (unknown [115.155.1.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id E72F965AD8; Thu, 9 Jul 2020 11:00:31 -0400 (EDT) Message-ID: <6e02fef204a84b1015f8e1973f1236ff17721e4d.camel@mengyan1223.wang> Subject: Re: gcc warn unreached else {} From: Xi Ruoyao Reply-To: gcc-help To: Jonny Grant Cc: gcc-help Date: Thu, 09 Jul 2020 23:00:28 +0800 In-Reply-To: <3a091703-4842-b738-bb38-fab01e787650@jguk.org> References: <3a091703-4842-b738-bb38-fab01e787650@jguk.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.3 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=4.4 required=5.0 tests=BAYES_05, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: **** X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jul 2020 15:00:56 -0000 On 2020-07-09 10:45 +0100, Jonny Grant wrote: > Hello! > > There is an example below, (my code is not like this example below). I'm > reporting a possible issue, and asking if there is a way to detect it in code > bases. If it's a real issue I can file a bug report on Bugzilla. > > Can gcc warn where code will not get to the 'return 3;' below? > > Cheers, Jonny > > > int main(void) > { > const int i = 1; > if(1 == i) > { > return 1; > } > else if(1 != i) > { > return 2; > } > else > { > return 3; > } > } Generally finding all the branches in a program impossible to be executed is unsolvable. Even in a program without any loop it's still NP-hard. For some "simple" cases maybe we can implement some heuristics, or use a brute force approach (as a part of -fanalyzer). But I doubt if these simple cases are really useful. -- Xi Ruoyao School of Aerospace Science and Technology, Xidian University