[llvm] CodeGen: replace assertions with explicit errors for landinpad lowering (PR #71287)

via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 4 09:05:19 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-globalisel

Author: AlexDenisov (AlexDenisov)

<details>
<summary>Changes</summary>

Report explicit error messages instead of silently crashing in release mode.

These checks can be moved to Verifier, but it breaks compatibility tests.

---
Full diff: https://github.com/llvm/llvm-project/pull/71287.diff


3 Files Affected:

- (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+7-3) 
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+3-1) 
- (added) llvm/test/CodeGen/Generic/landingpad_wrong_type.ll (+17) 


``````````diff
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index d8f9e30b2599779..a9129bb29c55fae 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2795,9 +2795,13 @@ bool IRTranslator::translateLandingPad(const User &U,
   MIRBuilder.buildUndef(Undef);
 
   SmallVector<LLT, 2> Tys;
-  for (Type *Ty : cast<StructType>(LP.getType())->elements())
-    Tys.push_back(getLLTForType(*Ty, *DL));
-  assert(Tys.size() == 2 && "Only two-valued landingpads are supported");
+  if (LP.getType()->isStructTy()) {
+    for (Type *Ty : cast<StructType>(LP.getType())->elements())
+      Tys.push_back(getLLTForType(*Ty, *DL));
+  }
+  if (Tys.size() != 2) {
+    report_fatal_error("Only two-valued landingpads are supported");
+  }
 
   // Mark exception register as live in.
   Register ExceptionReg = TLI.getExceptionPointerRegister(PersonalityFn);
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 48096dc1687fcec..1c25ae420a482a1 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -3166,7 +3166,9 @@ void SelectionDAGBuilder::visitLandingPad(const LandingPadInst &LP) {
   SmallVector<EVT, 2> ValueVTs;
   SDLoc dl = getCurSDLoc();
   ComputeValueVTs(TLI, DAG.getDataLayout(), LP.getType(), ValueVTs);
-  assert(ValueVTs.size() == 2 && "Only two-valued landingpads are supported");
+  if (ValueVTs.size() != 2) {
+    report_fatal_error("Only two-valued landingpads are supported");
+  }
 
   // Get the two live-in registers as SDValues. The physregs have already been
   // copied into virtual registers.
diff --git a/llvm/test/CodeGen/Generic/landingpad_wrong_type.ll b/llvm/test/CodeGen/Generic/landingpad_wrong_type.ll
new file mode 100644
index 000000000000000..06a04c9b0af7d56
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/landingpad_wrong_type.ll
@@ -0,0 +1,17 @@
+; RUN: not --crash llc %s 2>&1 | FileCheck %s
+; RUN: not --crash -global-isel %s 2>&1 | FileCheck %s
+
+declare i32 @pers(...)
+declare void @f()
+
+define void @main() personality ptr @pers {
+  invoke void @f() to label %normal unwind label %lp
+
+normal:
+  ret void
+
+lp:
+  landingpad {ptr} cleanup
+  ret void
+}
+; CHECK:LLVM ERROR: Only two-valued landingpads are supported

``````````

</details>


https://github.com/llvm/llvm-project/pull/71287


More information about the llvm-commits mailing list