diff options
author | Mark Seaborn <mseaborn@chromium.org> | 2013-06-24 18:41:45 -0700 |
---|---|---|
committer | Mark Seaborn <mseaborn@chromium.org> | 2013-06-24 18:41:45 -0700 |
commit | 26c1bae3de5daa2ea28d7ee7584b98723f38c3fa (patch) | |
tree | f14d2f14ce033175a22eb0bd4bdcb93b0c52bce1 /lib | |
parent | 9a2a4d5471baa159bfd4ed793962ec5d0841631b (diff) |
PNaCl ABI: Strip alignment info from memcpy/memmove/memset intrinsic calls
Do the same for memcpy/memmove/memset intrinsic calls that we have
already done for integer loads and stores: Remove assumptions about
pointer alignment by setting the alignment argument to 1. Make the
ABI checker require this.
BUG=https://code.google.com/p/nativeclient/issues/detail?id=3445
TEST=*.ll tests + PNaCl toolchain trybots
Review URL: https://codereview.chromium.org/17563008
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp | 12 | ||||
-rw-r--r-- | lib/Transforms/NaCl/StripAttributes.cpp | 9 |
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp index 1fe79757a0..9a96d19ed4 100644 --- a/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp +++ b/lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp @@ -315,6 +315,18 @@ const char *PNaClABIVerifyFunctions::checkInstruction(const Instruction *Inst) { isa<MDNode>(Arg))) return "bad intrinsic operand"; } + // Disallow alignments other than 1 on memcpy() etc., for the + // same reason that we disallow them on integer loads and + // stores. + if (const MemIntrinsic *MemOp = dyn_cast<MemIntrinsic>(Call)) { + // Avoid the getAlignment() method here because it aborts if + // the alignment argument is not a Constant. + Value *AlignArg = MemOp->getArgOperand(3); + if (!isa<ConstantInt>(AlignArg) || + cast<ConstantInt>(AlignArg)->getZExtValue() != 1) { + return "bad alignment"; + } + } // Allow the instruction and skip the later checks. return NULL; } diff --git a/lib/Transforms/NaCl/StripAttributes.cpp b/lib/Transforms/NaCl/StripAttributes.cpp index 9c3dd6c83e..fb3a080e84 100644 --- a/lib/Transforms/NaCl/StripAttributes.cpp +++ b/lib/Transforms/NaCl/StripAttributes.cpp @@ -14,6 +14,7 @@ // calls. // * Calling conventions from functions and function calls. // * The "align" attribute on functions. +// * The alignment argument of memcpy/memmove/memset intrinsic calls. // * The "unnamed_addr" attribute on functions and global variables. // * The distinction between "internal" and "private" linkage. // * "protected" and "internal" visibility of functions and globals. @@ -25,6 +26,7 @@ #include "llvm/IR/DataLayout.h" #include "llvm/IR/Function.h" +#include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" #include "llvm/Pass.h" @@ -182,6 +184,13 @@ void stripFunctionAttrs(DataLayout *DL, Function *Func) { CheckAttributes(Call.getAttributes()); Call.setAttributes(AttributeSet()); Call.setCallingConv(CallingConv::C); + + // Set memcpy(), memmove() and memset() to use pessimistic + // alignment assumptions. + if (MemIntrinsic *MemOp = dyn_cast<MemIntrinsic>(Inst)) { + Type *AlignTy = MemOp->getAlignmentCst()->getType(); + MemOp->setAlignment(ConstantInt::get(AlignTy, 1)); + } } else if (OverflowingBinaryOperator *Op = dyn_cast<OverflowingBinaryOperator>(Inst)) { cast<BinaryOperator>(Op)->setHasNoUnsignedWrap(false); |