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 compilation error on gcc 9.1 #441

Merged
merged 1 commit into from
Apr 20, 2020
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
6 changes: 4 additions & 2 deletions lib/mayaUsd/render/vp2RenderDelegate/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ namespace {
}

if (channelOffset == 0 && sizeof(DEST_TYPE) == sizeof(SRC_TYPE)) {
memcpy(vertexBuffer, primvarData.cdata(), sizeof(DEST_TYPE) * numVertices);
const void* source = static_cast<const void*>(primvarData.cdata());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this fix. Isn't the compiler error telling us that sizeof test somehow failed and we are using memcpy for not matching types?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. gcc 9.1 is only complaining about the type mismatch between source and destination of memcpy op. The memcpy function won't called if their types don't match, but this is run-time behavior that won't be taken into account at compile time.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something here and we would need to have a bit more information about which actual invocation of _FillPrimvarData is generating this error.

FWIW. There is one possibility where we will have a destination as Vec4f and source as Vec3f when filling color with alpha buffer. In this case, we should never enter the memcpy section...and the error should never be generated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed the invocation is from where the source is Vec3f and the destination is Vec4f. And we indeed don't enter the memcpy section at run time. But the compiler won't examine run-time code path at compile time, that is why it still generate the error.

The fix has been validated on gcc 9.1.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One detail, sizeof is a constant expression, the compiler should know that it doesn't enter this condition. Maybe it's a bug in the compiler and this is why we never saw it before.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess even if we had this memcpy call inside a if(false) clause the compiler would still generate this error. More because of compiler strictness, I am not sure if it is a bug.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at C++17 and what if const expression can do...you may be right that compiler won't help us here because of value dependency.

OK, you convinced me. Thx.

memcpy(vertexBuffer, source, sizeof(DEST_TYPE) * numVertices);
}
else {
for (size_t v = 0; v < numVertices; v++) {
Expand Down Expand Up @@ -244,7 +245,8 @@ namespace {
}

if (channelOffset == 0 && sizeof(DEST_TYPE) == sizeof(SRC_TYPE)) {
memcpy(vertexBuffer, primvarData.cdata(), sizeof(DEST_TYPE) * numVertices);
const void* source = static_cast<const void*>(primvarData.cdata());
memcpy(vertexBuffer, source, sizeof(DEST_TYPE) * numVertices);
}
else {
for (size_t v = 0; v < numVertices; v++) {
Expand Down