<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - False positive with -Wcast-align for already-aligned struct member"
href="http://llvm.org/bugs/show_bug.cgi?id=16772">16772</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>False positive with -Wcast-align for already-aligned struct member
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>pgut001@cs.auckland.ac.nz
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>A common idiom for reserving storage within a struct is to have an array of
char (or unsighed char) that you then cast to whatever you want. Zero-length
arrays are an obvious example. Problem is that when compiled with
-Wcast-align, clang complains about an alignment issue even though the array is
preceded by an alignment-inducing struct member. For example given the
following:
<span class="quote">> cat > ./thing.c <<EOF</span >
typedef struct {
int thing1;
char thing2;
void *thing3;
} THING_STRUCT;
typedef struct {
void *nextThing;
char data[ 100 ];
} THING_STORAGE_STRUCT;
int main( void )
{
THING_STRUCT *thingPtr;
THING_STORAGE_STRUCT thingStorage;
thingPtr = ( THING_STRUCT * ) thingStorage.data;
return( 0 );
}
EOF
<span class="quote">> clang -Wcast-align thing.c</span >
I get:
thing.c:17:13: warning: cast from 'char *' to 'THING_STRUCT *' increases
required
alignment from 1 to 8 [-Wcast-align]
thingPtr = ( THING_STRUCT * ) thingStorage.data;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
Given that thingStorage.data is preceded by a pointer member which should
ensure that the data member is aligned as required, it seems like this is a
false positive.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>