[llvm] [AMDGPU] Poison invalid globals after emitting error in LowerBufferFatPointers pass (PR #184662)

via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 10:54:29 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Arseniy Obolenskiy (aobolensk)

<details>
<summary>Changes</summary>

After the change from `report_fatal_error` to `Ctx.emitError` in #<!-- -->142014 there is a necessity to remove unsupported globals. Otherwise there is a secondary crash during ISel when processing them

Fixes SWDEV-511241

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


1 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp (+10-1) 


``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
index 05e97d2fc7508..f0720147937f2 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
@@ -2467,11 +2467,13 @@ bool AMDGPULowerBufferFatPointers::run(Module &M, const TargetMachine &TM) {
 
   BufferFatPtrToStructTypeMap StructTM(DL);
   BufferFatPtrToIntTypeMap IntTM(DL);
-  for (const GlobalVariable &GV : M.globals()) {
+  SmallVector<GlobalVariable *, 4> InvalidGlobals;
+  for (GlobalVariable &GV : M.globals()) {
     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");
+      InvalidGlobals.push_back(&GV);
       continue;
     }
 
@@ -2481,10 +2483,17 @@ bool AMDGPULowerBufferFatPointers::run(Module &M, const TargetMachine &TM) {
       Ctx.emitError("global variables that contain buffer fat pointers "
                     "(address space 7 pointers) are unsupported. Use "
                     "buffer resource pointers (address space 8) instead");
+      InvalidGlobals.push_back(&GV);
       continue;
     }
   }
 
+  for (GlobalVariable *GV : InvalidGlobals) {
+    GV->replaceAllUsesWith(PoisonValue::get(GV->getType()));
+    GV->eraseFromParent();
+    Changed = true;
+  }
+
   {
     // Collect all constant exprs and aggregates referenced by any function.
     SmallVector<Constant *, 8> Worklist;

``````````

</details>


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


More information about the llvm-commits mailing list