diff options
| author | Owen Anderson <resistor@mac.com> | 2015-03-02 09:35:06 +0000 |
|---|---|---|
| committer | Owen Anderson <resistor@mac.com> | 2015-03-02 09:35:06 +0000 |
| commit | 63fbf10c32014cd88eb495d2eed49592972adbe6 (patch) | |
| tree | 38b90dedb9529f4607a22751caa9e0358ab653b8 /llvm | |
| parent | 5af4b21c2e5ecc84a509cf54bd65a5b7ceccbe8e (diff) | |
| download | bcm5719-llvm-63fbf10c32014cd88eb495d2eed49592972adbe6.tar.gz bcm5719-llvm-63fbf10c32014cd88eb495d2eed49592972adbe6.zip | |
Teach the verifier to enforce that the alignment argument of memory intrinsics must be a power of 2.
llvm-svn: 230941
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/IR/Verifier.cpp | 10 | ||||
| -rw-r--r-- | llvm/test/Verifier/memcpy.ll | 9 |
2 files changed, 17 insertions, 2 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index d01e1389436..fbdc9880c5c 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2796,14 +2796,20 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) { } break; case Intrinsic::memcpy: case Intrinsic::memmove: - case Intrinsic::memset: - Assert1(isa<ConstantInt>(CI.getArgOperand(3)), + case Intrinsic::memset: { + ConstantInt *AlignCI = dyn_cast<ConstantInt>(CI.getArgOperand(3)); + Assert1(AlignCI, "alignment argument of memory intrinsics must be a constant int", &CI); + const APInt &AlignVal = AlignCI->getValue(); + Assert1(AlignCI->isZero() || AlignVal.isPowerOf2(), + "alignment argument of memory intrinsics must be a power of 2", + &CI); Assert1(isa<ConstantInt>(CI.getArgOperand(4)), "isvolatile argument of memory intrinsics must be a constant int", &CI); break; + } case Intrinsic::gcroot: case Intrinsic::gcwrite: case Intrinsic::gcread: diff --git a/llvm/test/Verifier/memcpy.ll b/llvm/test/Verifier/memcpy.ll new file mode 100644 index 00000000000..bd168cc953c --- /dev/null +++ b/llvm/test/Verifier/memcpy.ll @@ -0,0 +1,9 @@ +; RUN: not opt -verify < %s 2>&1 | FileCheck %s + +; CHECK: alignment argument of memory intrinsics must be a power of 2 + +define void @foo(i8* %P, i8* %Q) { + call void @llvm.memcpy.p0i8.p0i8.i32(i8* %P, i8* %Q, i32 4, i32 3, i1 false) + ret void +} +declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind |

