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

Fix aliasing issue in framework #300

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading