[llvm] AsmPrinter: Do not use report_fatal_error for unhandled ConstantExpr (PR #145275)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 22 23:14:14 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

<details>
<summary>Changes</summary>



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


3 Files Affected:

- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+3-2) 
- (modified) llvm/test/CodeGen/AMDGPU/addrspacecast-initializer-unsupported.ll (+8-2) 
- (modified) llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll (+2-2) 


``````````diff
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 403963f33b65c..9025f5b8526f1 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3603,10 +3603,11 @@ const MCExpr *AsmPrinter::lowerConstant(const Constant *CV,
   // Otherwise report the problem to the user.
   std::string S;
   raw_string_ostream OS(S);
-  OS << "Unsupported expression in static initializer: ";
+  OS << "unsupported expression in static initializer: ";
   CE->printAsOperand(OS, /*PrintType=*/false,
                      !MF ? nullptr : MF->getFunction().getParent());
-  report_fatal_error(Twine(S));
+  CE->getContext().emitError(S);
+  return MCConstantExpr::create(0, Ctx);
 }
 
 static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *C,
diff --git a/llvm/test/CodeGen/AMDGPU/addrspacecast-initializer-unsupported.ll b/llvm/test/CodeGen/AMDGPU/addrspacecast-initializer-unsupported.ll
index ba8398ea227ca..30ae18f64cbce 100644
--- a/llvm/test/CodeGen/AMDGPU/addrspacecast-initializer-unsupported.ll
+++ b/llvm/test/CodeGen/AMDGPU/addrspacecast-initializer-unsupported.ll
@@ -1,6 +1,12 @@
-; RUN: not --crash llc -mtriple=amdgcn -verify-machineinstrs -amdgpu-enable-lower-module-lds=false < %s 2>&1 | FileCheck -check-prefix=ERROR %s
+; RUN: not llc -mtriple=amdgcn -verify-machineinstrs -amdgpu-enable-lower-module-lds=false < %s 2> %t.err | FileCheck %s
+; RUN: FileCheck -check-prefix=ERROR %s < %t.err
+
+; ERROR: error: unsupported expression in static initializer: addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4))
+
+; CHECK: gv_flatptr_from_lds:
+; CHECK-NEXT: .quad 0+32
+; CHECK-NEXT: .size gv_flatptr_from_lds, 8
 
-; ERROR: LLVM ERROR: Unsupported expression in static initializer: addrspacecast (ptr addrspace(3) @lds.arr to ptr addrspace(4))
 
 @lds.arr = unnamed_addr addrspace(3) global [256 x i32] poison, align 4
 
diff --git a/llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll b/llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll
index f1f5d7e2b7204..45f3ab60e9044 100644
--- a/llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll
+++ b/llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll
@@ -1,10 +1,10 @@
-; RUN: not --crash llc < %s -mtriple=i386-linux 2>&1 | FileCheck %s
+; RUN: not llc < %s -mtriple=i386-linux 2>&1 | FileCheck %s
 
 ; ptrtoint expressions that cast to a wider integer type are not supported.
 ; A frontend can achieve a similar result by casting to the correct integer
 ; type and explicitly zeroing any additional bytes.
 ; { i32, i32 } { i32 ptrtoint (ptr @r to i32), i32 0 }
 
-; CHECK: LLVM ERROR: Unsupported expression in static initializer: ptrtoint (ptr @r to i64)
+; CHECK: error: unsupported expression in static initializer: ptrtoint (ptr @r to i64)
 
 @r = global i64 ptrtoint (ptr @r to i64)

``````````

</details>


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


More information about the llvm-commits mailing list