AMDGPU: Start using LLVMContext errors in buffer fat pointer lowering (#142014)

Avoid using report_fatal_error. Many more uses that should be converted
in the pass remain.
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
index 3835f4c..0f002b0 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
@@ -2430,17 +2430,26 @@
   // its arguments or return types adjusted.
   SmallVector<std::pair<Function *, bool>> NeedsRemap;
 
+  LLVMContext &Ctx = M.getContext();
+
   BufferFatPtrToStructTypeMap StructTM(DL);
   BufferFatPtrToIntTypeMap IntTM(DL);
   for (const GlobalVariable &GV : M.globals()) {
-    if (GV.getAddressSpace() == AMDGPUAS::BUFFER_FAT_POINTER)
-      report_fatal_error("Global variables with a buffer fat pointer address "
-                         "space (7) are not supported");
+    if (GV.getAddressSpace() == AMDGPUAS::BUFFER_FAT_POINTER) {
+      // FIXME: Use DiagnosticInfo unsupported but it requires a Function
+      Ctx.emitError("global variables with a buffer fat pointer address "
+                    "space (7) are not supported");
+      continue;
+    }
+
     Type *VT = GV.getValueType();
-    if (VT != StructTM.remapType(VT))
-      report_fatal_error("Global variables that contain buffer fat pointers "
-                         "(address space 7 pointers) are unsupported. Use "
-                         "buffer resource pointers (address space 8) instead.");
+    if (VT != StructTM.remapType(VT)) {
+      // FIXME: Use DiagnosticInfo unsupported but it requires a Function
+      Ctx.emitError("global variables that contain buffer fat pointers "
+                    "(address space 7 pointers) are unsupported. Use "
+                    "buffer resource pointers (address space 8) instead");
+      continue;
+    }
   }
 
   {
diff --git a/llvm/test/CodeGen/AMDGPU/buffer-fat-pointer-unsupported-errors.ll b/llvm/test/CodeGen/AMDGPU/buffer-fat-pointer-unsupported-errors.ll
new file mode 100644
index 0000000..3fc8d73
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/buffer-fat-pointer-unsupported-errors.ll
@@ -0,0 +1,22 @@
+; RUN: split-file %s %t
+; RUN: not opt -mtriple=amdgcn-amd-amdhsa -disable-output -passes=amdgpu-lower-buffer-fat-pointers %t/contains-null-init.ll 2>&1 | FileCheck -check-prefix=ERR0 %s
+; RUN: not opt -mtriple=amdgcn-amd-amdhsa -disable-output -passes=amdgpu-lower-buffer-fat-pointers %t/contains-poison-init.ll 2>&1 | FileCheck -check-prefix=ERR1 %s
+; RUN: not opt -mtriple=amdgcn-amd-amdhsa -disable-output -passes=amdgpu-lower-buffer-fat-pointers %t/defined-gv-type.ll 2>&1 | FileCheck -check-prefix=ERR2 %s
+; RUN: not opt -mtriple=amdgcn-amd-amdhsa -disable-output -passes=amdgpu-lower-buffer-fat-pointers %t/declared-gv-type.ll 2>&1 | FileCheck -check-prefix=ERR3 %s
+
+;--- contains-null-init.ll
+; ERR0: error: global variables that contain buffer fat pointers (address space 7 pointers) are unsupported. Use buffer resource pointers (address space 8) instead
+@init_null = global ptr addrspace(7) null
+
+;--- contains-poison-init.ll
+; ERR1: error: global variables that contain buffer fat pointers (address space 7 pointers) are unsupported. Use buffer resource pointers (address space 8) instead
+@init_poison = global ptr addrspace(7) poison
+
+;--- defined-gv-type.ll
+; ERR2: error: global variables with a buffer fat pointer address space (7) are not supported
+@gv_is_addrspace_7 = addrspace(7) global i32 0
+
+;--- declared-gv-type.ll
+; ERR3: error: global variables with a buffer fat pointer address space (7) are not supported
+@extern_gv_is_addrspace_7 = external addrspace(7) global i32
+