<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 --- - clang puzzled with bitfields and/or bitwise &"
href="http://llvm.org/bugs/show_bug.cgi?id=18028">18028</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang puzzled with bitfields and/or bitwise &
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.3
</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>devel@fresse.org
</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>Following program:
--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--
#include <stdio.h>
#include <stdint.h>
#include <string.h>
typedef union {
uint64_t u:56;
struct {
uint32_t:32;
uint32_t u24:24;
} __attribute__((packed));
struct {
uint64_t:32;
uint64_t s:8;
uint64_t m:8;
uint64_t h:8;
} __attribute__((packed));
} __attribute__((packed)) dt_hms_t;
struct dt_t_s {
struct {
uint64_t:8;
} __attribute__((packed));
union {
uint64_t u:56;
dt_hms_t hms;
} __attribute__((packed));
};
struct dt_dt_s {
union {
/* sandwich types */
struct {
uint64_t ign;
struct dt_t_s t;
};
};
};
int
main(void)
{
struct dt_dt_s test;
struct dt_t_s beef;
beef.hms.h = 23;
beef.hms.m = 59;
beef.hms.s = 0;
test.t = beef;
unsigned int first_access = (test.t.hms.u24 & 0xfffffffU);
unsigned int second_access = (test.t.hms.u24 & 0xfffffffU);
printf("%x %x\n", first_access, second_access);
return first_access != second_access;
}
--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--
The snippet (ab)uses implementation defined behaviour (accessing a union
element without writing to it first). However, the implementation defined
behaviour changes over time. Output:
$ ./a.out
60173b00 173b00
return code is 1
clang version 3.2 (tags/RELEASE_32/final) on the other hand handles this
snippet just fine.</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>