[llvm-commits] [PATCH] Fix Alias Bug
David Greene
dag at cray.com
Tue Jan 8 13:15:02 PST 2013
Use a union to do type punning instead of a cast. A cast
breaks strict aliasing rules.
---
llvm/unittests/Support/YAMLIOTest.cpp | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp
index afa71cc..f148c8d 100644
--- a/llvm/unittests/Support/YAMLIOTest.cpp
+++ b/llvm/unittests/Support/YAMLIOTest.cpp
@@ -783,10 +783,16 @@ namespace yaml {
static void mapping(IO &io, KindAndFlags& kf) {
io.mapRequired("kind", kf.kind);
// type of flags field varies depending on kind field
+ union {
+ uint32_t i;
+ AFlags aflags;
+ BFlags bflags;
+ } flags = { kf.flags };
+
if ( kf.kind == kindA )
- io.mapRequired("flags", *((AFlags*)&kf.flags));
+ io.mapRequired("flags", flags.aflags);
else
- io.mapRequired("flags", *((BFlags*)&kf.flags));
+ io.mapRequired("flags", flags.bflags);
}
};
}
--
1.7.8.4
More information about the llvm-commits
mailing list