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

Conversation

huidong-chen
Copy link

This commit is to fix the following compilation error with gcc 9.1:

‘void* memcpy(void*, const void*, size_t)’ copying an object
of type ‘class pxrInternal_v0_20__pxrReserved__::GfVec4f’ with
‘private’ member ‘pxrInternal_v0_20__pxrReserved__::GfVec4f::data’
from an array of ‘const class pxrInternal_v0_20__pxrReserved
_::GfVec3f’;
use assignment or copy-initialization instead [-Werror=class-memaccess]

error: ‘void* memcpy(void*, const void*, size_t)’ copying an object
of type ‘class pxrInternal_v0_20__pxrReserved__::GfVec4f’ with
‘private’ member ‘pxrInternal_v0_20__pxrReserved__::GfVec4f::_data’
from an array of ‘const class pxrInternal_v0_20__pxrReserved__::GfVec3f’;
use assignment or copy-initialization instead [-Werror=class-memaccess]
@huidong-chen huidong-chen added do-not-merge-yet Development is not finished, PR not ready for merge vp2renderdelegate Related to VP2RenderDelegate labels Apr 18, 2020
@@ -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.

@huidong-chen huidong-chen removed the do-not-merge-yet Development is not finished, PR not ready for merge label Apr 20, 2020
@kxl-adsk kxl-adsk merged commit 802de0c into dev Apr 20, 2020
@kxl-adsk kxl-adsk deleted the chenh/MAYA-104366/compilation-error-on-gcc-9-1 branch April 20, 2020 18:34
ppt-adsk pushed a commit that referenced this pull request Sep 27, 2023
* HYDRA 411 - create Cpp test infrastructure and documentation

* HYDRA 411 - remove unnecessary code changes

* HYDRA 411 - fix linux and mac issue with dynamically loading plugin by modifying rpath

* HYDRA 411 - removed unused imports, fixed readme

* HYDRA 411-remove cppFramework directory

* HYDRA 411 - remove unused variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vp2renderdelegate Related to VP2RenderDelegate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants