freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft-devel] strict aliasing


From: Werner LEMBERG
Subject: Re: [ft-devel] strict aliasing
Date: Sun, 15 Nov 2015 06:29:50 +0100 (CET)

>> Soo...  Do you get crashes in FreeType?
> 
> I don’t believe that we do get crashes in Freetype.

Good to know :-)

> Something like:
>       AFunc(const DB *db, const void **result) {
>               const DirectoryEntry *dir = NULL;
>               GetDirectoryEntry(db, (const void**)(&dir));
>               GetData(db, dir->offset, dir->size, result);
>       }
> 
> It appears that the compiler does not seem to recognize that
> GetDirectoryEntry() changes the value of dir,

This is exactly the kind of code that you have to take care of by
yourself if strict aliasing optimizations are done by the compiler –
you must be *sure* that the cast to `const void**' is valid, since
doing so bypasses the safety checks of the compiler.

> perhaps because it makes a copy of it before taking the address?

AFAIK yes, since this copy is the compiler's `safety check'.

> Have you reported this to the gcc team?

AFAIK, there is no bug – am I missing something?

>> My preferred solution would be to use something similar to the fix
>> in issue #27441, given that unions is not the right way to go for
>> C++, according to advice I've seen in the internet – and I want to
>> preserve the ability that a C++ compiler can compile FreeType.
> 
> It wasn’t clear what the solution was for 27441 - it seemed like it
> was cast to a different data type that has less gnarly accessors?

Something like this, yes.  Toshiya-san, can you give more information?

> It is understandable that you would want to use {sub,super}classing
> rather than casting in C++.  Perhaps the best solution is a
> SuperClassMacro(x) that reverts to (x)in C++ and ((union
> TheUltimateUnionr*)(x))->theSuperClass in the C case (except you
> need to do more testing).

Mhmm, my gut feeling says that we can manage this issue without using
a union.

> I am not authorized to directly contribute. However, I might be able
> to do some testing.

Thanks for the offer.  Please open a bug tracker issue, probably with
a link to this discussion thread, so that the issue won't be
forgotten.


   Werner

reply via email to

[Prev in Thread] Current Thread [Next in Thread]