This patch executes avr_builtin_supported_p at a later time and in
avr_resolve_overloaded_builtin. This allows for better diagnostics
and avoids lto1 hiccups when a built-in decl is NULL_TREE.
Ok for trunk?
Johann
--
AVR: Diagnose unsupported built-ins in avr_resolve_overloaded_builtin.
This patch executes avr_builtin_supported_p at a later time and in
avr_resolve_overloaded_builtin. This allows for better diagnostics
and avoids lto1 hiccups when a built-in decl is NULL_TREE.
gcc/
* config/avr/avr-protos.h (avr_builtin_supported_p): Remove.
* config/avr/avr.cc (avr_init_builtins): Don't initialize
non-available built-ins with NULL_TREE.
(avr_builtin_supported_p): Mote to...
* config/avr/avr-c.cc: ...here.
(avr_resolve_overloaded_builtin): Run avr_builtin_supported_p. AVR: Diagnose unsupported built-ins in avr_resolve_overloaded_builtin.
This patch executes avr_builtin_supported_p at a later time and in
avr_resolve_overloaded_builtin. This allows for better diagnostics
and avoids lto1 hiccups when a built-in decl is NULL_TREE.
gcc/
* config/avr/avr-protos.h (avr_builtin_supported_p): Remove.
* config/avr/avr.cc (avr_init_builtins): Don't initialize
non-available built-ins with NULL_TREE.
(avr_builtin_supported_p): Mote to...
* config/avr/avr-c.cc: ...here.
(avr_resolve_overloaded_builtin): Run avr_builtin_supported_p.
diff --git a/gcc/config/avr/avr-c.cc b/gcc/config/avr/avr-c.cc
index f4236555bf6..6f49d3f98a0 100644
--- a/gcc/config/avr/avr-c.cc
+++ b/gcc/config/avr/avr-c.cc
@@ -45,16 +45,52 @@ enum avr_builtin_id
};
-/* Implement `TARGET_RESOLVE_OVERLOADED_PLUGIN'. */
+/* Some of our built-in functions are available for GNU-C only:
+ - Built-ins that use named address-spaces.
+ - Built-ins that use fixed-point types. */
+
+static bool
+avr_builtin_supported_p (location_t loc, avr_builtin_id bid)
+{
+ if (! lang_GNU_C () // Means "C" actually, not "GNU-C".
+ && bid >= AVR_FIRST_C_ONLY_BUILTIN_ID)
+ {
+ if (loc != UNKNOWN_LOCATION)
+ error_at (loc, "built-in function is only supported for GNU-C");
+ return false;
+ }
+
+ const bool uses_as = (bid == AVR_BUILTIN_FLASH_SEGMENT
+ || bid == AVR_BUILTIN_STRLEN_FLASH
+ || bid == AVR_BUILTIN_STRLEN_FLASHX
+ || bid == AVR_BUILTIN_STRLEN_MEMX);
+ if (AVR_TINY && uses_as)
+ {
+ if (loc != UNKNOWN_LOCATION)
+ error_at (loc, "built-in function for named address-space is not"
+ " supported for reduced Tiny devices");
+ return false;
+ }
+
+ return true;
+}
+
+
+/* Implement `TARGET_RESOLVE_OVERLOADED_BUILTIN'. */
static tree
avr_resolve_overloaded_builtin (location_t loc, tree fndecl, void *vargs, bool)
{
+ const avr_builtin_id bid = (avr_builtin_id) DECL_MD_FUNCTION_CODE (fndecl);
+
+ if (! avr_builtin_supported_p (loc, bid))
+ return error_mark_node;
+
tree type0, type1, fold = NULL_TREE;
avr_builtin_id id = AVR_BUILTIN_COUNT;
vec<tree, va_gc> &args = * (vec<tree, va_gc> *) vargs;
- switch (DECL_MD_FUNCTION_CODE (fndecl))
+ switch (bid)
{
default:
break;
@@ -499,8 +535,8 @@ avr_cpu_cpp_builtins (cpp_reader *pfile)
/* Define builtin macros so that the user can easily query whether or
not a specific builtin is available. */
-#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE, LIBNAME, ATTRS) \
- if (avr_builtin_supported_p (AVR_BUILTIN_ ## NAME)) \
+#define DEF_BUILTIN(NAME, N_ARGS, TYPE, CODE, LIBNAME, ATTRS) \
+ if (avr_builtin_supported_p (UNKNOWN_LOCATION, AVR_BUILTIN_ ## NAME)) \
cpp_define (pfile, "__BUILTIN_AVR_" #NAME);
#include "builtins.def"
#undef DEF_BUILTIN
diff --git a/gcc/config/avr/avr-protos.h b/gcc/config/avr/avr-protos.h
index 6f37c48143e..83137c7f6f6 100644
--- a/gcc/config/avr/avr-protos.h
+++ b/gcc/config/avr/avr-protos.h
@@ -21,7 +21,6 @@
extern bool avr_function_arg_regno_p (int r);
extern void avr_cpu_cpp_builtins (cpp_reader * pfile);
-extern bool avr_builtin_supported_p (unsigned id);
extern enum reg_class avr_regno_reg_class (int r);
extern void asm_globalize_label (FILE *file, const char *name);
extern void avr_adjust_reg_alloc_order (void);
diff --git a/gcc/config/avr/avr.cc b/gcc/config/avr/avr.cc
index e358a2e8b8d..7acd260aace 100644
--- a/gcc/config/avr/avr.cc
+++ b/gcc/config/avr/avr.cc
@@ -15751,27 +15751,6 @@ avr_bdesc[AVR_BUILTIN_COUNT] =
};
-/* Some of our built-in function are available for GNU-C only:
- - Built-ins that use named address-spaces.
- - Built-ins that use fixed-point types. */
-
-bool
-avr_builtin_supported_p (unsigned id)
-{
- const bool uses_as = (id == AVR_BUILTIN_FLASH_SEGMENT
- || id == AVR_BUILTIN_STRLEN_FLASH
- || id == AVR_BUILTIN_STRLEN_FLASHX
- || id == AVR_BUILTIN_STRLEN_MEMX);
-
- // We don't support address-spaces on Reduced Tiny.
- if (AVR_TINY && uses_as)
- return false;
-
- return (lang_GNU_C ()
- || id < AVR_FIRST_C_ONLY_BUILTIN_ID);
-}
-
-
/* Implement `TARGET_BUILTIN_DECL'. */
static tree
@@ -15997,10 +15976,9 @@ avr_init_builtins (void)
char *name = (char *) alloca (1 + strlen (Name)); \
\
gcc_assert (id < AVR_BUILTIN_COUNT); \
- avr_bdesc[id].fndecl = avr_builtin_supported_p (id) \
- ? add_builtin_function (avr_tolower (name, Name), TYPE, id, \
- BUILT_IN_MD, LIBNAME, ATTRS) \
- : NULL_TREE; \
+ avr_bdesc[id].fndecl \
+ = add_builtin_function (avr_tolower (name, Name), TYPE, id, \
+ BUILT_IN_MD, LIBNAME, ATTRS); \
}
#include "builtins.def"
#undef DEF_BUILTIN