]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
AVR: Diagnose unsupported built-ins in avr_resolve_overloaded_builtin.
authorGeorg-Johann Lay <avr@gjlay.de>
Sat, 15 Feb 2025 13:35:24 +0000 (14:35 +0100)
committerGeorg-Johann Lay <avr@gjlay.de>
Sun, 16 Feb 2025 15:41:09 +0000 (16:41 +0100)
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): Move to...
* config/avr/avr-c.cc: ...here.
(avr_resolve_overloaded_builtin): Run avr_builtin_supported_p.

gcc/config/avr/avr-c.cc
gcc/config/avr/avr-protos.h
gcc/config/avr/avr.cc

index f4236555bf6cf326ea98b3633052326e974081eb..6f49d3f98a0b64019a0b99a633f8e7e1003a2bf9 100644 (file)
@@ -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
index 6f37c48143ec82377a785ba18eec9ae2deaf864d..83137c7f6f63fbee8c3354ec936483b301261d22 100644 (file)
@@ -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);
index e358a2e8b8dabd703ddc0720460a3b32cd4df0fb..7acd260aace73dd3d4ce80c74fed3d9601b501db 100644 (file)
@@ -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