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

Strict Aliasing Problem #152

Closed
BryceMehring opened this issue Jan 5, 2014 · 10 comments
Closed

Strict Aliasing Problem #152

BryceMehring opened this issue Jan 5, 2014 · 10 comments
Assignees
Labels
Milestone

Comments

@BryceMehring
Copy link

Using the -O2 flag for g++ 4.8.1 with glm, I get aliasing warnings everywhere:

warning: dereferencing type-punned pointer will break strict-aliasing rules

Edit: I'm also using the -Wall flag

@Groovounet
Copy link
Member

Can you point me to the code that generate that warning?

@BryceMehring
Copy link
Author

Including either glm/gtx/transform.hpp or glm/geometric.hpp will cause the warnings. There might be more.

@ghost
Copy link

ghost commented Jan 12, 2014

I also get a lot of those in Android NDK 9c (only in release build).

An example from 0.9.5.1 release:

In file included from   glm/detail/func_exponential.hpp:127:0,
                 from   glm/exponential.hpp:32,
                 from   glm/glm.hpp:109,
  glm/detail/func_exponential.inl: In instantiation of 'static vecType<float, (glm::precision)2u> glm::detail::compute_inversesqrt<vecType, float, (glm::precision)2u>::call(const vecType<float, (glm::precision)2u>&) [with vecType = glm::detail::tvec1]':
  glm/gtx/fast_square_root.inl:29:67:   required from here
  glm/detail/func_exponential.inl:176:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     tmp = *reinterpret_cast<vecType<float, lowp>*>(&i);
         ^

However, it occurs in tons of places.

@Groovounet
Copy link
Member

So I am not 100% sure I fixed the issue but at least a apply a tentative fix to resolve it.

This fix is available in GLM 0.9.5 branch of the repository.

Thanks for contributing,
Christophe

@bagage
Copy link

bagage commented Mar 11, 2014

The issue still occurs with the Android NDK, using glm branch 0.9.5 at func_integer.inl:234/175:

lsb = reinterpret_cast<int32&>(Value64);

Full warning:

In file included from libs/glm/glm/detail/func_integer.hpp:200:0,
                 from libs/glm/glm/integer.hpp:32,
                 from libs/glm/glm/glm.hpp:115,
libs/glm/glm/detail/func_integer.inl: In function 'void glm::umulExtended(const genUType&, const genUType&, genUType&, genUType&) [with genUType = unsigned int]':
libs/glm/glm/detail/func_integer.inl:175:42: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
libs/glm/glm/detail/func_integer.inl: In function 'void glm::imulExtended(const genIType&, const genIType&, genIType&, genIType&) [with genIType = int]':
libs/glm/glm/detail/func_integer.inl:234:41: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

@Groovounet
Copy link
Member

If that was the only two issues left I think this time the problem should be fixed.

This changes will be part of GLM 0.9.5.3.

Thanks for contributing,
Christophe

@Groovounet Groovounet added the bug label Mar 16, 2014
@Groovounet Groovounet added this to the GLM 0.9.5 milestone Mar 16, 2014
@bagage
Copy link

bagage commented Mar 16, 2014

I guess you fixed the wrong line. The faulty one was the line below it:
lsb = reinterpret_cast<int32&>(Value64);

@klemmster
Copy link

@Groovounet
We've encountered a similar issue in libavg.
I've added a fix(libavg/libavg@a894a9f) to our local glm copy for now, motivated by these two sources:

and a bit of research it seems to be the appropriate way.

If you would like to integrate this solution, just let me know which branch I should open a PR against.

@Groovounet Groovounet reopened this Jun 6, 2014
@Groovounet
Copy link
Member

I'll read this before coming to a conclusion.

I am not convinced that the aliasing here in GLM is really an issue because it's aliasing from a temporary variable created in the function generating that aliasing. Aliasing of the arguments is an issue that should be fixed in GLM 0.9.5.

Groovounet pushed a commit that referenced this issue Jun 21, 2014
@Groovounet
Copy link
Member

This issue should be fixed in GLM 0.9.5 branch for GLM 0.9.5.4 release.

Thanks,
Christophe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants