[PATCH] Fix for PR 14779: PPC64: Assertion failure in CodeGen/MachineInstr.cpp

Kai kai at redstar.de
Sun Feb 10 22:41:33 PST 2013


Hi!

The attached patch fixes PR 14779.

The root problem here is that the function argument list and the Ins 
vector may not have the same length. E.g. this happens if an anonymous 
aggregate is passed by value. In such a case the variable FuncArg is not 
in sync with Ins[ArgNo] and results in an assertion failure.

My patch moves the computation of FuncArg inside the block which handles 
byVal parameters. This guarantees that FuncArg refers to the same 
argument as Ins[ArgNo].

Regards
Kai
-------------- next part --------------
diff --git a/lib/Target/PowerPC/PPCISelLowering.cpp b/lib/Target/PowerPC/PPCISelLowering.cpp
index e789112..8bca48c 100644
--- a/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -2161,8 +2161,7 @@ PPCTargetLowering::LowerFormalArguments_64SVR4(
 
   SmallVector<SDValue, 8> MemOps;
   unsigned nAltivecParamsAtEnd = 0;
-  Function::const_arg_iterator FuncArg = MF.getFunction()->arg_begin();
-  for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo, ++FuncArg) {
+  for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo) {
     SDValue ArgVal;
     bool needsLoad = false;
     EVT ObjectVT = Ins[ArgNo].VT;
@@ -2215,6 +2214,9 @@ PPCTargetLowering::LowerFormalArguments_64SVR4(
       SDValue FIN = DAG.getFrameIndex(FI, PtrVT);
       InVals.push_back(FIN);
 
+      Function::const_arg_iterator FuncArg = MF.getFunction()->arg_begin();
+      for (unsigned I = 0, E = Ins[ArgNo].OrigArgIndex; I != E; ++I)
+        ++FuncArg;
       if (ObjSize < 8) {
         if (GPR_idx != Num_GPR_Regs) {
           unsigned VReg = MF.addLiveIn(GPR[GPR_idx], &PPC::G8RCRegClass);
diff --git a/test/CodeGen/PowerPC/anon_aggr.ll b/test/CodeGen/PowerPC/anon_aggr.ll
new file mode 100644
index 0000000..7bb9312
--- /dev/null
+++ b/test/CodeGen/PowerPC/anon_aggr.ll
@@ -0,0 +1,14 @@
+; RUN: llc < %s | FileCheck %s
+
+; Test case for PR 14779: anonymous aggregates are not handled correctly.
+
+target datalayout = "E-p:64:64:64-S0-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-n32:64"
+target triple = "powerpc64-unknown-linux-gnu"
+
+define i8* @_bug({ i64, i8* } %array, i8* byval %ptr) {
+entry:
+  %p = extractvalue { i64, i8* } %array, 1
+  ret i8* %p
+}
+
+; CHECK: mr 3, 4


More information about the llvm-commits mailing list