Change the Verifier to support returning first class aggregrates.
authorMatthijs Kooijman <matthijs@stdin.nl>
Thu, 5 Jun 2008 14:00:36 +0000 (14:00 +0000)
committerMatthijs Kooijman <matthijs@stdin.nl>
Thu, 5 Jun 2008 14:00:36 +0000 (14:00 +0000)
Add a testcase for functions returning first class aggregrates.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52002 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Verifier.cpp
test/Assembler/AggregrateReturn.ll [new file with mode: 0644]

index bfa2e6573f285225d3086c61a096d93ce72990f5..8cbb703a7369a5fcf9145a519575c82dcf8db091 100644 (file)
@@ -594,7 +594,10 @@ void Verifier::visitReturnInst(ReturnInst &RI) {
     Assert2(N == 0,
             "Found return instr that returns void in Function of non-void "
             "return type!", &RI, F->getReturnType());
-  else if (const StructType *STy = dyn_cast<StructType>(F->getReturnType())) {
+  else if (N > 1) {
+    const StructType *STy = dyn_cast<StructType>(F->getReturnType());
+    Assert2(STy, "Return instr with multiple values, but return type is not "
+                 "a struct", &RI, F->getReturnType());
     Assert2(STy->getNumElements() == N,
             "Incorrect number of return values in ret instruction!",
             &RI, F->getReturnType());
diff --git a/test/Assembler/AggregrateReturn.ll b/test/Assembler/AggregrateReturn.ll
new file mode 100644 (file)
index 0000000..264b343
--- /dev/null
@@ -0,0 +1,22 @@
+; RUN: llvm-as < %s | llvm-dis
+
+define { i32, i32 } @foo() {
+  %res = insertvalue { i32, i32 } undef, i32 0, 0
+  %res2 = insertvalue { i32, i32 } %res, i32 1, 1
+  ret { i32, i32 } %res2
+}
+
+define [ 2 x i32 ] @bar() {
+  %res = insertvalue [ 2 x i32 ] undef, i32 0, 0
+  %res2 = insertvalue [ 2 x i32 ] %res, i32 1, 1
+  ret [ 2 x i32 ] %res2
+}
+
+define i32 @main() {
+  %a = call { i32, i32 }()* @foo ()
+  %b = call [ 2 x i32 ]()* @bar ()
+  %a.0 = extractvalue { i32, i32 } %a, 0
+  %b.1 = extractvalue [ 2 x i32 ] %b, 1
+  %r = add i32 %a.0, %b.1
+  ret i32 %r
+}