[clang] [Clang] [Sema] Document invariant in Sema::AddOverloadCandidate (PR #135256)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 10 13:55:50 PDT 2025


https://github.com/shafik created https://github.com/llvm/llvm-project/pull/135256

Static analysis flagged 1 - ArgIdx in Sema::AddOverloadCandidate for its potential to overflow.

Turns out this is intentional since when PO ==
OverloadCandidateParamOrder::Reversed Args.size() is always two, so this will never overflow.

We document using an assert.

Fixes: https://github.com/llvm/llvm-project/issues/135086

>From 75b7a2ac7174033b161919742eb85b9b181a474f Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour <shafik.yaghmour at intel.com>
Date: Thu, 10 Apr 2025 13:49:37 -0700
Subject: [PATCH] [Clang] [Sema] Document invariant in
 Sema::AddOverloadCandidate

Static analysis flagged 1 - ArgIdx in Sema::AddOverloadCandidate for its
potential to overflow.

Turns out this is intentional since when PO ==
OverloadCandidateParamOrder::Reversed Args.size() is always two, so this will
never overflow.

We document using an assert.

Fixes: https://github.com/llvm/llvm-project/issues/135086
---
 clang/lib/Sema/SemaOverload.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index f46ef2c7f5bd6..9c2df0b21d278 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7189,6 +7189,7 @@ void Sema::AddOverloadCandidate(
     }
   }
 
+  assert(PO != OverloadCandidateParamOrder::Reversed || Args.size() == 2);
   // Determine the implicit conversion sequences for each of the
   // arguments.
   for (unsigned ArgIdx = 0; ArgIdx < Args.size(); ++ArgIdx) {



More information about the cfe-commits mailing list