Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Class-memaccess" compilation error in test [C++, gcc 10.1.0, Flatbuffers 1.12.0/master] #5930

Closed
bakinovsky-m opened this issue May 26, 2020 · 10 comments · Fixed by #5938
Closed

Comments

@bakinovsky-m
Copy link
Contributor

Compilation is failing on tests when using gcc 10.1.0.

flatbuffers/tests/arrays_test_generated.h: In constructor ‘MyGame::Example::ArrayStruct::ArrayStruct(float, int8_t, int32_t)’:
flatbuffers/tests/arrays_test_generated.h:156:34: error: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘struct MyGame::Example::NestedStruct’; use assignment or value-initialization instead [-Werror=class-memaccess]
  156 |     std::memset(d_, 0, sizeof(d_));
      |                                  ^
flatbuffers/tests/arrays_test_generated.h:66:40: note: ‘struct MyGame::Example::NestedStruct’ declared here
   66 | FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) NestedStruct FLATBUFFERS_FINAL_CLASS {
      |                                        ^~~~~~~~~~~~

Master branch and v1.12.0 tag are affected, didn't test other tags

Setup

  • gcc 10.1.0
  • flatbuffers 1.12.0 or master

Reproducing

  • cd to flatbuffers folders
  • run:
$ mkdir build && cd build
$ cmake .. #FLATBUFFERS_BUILD_TESTS is enabled by default
$ cmake --build .
@aardappel
Copy link
Collaborator

Yes, the default constructor really shouldn't use memset, we could instead generate a constructor similar to the one with arguments, but with 0 for each field value.

Care to make a PR for this?

@bakinovsky-m
Copy link
Contributor Author

As I understand, the problem is in constructor with parameters (not in default constructor, as it's already have static_cast<void*>(...) fix)
It appears when std::memset applies to NestedStruct array

I have some thoughts of how to fix this, so yeah, i will make the PR

@Qengineering
Copy link

I've exactly the same error with TensorFlow 2.4.0 tag on Ubuntu 20.10 and gcc 10.2.0.

Oddly, there is no problem with TF 2.4.0 on Ubuntu 20.04 + gcc 9.3.0, nor on Ubuntu 18.04 + gcc 7.5.0.
Both compile the flatbuffers flawlessly, while Ub20.10 + gcc 10.2.0 throws the above class-memaccess errors

@aardappel
Copy link
Collaborator

@Qengineering as you can see, it has been fixed.. so you'd need to get TensorFlow to update their copy of FlatBuffers.

As a local work-around, turn of -Werror for the files involved.

@Qengineering
Copy link

It's fixed was also what I thought after reading the comments above. Never had any problem before with the FlatBuffers.

I followed your steps, and downloaded version TF 2.4.0 again, hoping, against better, it will solve the issue.

$ wget -O tensorflow.zip https://github.com/tensorflow/tensorflow/archive/v2.4.0.zip
$ unzip tensorflow.zip
$ mv tensorflow-2.4.0 tensorflow
$ cd tensorflow
$ ./tensorflow/lite/tools/make/download_dependencies.sh
$ cd ~/tensorflow/tensorflow/lite/tools/make/downloads/flatbuffers
$ mkdir build
$ cd build
$ cmake ..
$ make -j4

Screenshot from 2021-01-05 10-59-26

Turning -Werror of is something I'd rather not do. After all, why issue an error if it has no bearing on functionality?
Using Ubuntu 20.10 with gcc 10.2.0. on a Raspberry Pi 4 with 2 GByte RAM. I'm just reporting the issue, so you know.

@vglavnyy
Copy link
Contributor

vglavnyy commented Jan 5, 2021

Probably this issue connected with #6337.
@aardappel
Maybe it's better to disable Werror by default and enable this flag only with CI?
Another option is to add overriding flags using an environment variable for example (FLATBUFFERS_CMAKE_CXX_FLAGS).

@aardappel
Copy link
Collaborator

@vglavnyy yeah, that be a good idea. I like -Werror, but it keeps producing problems when compilers introduce new warnings, and we can't test them all. It shouldn't stop people from building.

And generally allowing people their own control over compiler flags is good.

vglavnyy added a commit to vglavnyy/flatbuffers that referenced this issue Jan 29, 2021
This commit adds FLATBUFFERS_CXX_FLAGS cmake option.
This option allows override the -Werror flag (or any other flags).
Related issues:  google#6337, google#5930
aardappel pushed a commit that referenced this issue Feb 10, 2021
* [Build, cmake] Add -Werror override option

This commit adds FLATBUFFERS_CXX_FLAGS cmake option.
This option allows override the -Werror flag (or any other flags).
Related issues:  #6337, #5930

* Remove CMAKE_CXX_FLAGS replace option
@baqwas
Copy link

baqwas commented Dec 9, 2021

Hello,
I was following the tutorial by @Qengineering and ran into the exact problem that he commented on Jan 5. This issue is far above my job grade. I need to use RPi02 with Bullseye. My system is:

`
$ uname -a

Linux hostname 5.10.63-v7+ #1488 SMP Thu Nov 18 16:14:44 GMT 2021 armv7l GNU/Linux
`

Basic processor info:
`
processor : 3
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4

Hardware : BCM2835
Revision : 902120
Model : Raspberry Pi Zero 2 Rev 1.0
`

cmake does not report any error. Unfortunately, make reports the following error that suspends all subsequent install and ldconfig operations:

/home/pi/projects/tensorflow/tensorflow/lite/tools/make/downloads/flatbuffers/tests/arrays_test_generated.h:156:34: error: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘struct MyGame::Example::NestedStruct’; use assignment or value-initialization instead [-Werror=class-memaccess] 156 | std::memset(d_, 0, sizeof(d_));

Would appreciate indulgence for a newbie question from anyone who has a basic workaround. Thanks.

Kind regards.

@aardappel
Copy link
Collaborator

@baqwas again, this has been fixed in FlatBuffers, so ask about it on the tf/tflite repo.. they need to upgrade. Or force disable -Werror.

@baqwas
Copy link

baqwas commented Dec 9, 2021

Thanks @aardappel for the prompt response. Will do as advised. Truly appreciate your indulgence.

Kind regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants