aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-02-25 19:06:14 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-02-25 20:22:37 -0800
commit59cf0306b1c564bbe7b9aa1ea69657fe603615b1 (patch)
tree01dc173f5871f9ba8faa34a7bbbb43684a47baf7 /lib
parentc69b67ab6dcb00a40d12dc35df7fe2c682c6c36a (diff)
properly handle align 0 on memcpy and memset, warning if asked for
Diffstat (limited to 'lib')
-rw-r--r--lib/Target/JSBackend/CallHandlers.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/Target/JSBackend/CallHandlers.h b/lib/Target/JSBackend/CallHandlers.h
index a9caa54f0d..ec17f905d1 100644
--- a/lib/Target/JSBackend/CallHandlers.h
+++ b/lib/Target/JSBackend/CallHandlers.h
@@ -232,7 +232,11 @@ DEF_CALL_HANDLER(llvm_memcpy_p0i8_p0i8_i32, {
unsigned Len = LenInt->getZExtValue();
if (Len <= WRITE_LOOP_MAX) {
unsigned Align = AlignInt->getZExtValue();
- if (Align > 4 || Align == 0) Align = 4; // XXX actually memcpy align 0 means 1, not 4
+ if (Align > 4) Align = 4;
+ else if (Align == 0) Align = 1; // align 0 means 1 in memcpy and memset (unlike other places where it means 'default/4')
+ if (Align == 1 && Len > 1 && WarnOnUnaligned) {
+ errs() << "emcc: warning: unaligned memcpy in " << CI->getParent()->getParent()->getName() << ":" << *CI << " (compiler's fault?)\n";
+ }
unsigned Pos = 0;
std::string Ret;
std::string Dest = getValueAsStr(CI->getOperand(0));
@@ -279,7 +283,11 @@ DEF_CALL_HANDLER(llvm_memset_p0i8_i32, {
if (Len <= WRITE_LOOP_MAX) {
unsigned Align = AlignInt->getZExtValue();
unsigned Val = ValInt->getZExtValue();
- if (Align > 4 || Align == 0) Align = 4; // XXX actually memset align 0 means 1, not 4
+ if (Align > 4) Align = 4;
+ else if (Align == 0) Align = 1; // align 0 means 1 in memcpy and memset (unlike other places where it means 'default/4')
+ if (Align == 1 && Len > 1 && WarnOnUnaligned) {
+ errs() << "emcc: warning: unaligned memcpy in " << CI->getParent()->getParent()->getName() << ":" << *CI << " (compiler's fault?)\n";
+ }
unsigned Pos = 0;
std::string Ret;
std::string Dest = getValueAsStr(CI->getOperand(0));