From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22545 invoked by alias); 17 Dec 2009 17:12:33 -0000 Received: (qmail 22537 invoked by uid 22791); 17 Dec 2009 17:12:31 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mail3.caviumnetworks.com (HELO mail3.caviumnetworks.com) (12.108.191.235) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 17 Dec 2009 17:12:27 +0000 Received: from caexch01.caveonetworks.com (Not Verified[192.168.16.9]) by mail3.caviumnetworks.com with MailMarshal (v6,5,4,7535) id ; Thu, 17 Dec 2009 09:09:34 -0800 Received: from caexch01.caveonetworks.com ([192.168.16.9]) by caexch01.caveonetworks.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 17 Dec 2009 09:09:28 -0800 Received: from dd1.caveonetworks.com ([12.108.191.236]) by caexch01.caveonetworks.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Thu, 17 Dec 2009 09:09:28 -0800 Message-ID: <4B2A65C6.7080009@caviumnetworks.com> Date: Thu, 17 Dec 2009 17:12:00 -0000 From: David Daney User-Agent: Thunderbird 2.0.0.21 (X11/20090320) MIME-Version: 1.0 To: Jamie Lokier , "gcc@gcc.gnu.org" CC: =?ISO-8859-1?Q?Uwe_Kleine-K=F6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ARM: Convert BUG() to use unreachable() References: <1260266138-17684-1-git-send-email-u.kleine-koenig@pengutronix.de> <20091217150120.GD24967@shareable.org> In-Reply-To: <20091217150120.GD24967@shareable.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2009-12/txt/msg00249.txt.bz2 Jamie Lokier wrote: > Uwe Kleine-König wrote: >> Use the new unreachable() macro instead of for(;;); >> *(int *)0 = 0; >> >> /* Avoid "noreturn function does return" */ >> - for (;;); >> + unreachable(); > > Will GCC-4.5 remove ("optimise away") the *(int *)0 = 0 because it > knows the branch of the code leading to unreachable can never be reached? > I don't know the definitive answer, so I am sending to gcc@... FYI: #define unreachable() __builtin_unreachable() > If GCC-4.5 does not, are you sure a future version of GCC will never > remove it? In other words, is __builtin_unreachable() _defined_ in > such a way that it cannot remove the previous assignment? > > We have seen problems with GCC optimising away important tests for > NULL pointers in the kernel, due to similar propagation of "impossible > to occur" conditions, so it's worth checking with GCC people what the > effect of this one would be. > > In C, there is a general theoretical problem with back-propagation of > optimisations from code with undefined behaviour. In the case of > __builtin_unreachable(), it would depend on all sorts of unclearly > defined semantics whether it can remove a preceding *(int *)0 = 0. > > I'd strongly suggest asking on the GCC list. (I'd have mentioned this > earlier, if I'd known about the patch for other architectures). > > The documentation for __builtin_unreachable() only says the program is > undefined if control flow reaches it. In other words, it does not say > what effect it can have on previous instructions, and I think it's > quite likely that it has not been analysed in a case like this. > > One thing that would give me a lot more confidence, because the GCC > documentation does mention asm(), is this: > >> *(int *)0 = 0; >> /* Ensure unreachableness optimisations cannot propagate back. *I/ >> __asm__ volatile(""); >> /* Avoid "noreturn function does return" */ >> unreachable(); > > -- Jamie