This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[AVR] Fix bug 34299


Hello.

  In AVR target using "signal" or "interrupt" attributes in function
definition causes ICE . The reason for this is that the
"avr_handle_fndecl_attribute" checks the name of the function used as
interrupt handler routine and use DECL_ASSEMBLER_NAME macro for getting
function name. But DECL_ASSEMBLER_NAME has a side effect of setting
assembler_name for functions, which causes the assertion failure in c-decl.c.

  The DECL_NAME macro can not be used instead of DECL_ASSEMBLER_NAME, because
unfounded warnings for ADA code is generated in this case (bug #25448):

   procedure My_int;
   pragma Machine_Attribute (My_int, "signal");
   pragma Export (C, My_int, "__vector_1");
   procedure My_int is begin null; end;

demo_ada.adb:9: warning: `demo_ada__my_int' appears to be a misspelled
signal handler

 In Ada, the source code function name (demo_ada__my_int) for interrupts is
translated to__vector_xx with the "Pragma Export (..)" statement.
Its not possible to define "__vector_1" as a source code function name.

  Because neither the DECL_NAME nor the DECL_ASSEMBLER_NAME macro can be used
to get the function name in "avr_handle_fndecl_attribute", I move check for
correct interrupt handler routine name in the ASM_DECLARE_FUNCTION_NAME.

2009-03-14  Anatoly Sokolov  <aesok@post.ru>

        PR target/34299
        * config/avr/avr.c (avr_handle_fndecl_attribute): Move code for
        generate a warning if the function name does not begin with
        "__vector" and the function has either the 'signal' or 'interrupt'
        attribute, from here to ...
        (avr_declare_function_name): ...here. New function.
        * config/avr/avr.h (ASM_DECLARE_FUNCTION_NAME): Redefine.
        * config/avr/avr-protos.h (avr_declare_function_name): Declare


Index: gcc/config/avr/avr-protos.h
===================================================================
--- gcc/config/avr/avr-protos.h	(revision 144858)
+++ gcc/config/avr/avr-protos.h	(working copy)
@@ -1,6 +1,6 @@
 /* Prototypes for exported functions defined in avr.c
    
-   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008
+   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
    Contributed by Denis Chertykov (denisc@overta.ru)
 
@@ -32,6 +32,7 @@
 extern enum reg_class avr_reg_class_from_letter (int c);
 extern int frame_pointer_required_p (void);
 extern void asm_globalize_label (FILE *file, const char *name);
+extern void avr_asm_declare_function_name (FILE *, const char *, tree);
 extern void order_regs_for_local_alloc (void);
 extern int initial_elimination_offset (int from, int to);
 extern int avr_simple_epilogue (void);
Index: gcc/config/avr/avr.c
===================================================================
--- gcc/config/avr/avr.c        (revision 144858)
+++ gcc/config/avr/avr.c        (working copy)
@@ -4595,6 +4595,39 @@
   return default_assemble_integer (x, size, aligned_p);
 }
 
+/* Worker function for ASM_DECLARE_FUNCTION_NAME.  */
+
+void
+avr_asm_declare_function_name (FILE *file, const char *name, tree decl)
+{
+
+  /* If the function has the 'signal' or 'interrupt' attribute, test to
+     make sure that the name of the function is "__vector_NN" so as to
+     catch when the user misspells the interrupt vector name.  */
+
+  if (cfun->machine->is_interrupt)
+    {
+      if (strncmp (name, "__vector", strlen ("__vector")) != 0)
+        {
+          warning_at (DECL_SOURCE_LOCATION (decl), 0,
+                      "%qs appears to be a misspelled interrupt handler",
+                      name);
+        }
+    }
+  else if (cfun->machine->is_signal)
+    {
+      if (strncmp (name, "__vector", strlen ("__vector")) != 0)
+        {
+           warning_at (DECL_SOURCE_LOCATION (decl), 0,
+                       "%qs appears to be a misspelled signal handler",
+                       name);
+        }
+    }
+
+  ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "function");
+  ASM_OUTPUT_LABEL (file, name);
+}
+
 /* The routine used to output NUL terminated strings.  We use a special
    version of this for most svr4 targets because doing so makes the
    generated assembly code more compact (and thus faster to assemble)
@@ -4779,33 +4812,7 @@
               IDENTIFIER_POINTER (name));
       *no_add_attrs = true;
     }
-  else
-    {
-      const char *func_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (*node));
-      const char *attr = IDENTIFIER_POINTER (name);
 
-      /* If the function has the 'signal' or 'interrupt' attribute, test to
-         make sure that the name of the function is "__vector_NN" so as to
-         catch when the user misspells the interrupt vector name.  */
-
-      if (strncmp (attr, "interrupt", strlen ("interrupt")) == 0)
-        {
-          if (strncmp (func_name, "__vector", strlen ("__vector")) != 0)
-            {
-              warning (0, "%qs appears to be a misspelled interrupt handler",
-                       func_name);
-            }
-        }
-      else if (strncmp (attr, "signal", strlen ("signal")) == 0)
-        {
-          if (strncmp (func_name, "__vector", strlen ("__vector")) != 0)
-            {
-              warning (0, "%qs appears to be a misspelled signal handler",
-                       func_name);
-            }
-        }
-    }
-
   return NULL_TREE;
 }
 
Index: gcc/config/avr/avr.h
===================================================================
--- gcc/config/avr/avr.h        (revision 144858)
+++ gcc/config/avr/avr.h        (working copy)
@@ -590,10 +590,7 @@
    specific tm.h file (depending upon the particulars of your assembler).  */
 
 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)            \
-do {                                                           \
-     ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function");       \
-     ASM_OUTPUT_LABEL (FILE, NAME);                            \
-} while (0)
+avr_asm_declare_function_name ((FILE), (NAME), (DECL))
 
 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)                   \
   do {                                                                 \


Anatoly.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]