public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix build with current GCC: EL_EXPLICIT(location) always non-NULL
@ 2021-11-09 17:33 Pedro Alves
  2021-11-09 18:19 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2021-11-09 17:33 UTC (permalink / raw)
  To: gdb-patches

Compiling GDB with current GCC (1b4a63593b) runs into this:

  src/gdb/location.c: In function ‘int event_location_empty_p(const event_location*)’:
  src/gdb/location.c:963:38: error: the address of ‘event_location::<unnamed union>::explicit_loc’ will never be NULL [-Werror=address]
    963 |       return (EL_EXPLICIT (location) == NULL
	|                                      ^
  src/gdb/location.c:57:30: note: ‘event_location::<unnamed union>::explicit_loc’ declared here
     57 |     struct explicit_location explicit_loc;
	|                              ^~~~~~~~~~~~

GCC is right, EL_EXPLICIT is defined as returning the address of an
union field:

      /* An explicit location.  */
      struct explicit_location explicit_loc;
  #define EL_EXPLICIT(P) (&((P)->u.explicit_loc))

and thus must always be non-NULL.

Change-Id: Ie74fee7834495a93affcefce03c06e4d83ad8191
---
 gdb/location.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/gdb/location.c b/gdb/location.c
index 827294e106a..1ee20069313 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -960,12 +960,11 @@ event_location_empty_p (const struct event_location *location)
       return 0;
 
     case EXPLICIT_LOCATION:
-      return (EL_EXPLICIT (location) == NULL
-	      || (EL_EXPLICIT (location)->source_filename == NULL
-		  && EL_EXPLICIT (location)->function_name == NULL
-		  && EL_EXPLICIT (location)->label_name == NULL
-		  && (EL_EXPLICIT (location)->line_offset.sign
-		      == LINE_OFFSET_UNKNOWN)));
+      return (EL_EXPLICIT (location)->source_filename == NULL
+	      && EL_EXPLICIT (location)->function_name == NULL
+	      && EL_EXPLICIT (location)->label_name == NULL
+	      && (EL_EXPLICIT (location)->line_offset.sign
+		  == LINE_OFFSET_UNKNOWN));
 
     case PROBE_LOCATION:
       return EL_PROBE (location) == NULL;

base-commit: f0bbba7886f5dba158a143bebbd0691591f22b9f
-- 
2.26.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix build with current GCC: EL_EXPLICIT(location) always non-NULL
  2021-11-09 17:33 [PATCH] Fix build with current GCC: EL_EXPLICIT(location) always non-NULL Pedro Alves
@ 2021-11-09 18:19 ` Simon Marchi
  2021-11-15  0:21   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2021-11-09 18:19 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On 2021-11-09 12:33 p.m., Pedro Alves wrote:
> Compiling GDB with current GCC (1b4a63593b) runs into this:
>
>   src/gdb/location.c: In function ‘int event_location_empty_p(const event_location*)’:
>   src/gdb/location.c:963:38: error: the address of ‘event_location::<unnamed union>::explicit_loc’ will never be NULL [-Werror=address]
>     963 |       return (EL_EXPLICIT (location) == NULL
> 	|                                      ^
>   src/gdb/location.c:57:30: note: ‘event_location::<unnamed union>::explicit_loc’ declared here
>      57 |     struct explicit_location explicit_loc;
> 	|                              ^~~~~~~~~~~~
>
> GCC is right, EL_EXPLICIT is defined as returning the address of an
> union field:
>
>       /* An explicit location.  */
>       struct explicit_location explicit_loc;
>   #define EL_EXPLICIT(P) (&((P)->u.explicit_loc))
>
> and thus must always be non-NULL.

Looks good (and relatively obvious) to me.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix build with current GCC: EL_EXPLICIT(location) always non-NULL
  2021-11-09 18:19 ` Simon Marchi
@ 2021-11-15  0:21   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2021-11-15  0:21 UTC (permalink / raw)
  To: Simon Marchi, Pedro Alves, gdb-patches



On 2021-11-09 13:19, Simon Marchi wrote:
> On 2021-11-09 12:33 p.m., Pedro Alves wrote:
>> Compiling GDB with current GCC (1b4a63593b) runs into this:
>>
>>   src/gdb/location.c: In function ‘int event_location_empty_p(const event_location*)’:
>>   src/gdb/location.c:963:38: error: the address of ‘event_location::<unnamed union>::explicit_loc’ will never be NULL [-Werror=address]
>>     963 |       return (EL_EXPLICIT (location) == NULL
>> 	|                                      ^
>>   src/gdb/location.c:57:30: note: ‘event_location::<unnamed union>::explicit_loc’ declared here
>>      57 |     struct explicit_location explicit_loc;
>> 	|                              ^~~~~~~~~~~~
>>
>> GCC is right, EL_EXPLICIT is defined as returning the address of an
>> union field:
>>
>>       /* An explicit location.  */
>>       struct explicit_location explicit_loc;
>>   #define EL_EXPLICIT(P) (&((P)->u.explicit_loc))
>>
>> and thus must always be non-NULL.
> 
> Looks good (and relatively obvious) to me.
> 
> Simon
> 

I pushed your patch, since somebody stumbled on the same problem and sent
a separate patch with the same fix.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-15  0:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 17:33 [PATCH] Fix build with current GCC: EL_EXPLICIT(location) always non-NULL Pedro Alves
2021-11-09 18:19 ` Simon Marchi
2021-11-15  0:21   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).