[llvm] Silence illegal address computation warning (PR #83244)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 04:41:09 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Martin Wehking (MartinWehking)

<details>
<summary>Changes</summary>

Add an assertion before an access of ValMappings to ensure that it is within the array bounds.
Silence a static analyzer warning through this.

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


1 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AMDGPUGenRegisterBankInfo.def (+1) 


``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUGenRegisterBankInfo.def b/llvm/lib/Target/AMDGPU/AMDGPUGenRegisterBankInfo.def
index d6a94c972340ea..e7b3afc91d6520 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUGenRegisterBankInfo.def
+++ b/llvm/lib/Target/AMDGPU/AMDGPUGenRegisterBankInfo.def
@@ -284,6 +284,7 @@ const RegisterBankInfo::ValueMapping *getValueMapping(unsigned BankID,
     break;
   }
 
+  assert(Idx < sizeof(ValMappings) / sizeof(ValMappings[0]));
   assert(Log2_32_Ceil(Size) == Log2_32_Ceil(ValMappings[Idx].BreakDown->Length));
   assert(BankID == ValMappings[Idx].BreakDown->RegBank->getID());
 

``````````

</details>


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


More information about the llvm-commits mailing list