aboutsummaryrefslogtreecommitdiff
path: root/unittests/Support
diff options
context:
space:
mode:
authorDavid Greene <greened@obbligato.org>2013-01-10 18:17:54 +0000
committerDavid Greene <greened@obbligato.org>2013-01-10 18:17:54 +0000
commit5e1b31bf5588cd9ea0b16e94fcc1d908e40027e2 (patch)
treeca52460dfcc0b6cf196ca8e62277067b5063f4fe /unittests/Support
parentc560bf638b74eb48347a7b945b90aa89ffcc1620 (diff)
Fix Alias Bug
Use memcpy to do type punning instead of a cast. A cast or similar operation through a union breaks strict aliasing rules. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172081 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Support')
-rw-r--r--unittests/Support/YAMLIOTest.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/unittests/Support/YAMLIOTest.cpp b/unittests/Support/YAMLIOTest.cpp
index afa71cc25e..a39fbebf29 100644
--- a/unittests/Support/YAMLIOTest.cpp
+++ b/unittests/Support/YAMLIOTest.cpp
@@ -783,10 +783,18 @@ namespace yaml {
static void mapping(IO &io, KindAndFlags& kf) {
io.mapRequired("kind", kf.kind);
// type of flags field varies depending on kind field
- if ( kf.kind == kindA )
- io.mapRequired("flags", *((AFlags*)&kf.flags));
- else
- io.mapRequired("flags", *((BFlags*)&kf.flags));
+
+ // Use memcpy here to avoid breaking strict aliasing rules.
+ if ( kf.kind == kindA ) {
+ AFlags aflags;
+ memcpy(&aflags, &kf.flags, sizeof(aflags));
+ io.mapRequired("flags", aflags);
+ }
+ else {
+ BFlags bflags;
+ memcpy(&bflags, &kf.flags, sizeof(bflags));
+ io.mapRequired("flags", bflags);
+ }
}
};
}