Skip to content

Commit

Permalink
Merge pull request #300 from Lamakaio/aliasing_fix
Browse files Browse the repository at this point in the history
Fix aliasing issue in framework
  • Loading branch information
Capital-Asterisk authored Oct 4, 2024
2 parents 1069fc0 + 5b555aa commit b67b90b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/osp/framework/framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "../core/keyed_vector.h"
#include "../tasks/tasks.h"

#include <cstring>
#include <entt/core/any.hpp>

#include <Corrade/Containers/ArrayViewStl.h>
Expand Down Expand Up @@ -336,13 +337,17 @@ struct Framework
// Access struct members of out.pl and out.di as if they're arrays, in order to write
// DataIds and PipelineIds to them.

//Using this reference to avoid strict aliasing UB : https://gist.github.com/shafik/848ae25ee209f698763cffee272a58f8
//Apparently the memcpy calls get optimized away.

FeatureInterface const &rInterface = m_fiinstData[fiId];

if constexpr ( ! std::is_empty_v<typename FI_T::Pipelines> )
{
auto const plMembers = arrayCast<PipelineDefBlank_t>( arrayCast<std::byte>( arrayView(&out.pl, 1) ) );
for (std::size_t i = 0; i < plMembers.size(); ++i)
{
plMembers[i].m_value = rInterface.pipelines[i];
std::memcpy(&plMembers[i].m_value, &rInterface.pipelines[i], sizeof(PipelineId));
}
}

Expand All @@ -351,7 +356,7 @@ struct Framework
auto const diMembers = arrayCast<DataId>( arrayCast<std::byte>( arrayView(&out.di, 1) ) );
for (std::size_t i = 0; i < diMembers.size(); ++i)
{
diMembers[i] = rInterface.data[i];
std::memcpy(&diMembers[i], &rInterface.data[i], sizeof(DataId));
}
}
}
Expand Down

0 comments on commit b67b90b

Please sign in to comment.