set_inlining_locations looks at a possible macro expansion location
when the location is in a system header but it fails to update its
counter when there's no macro involved.  The following fixes that.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

This doesn't fix the observed diagnostic in the PR which I think is
now given by design since we diagnose inlined code from a system
header into a function not in a system header.  But I think it still
fixes a bug.

The whole set_inlining_locations is a bit pointless since all that
matters should be the location of the call (and its system header
status) then.  I'll also note that -Wno-system-headers doesn't
help and we don't have any flag to disable diagnosing 
inlined-from-system-header code either.

Unfortunately this is all from changes done by Martin Sebor so
it's difficult to tell the true intention.  The code in
set_inlining_locations doesn't really do what it documents
but fixing (I'll attach the "failed" patch in the PR) will
break testcases that test we diagnose inline copies.

Anyway - OK for the change below where I don't have any testcase.

Thanks,
Richard.

        PR middle-end/109559
        * tree-diagnostic.cc (set_inlining_locations): Always
        increment nsyslocs when loc is in a system header.
---
 gcc/tree-diagnostic.cc | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/gcc/tree-diagnostic.cc b/gcc/tree-diagnostic.cc
index a660c7d0785..e050a6eccf6 100644
--- a/gcc/tree-diagnostic.cc
+++ b/gcc/tree-diagnostic.cc
@@ -339,24 +339,14 @@ set_inlining_locations (diagnostic_context *,
       block = BLOCK_SUPERCONTEXT (block);
     }
 
+  if (in_system_header_at (loc))
+    ++nsyslocs;
+
+  /* When there is an inlining context use the macro expansion
+     location for the original location and bump up NSYSLOCS if
+     it's in a system header since it's not counted above.  */
   if (ilocs.length ())
-    {
-      /* When there is an inlining context use the macro expansion
-        location for the original location and bump up NSYSLOCS if
-        it's in a system header since it's not counted above.  */
-      location_t sysloc = expansion_point_location_if_in_system_header (loc);
-      if (sysloc != loc)
-       {
-         loc = sysloc;
-         ++nsyslocs;
-       }
-    }
-  else
-    {
-      /* When there's no inlining context use the original location
-        and set NSYSLOCS accordingly.  */
-      nsyslocs = in_system_header_at (loc) != 0;
-    }
+    loc = expansion_point_location_if_in_system_header (loc);
 
   ilocs.safe_push (loc);
 
-- 
2.35.3

Reply via email to