Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: src/IceAssembler.h

Issue 1311653003: Add UBSAN build option and fix undefined behaviour errors. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Neater way to set Target_Max Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Makefile.standalone ('k') | src/IceInst.h » ('j') | src/IceInst.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceAssembler.h
diff --git a/src/IceAssembler.h b/src/IceAssembler.h
index 7f5d909ed30215e46ac81595e035a203a478d047..b007325e7f45053f286d8c3d1cb968cafab460f7 100644
--- a/src/IceAssembler.h
+++ b/src/IceAssembler.h
@@ -100,20 +100,22 @@ public:
/// Basic support for emitting, loading, and storing.
template <typename T> void emit(T Value) {
assert(hasEnsuredCapacity());
- *reinterpret_cast<T *>(Cursor) = Value;
+ memcpy(reinterpret_cast<void *>(Cursor), &Value, sizeof(T));
Jim Stichnoth 2015/09/04 21:32:48 Have you checked the effect of this patch on assem
ascull 2015/09/05 00:00:48 The binary produces is the same before and after t
Jim Stichnoth 2015/09/05 01:03:22 OK, thanks for checking.
Cursor += sizeof(T);
}
template <typename T> T load(intptr_t Position) const {
assert(Position >= 0 &&
Position <= (size() - static_cast<intptr_t>(sizeof(T))));
- return *reinterpret_cast<T *>(Contents + Position);
+ T Value;
+ memcpy(&Value, reinterpret_cast<void *>(Contents + Position), sizeof(T));
+ return Value;
}
template <typename T> void store(intptr_t Position, T Value) {
assert(Position >= 0 &&
Position <= (size() - static_cast<intptr_t>(sizeof(T))));
- *reinterpret_cast<T *>(Contents + Position) = Value;
+ memcpy(reinterpret_cast<void *>(Contents + Position), &Value, sizeof(T));
}
/// Emit a fixup at the current location.
« no previous file with comments | « Makefile.standalone ('k') | src/IceInst.h » ('j') | src/IceInst.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698