NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/59245: GCC silent data corruption due to "#pragma GCC diagnostic push/pop"



The following reply was made to PR bin/59245; it has been noted by GNATS.

From: RVP <rvp%SDF.ORG@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: bin/59245: GCC silent data corruption due to "#pragma GCC
 diagnostic push/pop"
Date: Wed, 2 Apr 2025 06:30:10 +0000 (UTC)

 On Tue, 1 Apr 2025, cryintothebluesky%gmail.com@localhost wrote:
 
 > I'm observing some weird corruption with GCC on sparc64 running
 > NetBSD-9.4 and evbarmv7hf-el running NetBSD-9.2.
 >
 
 Also on amd64 with the latest 10.1_STABLE running `gcc (nb3 20231008) 10.5.0',
 
 > The corruption seems to occur with the following pragmas:
 >
 > #pragma GCC diagnostic push
 > #pragma GCC diagnostic ignored "-Wcast-align"
 > ...
 >
 > #pragma GCC diagnostic pop
 >
 
 but, gcc-12.4.0 in -HEAD has no issues, so this was fixed somewhere bewtixt
 those two. So, not a NetBSD bug, I would say.
 
 In any case, work around this by applying the pragmas differently:
 
 a) whole functions (the usual way):
 
 ```
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wcast-align"
 
 static void fn(const void *data, size_t data_size)
 {
  	[...]
 }
 
 #pragma GCC diagnostic pop
 ```
 
 b) whole blocks (the other std. way):
 
 ```
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wcast-align"
 
 for (u64_ptr = data; [...]) {
  	[...]
 }
 
 #pragma GCC diagnostic pop
 ```
 
 c) heck, even this works:
 
 ```
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wcast-align"
 
 for (u64_ptr = data;
       u64_ptr < (const uint64_t *)((const uint8_t *)data + data_size);
       u64_ptr++)
 {
 #pragma GCC diagnostic pop
 
  	[...]
 }
 ```
 
 but, I think this last is a fluke (at least doesn't confuse GCC as much).
 
 -RVP
 


Home | Main Index | Thread Index | Old Index