Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6383)

Issue 5515047: use memcpy to fix strict-aliasing warning (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 4 months ago by reed1
Modified:
12 years, 3 months ago
CC:
tony
Base URL:
http://skia.googlecode.com/svn/trunk/
Visibility:
Public.

Patch Set 1 #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+5 lines, -1 line) Patch
M include/core/SkDescriptor.h View 1 chunk +5 lines, -1 line 3 comments Download

Messages

Total messages: 13
reed1
I was unable to capture this in an inline function and still suppress the warning ...
12 years, 4 months ago (2012-01-05 17:03:07 UTC) #1
caryclark1
http://codereview.appspot.com/5515047/diff/1/include/core/SkDescriptor.h File include/core/SkDescriptor.h (right): http://codereview.appspot.com/5515047/diff/1/include/core/SkDescriptor.h#newcode161 include/core/SkDescriptor.h:161: memcpy(&fDesc, &fStorage[0], sizeof(fDesc)); What about a macro? #define SK_STRICT_ASSIGN(dest, ...
12 years, 4 months ago (2012-01-05 18:15:26 UTC) #2
TomH
Tangent: other sources of strict-aliasing breakage are: src/animator/SkAnimatorScript.cpp src/animator/SkDisplayNumber.cpp bench/MathBench.cpp
12 years, 4 months ago (2012-01-05 19:39:13 UTC) #3
TomH
On 2012/01/05 17:03:07, reed1 wrote: > I was unable to capture this in an inline ...
12 years, 4 months ago (2012-01-05 20:13:57 UTC) #4
TomH
Performance tests of strict-aliasing vs no-strict-aliasing are confusing. For example, the verts benchmark runs 25-30% ...
12 years, 4 months ago (2012-01-06 18:17:09 UTC) #5
joth
http://codereview.appspot.com/5515047/diff/1/include/core/SkDescriptor.h File include/core/SkDescriptor.h (right): http://codereview.appspot.com/5515047/diff/1/include/core/SkDescriptor.h#newcode162 include/core/SkDescriptor.h:162: #endif another one to try (at least for comparison) ...
12 years, 3 months ago (2012-01-12 20:46:19 UTC) #6
jbates
http://codereview.appspot.com/5515047/diff/1/include/core/SkDescriptor.h File include/core/SkDescriptor.h (right): http://codereview.appspot.com/5515047/diff/1/include/core/SkDescriptor.h#newcode159 include/core/SkDescriptor.h:159: fDesc = (SkDescriptor*)fStorage; If you change fStorage to a ...
12 years, 3 months ago (2012-01-12 21:28:37 UTC) #7
reed1
if true, that's wacky, since uint32_t is closing to ensuring proper alignement for SkDescriptor than ...
12 years, 3 months ago (2012-01-12 21:32:27 UTC) #8
jbates
On 2012/01/12 21:32:27, reed1 wrote: > if true, that's wacky, since uint32_t is closing to ...
12 years, 3 months ago (2012-01-12 21:36:36 UTC) #9
jbates
On 2012/01/12 21:36:36, jbates wrote: > On 2012/01/12 21:32:27, reed1 wrote: > > if true, ...
12 years, 3 months ago (2012-01-12 21:39:37 UTC) #10
bsalomon
On 2012/01/12 21:39:37, jbates wrote: > On 2012/01/12 21:36:36, jbates wrote: > > On 2012/01/12 ...
12 years, 3 months ago (2012-01-12 21:45:06 UTC) #11
jbates
On 2012/01/12 21:45:06, bsalomon wrote: > On 2012/01/12 21:39:37, jbates wrote: > > On 2012/01/12 ...
12 years, 3 months ago (2012-01-12 21:53:25 UTC) #12
jbates
12 years, 3 months ago (2012-01-12 23:24:52 UTC) #13
On 2012/01/12 21:53:25, jbates wrote:
> On 2012/01/12 21:45:06, bsalomon wrote:
> > On 2012/01/12 21:39:37, jbates wrote:
> > > On 2012/01/12 21:36:36, jbates wrote:
> > > > On 2012/01/12 21:32:27, reed1 wrote:
> > > > > if true, that's wacky, since uint32_t is closing to ensuring proper
> > > alignement
> > > > > for SkDescriptor than uint8_t.
> > > > 
> > > > Good point -- you would also need to specify the alignment of the array
> with
> > > > __attribute__((__aligned__(alignof(SkDescriptor)))) for GCC and whatever
> the
> > > > MSVC variant is.
> > > 
> > > Although, since the array follows a pointer (fDesc), it's already going to
> be
> > > aligned at least 4 bytes (8 bytes for the 64-bit build). But without the
> > > alignment attribute, you might get warnings when it's casted to
SkDescriptor
> > > about differing alignment.
> > 
> > According to this article it is safe to cast _to_ a char* but not _from_ a
> > char*:
> >
>
http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-ali...
> 
> If you don't know the history of the char pointer you are casting from, then
it
> is dangerous. But in this case, the aliasing of SkDescriptor is one of two
> cases: as a char* or as a SkDescriptor*. It looks like the example shown in
Mike
> Acton's article is showing that you can't alias a uint32 as uint16 and expect
it
> to be safe by casting through a char*.

In any case, since this code never actually accesses the fStorage array
directly, there's no actual danger here even if the type is left as uint32. I
would go with joth's idea of placement new and see if the compiler warning goes
away.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b