GameDevTecnico / cubos

A still very barebones game engine focused on voxels and data-oriented programming
https://cubosengine.org
MIT License
83 stars 34 forks source link

-O3 flag causes Compiler Error on ECS QueryFilter #1351

Open SrGesus opened 3 hours ago

SrGesus commented 3 hours ago

Description

Sometimes the compiler doesn't seem to be able to infer that a QueryFilter's mNodeCount is lesser or equal than MaxCursorCount, this results in a compiler warning, and therefore a compiler error.

Reproduce

Steps to reproduce the behavior:

  1. Clone the repo
  2. cmake -S. -Bbuild -D CMAKE_CXX_COMPILER=c++
  3. cmake --build build -j 12

Expected behaviour

No compiler error.

Screenshots

[ 26%] Building CXX object core/CMakeFiles/cubos-core.dir/src/ecs/query/filter.cpp.o
cd /home/user/Documents/gamedev/cubos/build/core && /usr/bin/c++ -DCPPTRACE_DEMANGLE_WITH_CXXABI -DCPPTRACE_GET_SYMBOLS_WITH_LIBDWARF -DCPPTRACE_HAS_CXX_EXCEPTION_TYPE -DCPPTRACE_HAS_DL_FIND_OBJECT -DCPPTRACE_STATIC_DEFINE -DCPPTRACE_UNWIND_WITH_UNWIND -DCUBOS_CORE_ECS_MAX_COMPONENTS=63 -DCUBOS_CORE_EXPORT -DCUBOS_CORE_IMPORT -DCUBOS_METRIC_MAX_ENTRIES=1024 -DCUBOS_PROFILING=ON -DGLAD_GLAPI_EXPORT -DGLAD_GLAPI_EXPORT_BUILD -DGLM_FORCE_SILENT_WARNINGS -DWITH_GLFW -DWITH_OPENGL -Dcubos_core_EXPORTS -I/home/user/Documents/gamedev/cubos/core/include -I/home/user/Documents/gamedev/cubos/core/lib/glad/include -I/home/user/Documents/gamedev/cubos/core/lib/glfw/include -I/home/user/Documents/gamedev/cubos/core/lib/stduuid/include -I/home/user/Documents/gamedev/cubos/core/lib/stduuid -I/home/user/Documents/gamedev/cubos/core/lib/json/include -isystem /home/user/Documents/gamedev/cubos/core/lib/cpptrace/include -isystem /home/user/Documents/gamedev/cubos/build/core/lib/cpptrace/include -isystem /home/user/Documents/gamedev/cubos/core/lib/miniaudio -isystem /home/user/Documents/gamedev/cubos/core/lib/glm/glm/.. -O3 -DNDEBUG -std=gnu++20 -fPIC -Wall -Wextra -pedantic -Wconversion -Werror -Wno-attributes -Wno-maybe-uninitialized -MD -MT core/CMakeFiles/cubos-core.dir/src/ecs/query/filter.cpp.o -MF CMakeFiles/cubos-core.dir/src/ecs/query/filter.cpp.o.d -o CMakeFiles/cubos-core.dir/src/ecs/query/filter.cpp.o -c /home/user/Documents/gamedev/cubos/core/src/ecs/query/filter.cpp
/home/user/Documents/gamedev/cubos/core/src/ecs/query/filter.cpp: In member function ‘void cubos::core::ecs::QueryFilter::update()’:
/home/user/Documents/gamedev/cubos/core/src/ecs/query/filter.cpp:139:22: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
  139 |         mNodePins[i] = mNodePins[i - 1] | mNodes[i - 1]->pins();
      |         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/user/Documents/gamedev/cubos/core/src/ecs/query/filter.cpp:3:
/home/user/Documents/gamedev/cubos/core/include/cubos/core/ecs/query/filter.hpp:66:31: note: at offset 8 into destination object ‘cubos::core::ecs::QueryFilter::mNodePins’ of size 8
   66 |         QueryNode::TargetMask mNodePins[QueryNode::MaxCursorCount];
      |                               ^~~~~~~~~
cc1plus: all warnings being treated as errors
SrGesus commented 3 hours ago

This is kind of weird, if i open the project in vscode it will prompt me to choose a compiler, and after choosing g++ it will compile without any error, but if i use the flag -D CMAKE_CXX_COMPILER=g++ it will not... c++ looks like a symbolic link to g++ so I don't know why this is happening.

SrGesus commented 3 hours ago

Hmm running in verbose and looking at the compilation commands, the difference seems to be that the one that errors has the -O3 -DNDEBUG flags image

SrGesus commented 2 hours ago

Weirdly enough it seems like -O3 is the flag that is causing this...

SrGesus commented 2 hours ago

Have tested and the same happens with Clang if -O3, I think it is not a compiler issue

SrGesus commented 2 hours ago

It's kind of bothersome that

CUBOS_ASSERT(mNodeCount <= QueryNode::MaxCursorCount);

Won't make the error go away