Skip to content

[SystemZ][z/OS] Fix crash when personality function is null - #217947

Open
redstar wants to merge 1 commit into
mainfrom
users/redstar/fixpersonalitycrash
Open

[SystemZ][z/OS] Fix crash when personality function is null#217947
redstar wants to merge 1 commit into
mainfrom
users/redstar/fixpersonalitycrash

Conversation

@redstar

@redstar redstar commented Aug 21, 2026

Copy link
Copy Markdown
Member

When the personality function is specified as null, then the current code triggers an assertion. The correct behaviour, like on Linux, is to not emit the DWARF EH data and the reference to the personality function.

When the personality function is specified as `null`, then the
current code triggers an assertion. The correct behaviour, like on
Linux, is to not emit the DWARF EH data and the reference to the
personality function.
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-systemz

Author: Kai Nacke (redstar)

Changes

When the personality function is specified as null, then the current code triggers an assertion. The correct behaviour, like on Linux, is to not emit the DWARF EH data and the reference to the personality function.


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

2 Files Affected:

  • (modified) llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp (+7-7)
  • (added) llvm/test/CodeGen/SystemZ/zos-no-personality.ll (+19)
diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index 50c0c04a70df2..235d8eea84ec5 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -1609,13 +1609,13 @@ void SystemZAsmPrinter::calculatePPA1() {
     const Function *Per = dyn_cast<Function>(
         MF->getFunction().getPersonalityFn()->stripPointerCasts());
     PersonalityRoutine = Per ? MF->getTarget().getSymbol(Per) : nullptr;
-    assert(PersonalityRoutine && "Missing personality routine");
-
-    GCCEH = MF->getContext().getOrCreateSymbol(Twine("GCC_except_table") +
-                                               Twine(MF->getFunctionNumber()));
-    PersonalityADADisp = ADATable.insert(PersonalityRoutine,
-                                         SystemZII::MO_ADA_INDIRECT_FUNC_DESC);
-    GCCEHADADisp = ADATable.insert(GCCEH, SystemZII::MO_ADA_DATA_SYMBOL_ADDR);
+    if (PersonalityRoutine) {
+      GCCEH = MF->getContext().getOrCreateSymbol(
+          Twine("GCC_except_table") + Twine(MF->getFunctionNumber()));
+      PersonalityADADisp = ADATable.insert(
+          PersonalityRoutine, SystemZII::MO_ADA_INDIRECT_FUNC_DESC);
+      GCCEHADADisp = ADATable.insert(GCCEH, SystemZII::MO_ADA_DATA_SYMBOL_ADDR);
+    }
   }
 
   // Get the name of the function, with suffix _.
diff --git a/llvm/test/CodeGen/SystemZ/zos-no-personality.ll b/llvm/test/CodeGen/SystemZ/zos-no-personality.ll
new file mode 100644
index 0000000000000..d8212dc3c1e70
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/zos-no-personality.ll
@@ -0,0 +1,19 @@
+; RUN: llc -mtriple s390x-zos < %s | FileCheck %s
+
+define { ptr, i32 } @foo() personality ptr null {
+  invoke void null(ptr null, ptr null)
+          to label %1 unwind label %2
+
+1:
+  ret { ptr, i32 } zeroinitializer
+
+2:
+  %3 = landingpad { ptr, i32 }
+          catch ptr null
+  ret { ptr, i32 } %3
+}
+
+; CHECK: foo DS 0H
+; CHECK-NOT: .gcc_exception_table.foo
+; CHECK: L#PPA1_foo_0 DS 0H
+; CHECK-NOT: *   Bit 3: 1 = C++ EH block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant