This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] gold: add cast to gold_unreachable to workaround gcc giving invalid "no return statement" warnings
- From: Ian Lance Taylor <iant at google dot com>
- To: Mikolaj Zalewski <mikolajz at google dot com>
- Cc: binutils at sourceware dot org
- Date: Fri, 14 Aug 2009 01:34:26 -0700
- Subject: Re: [PATCH] gold: add cast to gold_unreachable to workaround gcc giving invalid "no return statement" warnings
- References: <7ebec9e70908130809n1eadef26o479906b6e228caea@mail.gmail.com>
Mikolaj Zalewski <mikolajz@google.com> writes:
> I couldn't compile gold today because of the "no return statement"
> warning when using gold_unreachable. At
> http://gcc.gnu.org/ml/gcc-bugs/2007-11/msg01605.html I've found a
> workaround that should work for gcc >= 3.4. Such a patch that affects
> only gold_unreachable is ok?
>
> 2009-08-13 Mikolaj Zalewski <mikolajz@google.com>
>
> * gold.h (gold_unreachable): Add a cast.
I would prefer a patch like this one, which gives us a way to clean it
up a few years down the road. Could you check whether this solves the
problem for you? If it does, I'll commit it. Thanks.
Ian
2009-08-14 Ian Lance Taylor <iant@google.com>
* gold.h (FUNCTION_NAME): Define.
(gold_unreachable): Use FUNCTION_NAME.
Index: gold.h
===================================================================
RCS file: /cvs/src/src/gold/gold.h,v
retrieving revision 1.39
diff -p -u -r1.39 gold.h
--- gold.h 5 Aug 2009 20:51:56 -0000 1.39
+++ gold.h 14 Aug 2009 08:30:51 -0000
@@ -253,11 +253,22 @@ gold_undefined_symbol_at_location(const
extern void
gold_nomem() ATTRIBUTE_NORETURN;
+// In versions of gcc before 4.3, using __FUNCTION__ in a template
+// function can cause gcc to get confused about whether or not the
+// function can return. See http://gcc.gnu.org/PR30988. Use a macro
+// to avoid the problem. This can be removed when we no longer need
+// to care about gcc versions before 4.3.
+#if defined(__GNUC__) && GCC_VERSION < 4003
+#define FUNCTION_NAME static_cast<const char*>(__FUNCTION__)
+#else
+#define FUNCTION_NAME __FUNCTION__
+#endif
+
// This macro and function are used in cases which can not arise if
// the code is written correctly.
#define gold_unreachable() \
- (gold::do_gold_unreachable(__FILE__, __LINE__, __FUNCTION__))
+ (gold::do_gold_unreachable(__FILE__, __LINE__, FUNCTION_NAME))
extern void do_gold_unreachable(const char*, int, const char*)
ATTRIBUTE_NORETURN;