[Bug c++/64270] New: packed fields

damien.ruscoe at imgtec dot com gcc-bugzilla@gcc.gnu.org
Thu Dec 11 14:11:00 GMT 2014


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64270

            Bug ID: 64270
           Summary: packed fields
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: damien.ruscoe at imgtec dot com

Testcase attached.

Passing an array field from a packed struct into a function as a reference
appears to copy the array.
If the function accesses the address of the array (or any of its elements) it
will get the address of the temporary created in the scope of that function.
Using that address after the return of the function leads to bad stuff
happening :/


Testing has been done on many versions of gcc


$ g++ --version && g++ packed_stuct_access.cpp && ./a.out
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46)
0xbfd28c4c
0xbfd28c54
a.out: packed_stuct_access.cpp:8: void ASSERT_EQUALS(const T&, const T&) [with
T = const uint32_t*]: Assertion `expected == value' failed.
Aborted

$ g++ --version && g++ packed_stuct_access.cpp && ./a.out
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54)
0xbfeb608c
0xbfeb6094
a.out: packed_stuct_access.cpp:8: void ASSERT_EQUALS(const T&, const T&) [with
T = const uint32_t*]: Assertion `expected == value' failed.
Aborted

$ g++ --version && g++ packed_stuct_access.cpp && ./a.out
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55)
0xbf93351c
0xbf933524
a.out: packed_stuct_access.cpp:8: void ASSERT_EQUALS(const T&, const T&) [with
T = const uint32_t*]: Assertion `expected == value' failed.
Aborted

$ g++ --version && g++ packed_stuct_access.cpp && ./a.out
g++ (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3)
0x7fff5992e0d0
0x7fff5992e0e0
a.out: packed_stuct_access.cpp:8: void ASSERT_EQUALS(const T&, const T&) [with
T = const uint32_t*]: Assertion `expected == value' failed.
Aborted (core dumped)

$ g++ --version && g++ packed_stuct_access.cpp && ./a.out
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)
0x7fff31acda70
0x7fff31acda80
a.out: packed_stuct_access.cpp:8: void ASSERT_EQUALS(const T&, const T&) [with
T = const uint32_t*]: Assertion `expected == value' failed.
Aborted (core dumped)

$ g++ --version && g++ packed_stuct_access.cpp && ./a.out
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
0x7fff3641dee0
0x7fff3641def0
a.out: packed_stuct_access.cpp:8: void ASSERT_EQUALS(const T&, const T&) [with
T = const uint32_t*]: Assertion `expected == value' failed.
Aborted (core dumped)

$ g++ --version && g++ packed_stuct_access.cpp && ./a.out
g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
0x7fff3456f260
0x7fff3456f250
a.out: packed_stuct_access.cpp:8: void ASSERT_EQUALS(const T&, const T&) [with
T = const unsigned int*]: Assertion `expected == value' failed.
Aborted (core dumped)



More information about the Gcc-bugs mailing list