summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/YAMLIOTest.cpp
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
commit4162c2d31ba23fcda2e8184b12f47590c5f16920 (patch)
tree8d236c1f8e1fd7166c31c83e4b6135ce26ba2ccf /llvm/unittests/Support/YAMLIOTest.cpp
parent37c528259ae36ba14dbaeb10e3b174bd5ed993dd (diff)
downloadbcm5719-llvm-4162c2d31ba23fcda2e8184b12f47590c5f16920.tar.gz
bcm5719-llvm-4162c2d31ba23fcda2e8184b12f47590c5f16920.zip
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. llvm-svn: 172081
Diffstat (limited to 'llvm/unittests/Support/YAMLIOTest.cpp')
-rw-r--r--llvm/unittests/Support/YAMLIOTest.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp
index afa71cc25ea..a39fbebf295 100644
--- a/llvm/unittests/Support/YAMLIOTest.cpp
+++ b/llvm/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);
+ }
}
};
}
OpenPOWER on IntegriCloud