[llvm] r230941 - Teach the verifier to enforce that the alignment argument of memory intrinsics must be a power of 2.
Owen Anderson
resistor at mac.com
Mon Mar 2 01:35:06 PST 2015
Author: resistor
Date: Mon Mar 2 03:35:06 2015
New Revision: 230941
URL: http://llvm.org/viewvc/llvm-project?rev=230941&view=rev
Log:
Teach the verifier to enforce that the alignment argument of memory intrinsics must be a power of 2.
Added:
llvm/trunk/test/Verifier/memcpy.ll
Modified:
llvm/trunk/lib/IR/Verifier.cpp
Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=230941&r1=230940&r2=230941&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Mon Mar 2 03:35:06 2015
@@ -2796,14 +2796,20 @@ void Verifier::visitIntrinsicFunctionCal
} 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:
Added: llvm/trunk/test/Verifier/memcpy.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/memcpy.ll?rev=230941&view=auto
==============================================================================
--- llvm/trunk/test/Verifier/memcpy.ll (added)
+++ llvm/trunk/test/Verifier/memcpy.ll Mon Mar 2 03:35:06 2015
@@ -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
More information about the llvm-commits
mailing list