-
Notifications
You must be signed in to change notification settings - Fork 14.4k
AsmPrinter: Do not use report_fatal_error for unhandled ConstantExpr #145275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AsmPrinter: Do not use report_fatal_error for unhandled ConstantExpr #145275
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-backend-x86 Author: Matt Arsenault (arsenm) ChangesFull diff: https://github.com/llvm/llvm-project/pull/145275.diff 3 Files Affected:
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)
|
@llvm/pr-subscribers-backend-amdgpu Author: Matt Arsenault (arsenm) ChangesFull diff: https://github.com/llvm/llvm-project/pull/145275.diff 3 Files Affected:
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)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
CE->printAsOperand(OS, /*PrintType=*/false, | ||
!MF ? nullptr : MF->getFunction().getParent()); | ||
report_fatal_error(Twine(S)); | ||
CE->getContext().emitError(S); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
No description provided.