Re: [Compile Regression in 2.4.25-pre8][PATCH 37/42]

Kronos
2004-02-03T21:07:40Z

Il Mon, Feb 02, 2004 at 10:08:48PM +0100, Geert Uytterhoeven ha scritto:
> On Mon, 2 Feb 2004, Kronos wrote:
> > siimage.c:65: warning: control reaches end of non-void function
> >
> > The last statement before the end is BUG(), but I added a return to
> > silence the warning.
> >
> > diff -Nru -X dontdiff linux-2.4-vanilla/drivers/ide/pci/siimage.c linux-2.4/drivers/ide/pci/siimage.c
> > --- linux-2.4-vanilla/drivers/ide/pci/siimage.c Tue Nov 11 17:51:38 2003
> > +++ linux-2.4/drivers/ide/pci/siimage.c Sat Jan 31 19:07:56 2004
> > @@ -62,6 +62,9 @@
> > return 0;
> > }
> > BUG();
> > +
> > + /* gcc will complain */
> > + return 0;
> > }
>
> What about adding `attribute ((noreturn))' to the declaration of BUG() instead?

Ok, I cooked up this patch. BUG() is a function marked as noreturn that is
always inlined. Unfortunately, gcc prior to 3.x does not support
__always_inline__ attribute, so I had to revert to the old macro with older
compiler.

The patch fixes warnings with newer compiler, but not with older ones.
Note that the while(1) is needed, otherwise gcc will say that the
function marked as noreturn does actually return.

Comments?

diff -Nru -X dontdiff linux-2.4-vanilla/include/asm-i386/page.h linux-2.4/include/asm-i386/page.h
--- linux-2.4-vanilla/include/asm-i386/page.h Tue Nov 11 18:05:52 2003
+++ linux-2.4/include/asm-i386/page.h Tue Feb 3 07:26:04 2004
@@ -10,6 +10,7 @@
#ifndef __ASSEMBLY__

#include <linux/config.h>
+#include <linux/compiler.h>

#ifdef CONFIG_X86_USE_3DNOW

@@ -94,6 +95,26 @@
* The offending file and line are encoded after the "officially
* undefined" opcode for parsing in the trap handler.
*/
+#ifdef __bug
+#if 1 /* Set to zero for a slightly smaller kernel */
+__bug void __bugfn(void) {
+ while(1) {
+ __asm__ __volatile__( "ud2\n"
+ "\t.word %c0\n"
+ "\t.long %c1\n"
+ : : "i" (__LINE__), "i" (__FILE__));
+ }
+}
+#else
+__bug void __bugfn(void) {
+ while(1) {
+ __asm__ __volatile__("ud2\n");
+ }
+}
+#endif
+#define BUG() __bugfn()
+
+#else /* __bug */

#if 1 /* Set to zero for a slightly smaller kernel */
#define BUG() \
@@ -104,6 +125,8 @@
#else
#define BUG() __asm__ __volatile__("ud2\n")
#endif
+
+#endif /* __bug */

#define PAGE_BUG(page) do { \
BUG(); \
diff -Nru -X dontdiff linux-2.4-vanilla/include/linux/compiler.h linux-2.4/include/linux/compiler.h
--- linux-2.4-vanilla/include/linux/compiler.h Tue Sep 18 23:12:45 2001
+++ linux-2.4/include/linux/compiler.h Tue Feb 3 07:25:57 2004
@@ -13,4 +13,11 @@
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)

+#if __GNUC__ >= 3
+/* __noreturn__ is implemented since gcc 2.5.
+ * __always_inline__ is not present in 2.9x
+ */
+#define __bug __attribute__((__noreturn__, __always_inline__))
+#endif
+
#endif /* __LINUX_COMPILER_H */

Luca
PS: I wrote the patch early this morning, on train. It may be a huge pile of
crap ;)
--
Reply-To: kronos@kronoz.cjb.net
Home: http://kronoz.cjb.net
The trouble with computers is that they do what you tell them,
not what you want.
D. Cohen