Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Jun 23, 2025

No description provided.

Copy link
Contributor Author

arsenm commented Jun 23, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm arsenm marked this pull request as ready for review June 23, 2025 06:13
@llvmbot
Copy link
Member

llvmbot commented Jun 23, 2025

@llvm/pr-subscribers-backend-x86

Author: Matt Arsenault (arsenm)

Changes

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 --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)

@llvmbot
Copy link
Member

llvmbot commented Jun 23, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

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 --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)

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arsenm arsenm merged commit 6b129d6 into main Jun 23, 2025
13 checks passed
@arsenm arsenm deleted the users/arsenm/asm-printer/do-not-use-report-fatal-error-unsupported-constantexpr branch June 23, 2025 07:30
CE->printAsOperand(OS, /*PrintType=*/false,
!MF ? nullptr : MF->getFunction().getParent());
report_fatal_error(Twine(S));
CE->getContext().emitError(S);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if the error message mentioned which global is being initialized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should add some new DiagnosticInfo types for dealing with bad global references. Right now they mostly assume a function context

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.

6 participants