[Bug c/41809] escaping address of packed field should trigger warning

2020-05-19 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41809

Martin Sebor  changed:

   What|Removed |Added

  Known to work||10.1.0, 9.2.0
 Resolution|--- |FIXED
 Status|NEW |RESOLVED
   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=68160

--- Comment #8 from Martin Sebor  ---
Let me resolve the attribute subset of the problem as fixed.  The outstanding 
#pragma pack subset is the subject of pr68160.

[Bug c/41809] escaping address of packed field should trigger warning

2020-05-19 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41809

Martin Sebor  changed:

   What|Removed |Added

 CC||msebor at gcc dot gnu.org

--- Comment #7 from Martin Sebor  ---
Starting with version 9 GCC diagnoses both calls in the test case in comment #0
(the test case with #pragma pack in comment #3 is not diagnosed):

$ cat pr41809.c && gcc -O2 -S -Wall pr41809.c
void f(int *);

struct s {
int x;
char c;
} __attribute__((__packed__));

struct s A[10];

int main(void)
{
for (int i = 0; i != sizeof(A)/sizeof(A[0]); ++i) {
f([i].x);
f((int*)(char*)[i].x);
}
}
pr41809.c: In function ‘main’:
pr41809.c:13:11: warning: taking address of packed member of ‘struct s’ may
result in an unaligned pointer value [-Waddress-of-packed-member]
   13 | f([i].x);
  |   ^~~
pr41809.c:14:11: warning: taking address of packed member of ‘struct s’ may
result in an unaligned pointer value [-Waddress-of-packed-member]
   14 | f((int*)(char*)[i].x);
  |   ^~~~

[Bug c/41809] escaping address of packed field should trigger warning

2017-03-24 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41809

Martin Sebor  changed:

   What|Removed |Added

 CC||rguenth at gcc dot gnu.org

--- Comment #6 from Martin Sebor  ---
*** Bug 54032 has been marked as a duplicate of this bug. ***

[Bug c/41809] escaping address of packed field should trigger warning

2017-03-24 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41809

Martin Sebor  changed:

   What|Removed |Added

 CC||meisenmann.lba@fh-salzburg.
   ||ac.at

--- Comment #5 from Martin Sebor  ---
*** Bug 79918 has been marked as a duplicate of this bug. ***

[Bug c/41809] escaping address of packed field should trigger warning

2012-10-18 Thread tetra2005 at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41809



--- Comment #3 from Yuri Gribov tetra2005 at gmail dot com 2012-10-18 
11:38:45 UTC ---

Created attachment 28481

  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=28481

Another testcase



Testcase which demonstrates more issues.


[Bug c/41809] escaping address of packed field should trigger warning

2012-10-18 Thread tetra2005 at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41809



Yuri Gribov tetra2005 at gmail dot com changed:



   What|Removed |Added



 CC||tetra2005 at gmail dot com



--- Comment #4 from Yuri Gribov tetra2005 at gmail dot com 2012-10-18 
11:41:10 UTC ---

Gcc does warn (actually it even errs) if you try to pass unaligned variable by

reference but does not do this when you use pointers:

  $ g++ -Wall -c pack_warns.cpp

  pack_warns.cpp:22:9: error: cannot bind packed field 't-Test::x' to 'float'



Also it'll fail to warn if you use #pragma pack instead of

__attribute__((packed)):

  $ g++ -Wall -c -DUSE_PRAGMA pack_warns.cpp   # Compiles wo warnings



Just wanted to mention that users frequently run into errors with unaligned

data (especially on targets where it really matters e.g. on ARM) so this might

be important issue.


[Bug c/41809] escaping address of packed field should trigger warning

2012-02-01 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41809

Andrew Pinski pinskia at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2012-02-01
 Ever Confirmed|0   |1

--- Comment #2 from Andrew Pinski pinskia at gcc dot gnu.org 2012-02-01 
23:28:03 UTC ---
Confirmed.