[LLVMbugs] [Bug 23599] New: Clang miscompiles assignments to packed struct members
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed May 20 14:30:06 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=23599
Bug ID: 23599
Summary: Clang miscompiles assignments to packed struct members
Product: new-bugs
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: vonosmas at gmail.com
CC: llvmbugs at cs.uiuc.edu, nlewycky at google.com
Classification: Unclassified
$ cat tmp/a.cc
#include <stdio.h>
#include <stdint.h>
#define ETH_ALEN 6
struct ether_addr
{
uint8_t ether_addr_octet[ETH_ALEN];
} __attribute__ ((__packed__));
struct ether_header
{
uint8_t ether_dhost[ETH_ALEN];
uint8_t ether_shost[ETH_ALEN];
} __attribute__ ((__packed__));
void Print(const ether_header ð) {
for (int i = 0; i < 6; i++)
printf("%d ", eth.ether_dhost[i]);
printf("\n");
for (int i = 0; i < 6; i++)
printf("%d ", eth.ether_shost[i]);
printf("\n");
}
void FooBarBaz(const ether_addr& ether_src, const ether_addr& ether_dst) {
ether_header eth{};
*((ether_addr*)eth.ether_shost) = ether_src;
*((ether_addr*)eth.ether_dhost) = ether_dst;
Print(eth);
}
int main() {
FooBarBaz({{1,2,3,4,5,6}}, {{7,8,9,10,11,12}});
return 0;
}
$ ./bin/clang++ -O2 tmp/a.cc -std=c++11 && ./a.out
7 8 9 10 11 12
0 0 0 0 0 0
$ ./bin/clang++ -O0 tmp/a.cc -std=c++11 && ./a.out
7 8 9 10 11 12
1 2 3 4 5 6
I haven't yet figured out which optimization pass is responsible for that. Note
that if I swap the assignments of ether_src and ether_dst, the program works as
expected.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150520/9ab83d45/attachment.html>
More information about the llvm-bugs
mailing list