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

Martin Wehking via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 02:20:14 PST 2024


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

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

>From 74f74cff40ebd567643a7b8c0f96dddc36987d68 Mon Sep 17 00:00:00 2001
From: Martin Wehking <martin.wehking at codeplay.com>
Date: Wed, 28 Feb 2024 10:03:17 +0000
Subject: [PATCH] Silence illegal address computation warning

Add an assertion before an access of ValMappings to ensure that
it is within the array bounds.
Silence a static analyzer warning through this.
---
 llvm/lib/Target/AMDGPU/AMDGPUGenRegisterBankInfo.def | 1 +
 1 file changed, 1 insertion(+)

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());
 



More information about the llvm-commits mailing list