[llvm] [TargetLowering] fix index OOB (PR #67494)
James Y Knight via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 26 14:53:10 PDT 2023
================
@@ -5889,10 +5889,17 @@ void TargetLowering::ComputeConstraintToUse(AsmOperandInfo &OpInfo,
for (const unsigned E = G.size();
BestIdx < E && (G[BestIdx].second == TargetLowering::C_Other ||
G[BestIdx].second == TargetLowering::C_Immediate);
- ++BestIdx)
+ ++BestIdx) {
if (lowerImmediateIfPossible(G[BestIdx], Op, DAG, *this))
break;
+ // If we're out of constraints, just pick the first one.
+ if (BestIdx + 1 == E) {
+ BestIdx = 0;
+ break;
+ }
+ }
+ assert(BestIdx < G.size() && "bad index for best constraint");
----------------
jyknight wrote:
llvm SmallVector::operator[] already has this assert.
https://github.com/llvm/llvm-project/pull/67494
More information about the llvm-commits
mailing list