aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2007-07-10 19:28:12 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2007-07-10 19:28:12 +0000
commitb91025b619515040d2c21cb30ff969c974eb40d0 (patch)
tree55f1dceb36125d1571bf43e66cf00101fb4bd8c4
parenta289511090b2b48e0824349865e5bc9cb4b7d33c (diff)
check for correct usage of the byval attribute
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@38506 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/VMCore/Verifier.cpp13
-rw-r--r--test/Verifier/byval-1.ll2
-rw-r--r--test/Verifier/byval-2.ll2
-rw-r--r--test/Verifier/byval-3.ll2
-rw-r--r--test/Verifier/byval-4.ll4
5 files changed, 21 insertions, 2 deletions
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index 16e87f4f7a..4e3a16e8ee 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -361,6 +361,10 @@ void Verifier::visitFunction(Function &F) {
if (const ParamAttrsList *Attrs = FT->getParamAttrs()) {
unsigned Idx = 1;
+
+ Assert(!Attrs->paramHasAttr(0, ParamAttr::ByVal),
+ "Attribute ByVal should not apply to functions!");
+
for (FunctionType::param_iterator I = FT->param_begin(),
E = FT->param_end(); I != E; ++I, ++Idx) {
if (Attrs->paramHasAttr(Idx, ParamAttr::ZExt) ||
@@ -370,9 +374,14 @@ void Verifier::visitFunction(Function &F) {
if (Attrs->paramHasAttr(Idx, ParamAttr::NoAlias))
Assert1(isa<PointerType>(FT->getParamType(Idx-1)),
"Attribute NoAlias should only apply to Pointer type!", &F);
- if (Attrs->paramHasAttr(Idx, ParamAttr::ByVal))
+ if (Attrs->paramHasAttr(Idx, ParamAttr::ByVal)) {
Assert1(isa<PointerType>(FT->getParamType(Idx-1)),
- "Attribute ByVal should only apply to Pointer type!", &F);
+ "Attribute ByVal should only apply to pointer to structs!", &F);
+ const PointerType *Ty =
+ cast<PointerType>(FT->getParamType(Idx-1));
+ Assert1(isa<StructType>(Ty->getElementType()),
+ "Attribute ByVal should only apply to pointer to structs!", &F);
+ }
}
}
diff --git a/test/Verifier/byval-1.ll b/test/Verifier/byval-1.ll
new file mode 100644
index 0000000000..cbae548c97
--- /dev/null
+++ b/test/Verifier/byval-1.ll
@@ -0,0 +1,2 @@
+; RUN: not llvm-as < %s -o /dev/null -f
+declare void @h(i32* byval %num)
diff --git a/test/Verifier/byval-2.ll b/test/Verifier/byval-2.ll
new file mode 100644
index 0000000000..56b8a27d1f
--- /dev/null
+++ b/test/Verifier/byval-2.ll
@@ -0,0 +1,2 @@
+; RUN: not llvm-as < %s -o /dev/null -f
+declare void @h(i32* %num) byval
diff --git a/test/Verifier/byval-3.ll b/test/Verifier/byval-3.ll
new file mode 100644
index 0000000000..9c2cb98451
--- /dev/null
+++ b/test/Verifier/byval-3.ll
@@ -0,0 +1,2 @@
+; RUN: not llvm-as < %s -o /dev/null -f
+declare void @h(i32 byval %num)
diff --git a/test/Verifier/byval-4.ll b/test/Verifier/byval-4.ll
new file mode 100644
index 0000000000..ff733a5bdc
--- /dev/null
+++ b/test/Verifier/byval-4.ll
@@ -0,0 +1,4 @@
+; RUN: llvm-as < %s -o /dev/null -f
+%struct.foo = type { i64 }
+
+declare void @h(%struct.foo* byval %num)