Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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

return MCConstantExpr::create(0, Ctx);
}

static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *C,
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll
Original file line number Diff line number Diff line change
@@ -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)
Loading