]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
AVR: Improve location of late diagnostics.
authorGeorg-Johann Lay <avr@gjlay.de>
Tue, 3 Dec 2024 13:19:40 +0000 (14:19 +0100)
committerGeorg-Johann Lay <avr@gjlay.de>
Tue, 3 Dec 2024 20:52:06 +0000 (21:52 +0100)
Some diagnostics are issues late, e.g. in avr_print_operand().
This patch uses the insn's location as a proxy for the operand
location.  Without the patch, the location is usually input_location,
which points to the closing } of the function body.

gcc/
* config/avr/avr.cc (avr_insn_location): New variable.
(avr_final_prescan_insn): Set avr_insn_location.
(avr_asm_final_postscan_insn): Unset avr_insn_location after last insn.
(avr_print_operand): Pass avr_insn_location to warning_at.

gcc/testsuite/
* gcc.dg/Warray-bounds-33.c: Adjust for avr diagnostics.
* gcc.dg/pr56228.c: Same.
* gcc.dg/pr86124.c: Same.
* gcc.dg/pr94291.c: Same.
* gcc.dg/tree-ssa/pr82059.c: Same.

gcc/config/avr/avr.cc
gcc/testsuite/gcc.dg/Warray-bounds-33.c
gcc/testsuite/gcc.dg/pr56228.c
gcc/testsuite/gcc.dg/pr86124.c
gcc/testsuite/gcc.dg/pr94291.c
gcc/testsuite/gcc.dg/tree-ssa/pr82059.c

index ccf9b05bb3e5cc79e562328915c0b4826ffdc952..9bebd67cd9c4453c75a0b1d2747c312923f66707 100644 (file)
@@ -234,6 +234,7 @@ bool avr_has_rodata_p = false;
    insn condition for shift insn splitters.  */
 int n_avr_fuse_add_executed = 0;
 
+static location_t avr_insn_location = UNKNOWN_LOCATION;
 
 \f
 /* Transform UP into lowercase and write the result to LO.
@@ -2712,12 +2713,17 @@ avr_print_operand (FILE *file, rtx x, int code)
            fatal_insn ("bad address, not a constant:", addr);
          /* Assembler template with m-code is data - not progmem section */
          if (text_segment_operand (addr, VOIDmode))
-           if (warning (0, "accessing data memory with"
-                        " program memory address"))
-             {
-               output_addr_const (stderr, addr);
-               fprintf(stderr,"\n");
-             }
+           {
+             location_t loc = avr_insn_location != UNKNOWN_LOCATION
+               ? avr_insn_location
+               : input_location;
+             if (warning_at (loc, 0, "accessing data memory with"
+                             " program memory address"))
+               {
+                 output_addr_const (stderr, addr);
+                 fprintf (stderr,"\n");
+               }
+           }
          output_addr_const (file, addr);
        }
       else if (code == 'o')
@@ -2760,12 +2766,17 @@ avr_print_operand (FILE *file, rtx x, int code)
     {
       /* Constant progmem address - like used in jmp or call */
       if (text_segment_operand (x, VOIDmode) == 0)
-       if (warning (0, "accessing program memory"
-                    " with data memory address"))
-         {
-           output_addr_const (stderr, x);
-           fprintf (stderr, "\n");
-         }
+       {
+         location_t loc = avr_insn_location != UNKNOWN_LOCATION
+           ? avr_insn_location
+           : input_location;
+         if (warning_at (loc, 0, "accessing program memory"
+                         " with data memory address"))
+           {
+             output_addr_const (stderr, x);
+             fprintf (stderr, "\n");
+           }
+       }
       /* Use normal symbol for direct address no linker trampoline needed */
       output_addr_const (file, x);
     }
