[clang] [llvm] [RISCV] Avoid fatal error for SiFive CLIC preemptible frame pointers (PR #217949)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 21 11:26:06 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-risc-v

Author: Zeyi Xu (zeyi2)

<details>
<summary>Changes</summary>

SiFive CLIC `preemptible` interrupt handlers currently use `s0` to preserve `mcause` and cannot be generated with a frame pointer. At `-O0`, Clang enables frame pointers by default, causing the fatal error to produce a backend crash report.

This commit switches to `DiagnosticInfoUnsupported` to emit a regular source-located error and suggest considering `-fomit-frame-pointer`.

This does not change the existing code generation restriction.

Fixes https://github.com/llvm/llvm-project/issues/217936

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.md (+3) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+3-2) 
- (modified) llvm/test/CodeGen/RISCV/sifive-interrupt-attr-err.ll (+2-2) 


``````````diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 8c9467ca7b742..6e33c8c4891fb 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -595,6 +595,9 @@ features cannot lower the translation-unit ABI level;
 - Added a new warning when the same interrupt type is specified more than
   once in a RISC-V `interrupt` attribute.
 
+- SiFive CLIC preemptible interrupt handlers now diagnose unsupported frame
+  pointers instead of producing a backend fatal error.
+
 - Added `-march=native` for better compatibility with ARM, AArch64, and X86. This
   option will be treated like `-mcpu=native` if `-mcpu` is not present. If
   `-mcpu` is present, the ISA will be selected from the host CPU and the tune
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 1db51b19fde2d..f3f10224378c5 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -26239,8 +26239,9 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
       reportFatalUsageError("'rnmi' interrupt kind requires Srnmi extension");
     const TargetFrameLowering *TFI = Subtarget.getFrameLowering();
     if (Kind.starts_with("SiFive-CLIC-preemptible") && TFI->hasFP(MF))
-      reportFatalUsageError("'SiFive-CLIC-preemptible' interrupt kinds cannot "
-                            "have a frame pointer");
+      Func.getContext().diagnose(DiagnosticInfoUnsupported{
+          Func, "'SiFive-CLIC-preemptible' interrupt kinds cannot have a frame "
+                "pointer; consider compiling with '-fomit-frame-pointer'"});
   }
 
   EVT PtrVT = getPointerTy(DAG.getDataLayout());
diff --git a/llvm/test/CodeGen/RISCV/sifive-interrupt-attr-err.ll b/llvm/test/CodeGen/RISCV/sifive-interrupt-attr-err.ll
index ccc11b74f78e7..9e06762f4e71d 100644
--- a/llvm/test/CodeGen/RISCV/sifive-interrupt-attr-err.ll
+++ b/llvm/test/CodeGen/RISCV/sifive-interrupt-attr-err.ll
@@ -3,9 +3,9 @@
 ; RUN: not llc -mtriple riscv64-unknown-elf -mattr=+experimental-xsfmclic -o - %s 2>&1 \
 ; RUN:   | FileCheck %s
 
-;; Test that these report fatal errors.
+;; Test that these report regular errors.
 
-; CHECK: LLVM ERROR: 'SiFive-CLIC-preemptible' interrupt kinds cannot have a frame pointer
+; CHECK: error: <unknown>:0:0: in function preemptible void (): 'SiFive-CLIC-preemptible' interrupt kinds cannot have a frame pointer; consider compiling with '-fomit-frame-pointer'
 
 define void @preemptible() "interrupt"="SiFive-CLIC-preemptible" "frame-pointer"="all" {
   ret void

``````````

</details>


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


More information about the cfe-commits mailing list