@@ -2954,6 +2965,8 @@ void
 avr_final_prescan_insn (rtx_insn *insn, rtx * /*operands*/,
                        int /*num_operands*/)
 {
+  avr_insn_location = LOCATION_LOCUS (INSN_LOCATION (insn));
+
   if (avr_log.rtx_costs)
     {
       rtx set = single_set (insn);
@@ -2982,6 +2995,9 @@ avr_final_prescan_insn (rtx_insn *insn, rtx * /*operands*/,
 static void
 avr_asm_final_postscan_insn (FILE *stream, rtx_insn *insn, rtx *, int)
 {
+  if (!next_real_insn (insn))
+    avr_insn_location = UNKNOWN_LOCATION;
+
   if (cfun->machine->gasisr.yes
       && !next_real_insn (insn))
     {
index 13efabe33b6ebcb0f51468b081aa7f7c52dd9068..5f06471f820785d3e16bfe248763fe9bf1a5c5ac 100644 (file)
@@ -2,7 +2,6 @@
    an object of incomplete type
    { dg-do compile }
    { dg-options "-O2 -Wall" }  */
-/* { dg-skip-if "acessing data memory with program memory address" { "avr-*-*" } } */
 
 struct S
 {
@@ -30,7 +29,7 @@ void test_incomplete_enum (void)
 void test_func (void)
 {
   struct S *b = (struct S*)&f;
-  if (b->s)
+  if (b->s) /* { dg-warning "accessing data memory with program memory address.*" "" { target avr-*-* } } */
     f ();
 }
 
index 6e2b4b1ab9913176b3731ebf904ba87d188bef92..79699a21c16f1ef4a2a6ddda2815d386ee97e276 100644 (file)
@@ -1,7 +1,6 @@
 /* PR target/56228 */
 /* { dg-do assemble } */
 /* { dg-options "-O2" } */
-/* { dg-skip-if "accessing program memory with data memory address" { "avr-*-*" } } */
 
 short a[14] = { 1, 2 };
 short b[15] = { 3, 4 };
@@ -11,7 +10,7 @@ foo ()
 {
   void (*fna) (void) = (void (*) (void)) a;
   void (*fnb) (void) = (void (*) (void)) b;
-  fna ();
+  fna (); /* { dg-warning "accessing program memory with data memory address.*" "" { target avr-*-* } } */
   fnb ();
   return a[1] == b[1];
 }
index c8a66ffbfb4c5a1a8b97fe212c6e8baeb2784810..ebcaed78842644c2d06539fbc47050cbe72e2aae 100644 (file)
@@ -1,6 +1,5 @@
 /* { dg-do compile } */
 /* { dg-options "-O -fipa-pta" } */
-/* { dg-skip-if "acessing data memory with program memory address" { "avr-*-*" } } */
 
 extern void a (void);
 
@@ -8,5 +7,5 @@ void b (void)
 {
   void *c;
   c = a;
-  *(char *)c = 1;
+  *(char *)c = 1; /* { dg-warning "accessing data memory with program memory address.*" "" { target avr-*-* } } */
 }
index 7d9331b391f5ac0f2c1c53dbca7a557aadf1d2e7..400524cc5062d6d008ee6a9dd320ea738d2b9745 100644 (file)
@@ -1,7 +1,6 @@
 /* PR rtl-optimization/94291 */
 /* { dg-do compile } */
 /* { dg-options "-Og" } */
-/* { dg-skip-if "accessing data memory with program memory address" { "avr-*-*" } } */
 
 unsigned a;
 
@@ -10,6 +9,7 @@ foo (void)
 {
   unsigned x
     = (__builtin_sub_overflow ((long long) a, 0, &x)
-       ? 1 : (__INTPTR_TYPE__) __builtin_memmove (&x, foo, 1));
+       ? 1 : (__INTPTR_TYPE__) __builtin_memmove (&x, foo, 1)); /* { dg-warning "accessing data memory with program memory address.*" "" { target avr-*-* } } */
+
   return a;
 }
index 6421101b86777223d19ed8b9c730fd106c0cad69..ffa643faa173f28821509817d02153aa061d3f4b 100644 (file)
@@ -1,7 +1,6 @@
 /* PR tree-optimization/82059 */
 /* { dg-do compile } */
 /* { dg-options "-O2 -fdump-tree-isolate-paths" } */
-/* { dg-skip-if "accessing data memory with program memory address" { avr-*-* } } */
 
 struct a
 {
@@ -19,5 +18,5 @@ h ()
   if (!i)
     d ();
   i->c = &f;
-  i->b = *(char *) h;
+  i->b = *(char *) h; /* { dg-warning "accessing data memory with program memory address.*" "" { target avr-*-* } } */
 }