Skip to content

[Clang] [Sema] Document invariant in Sema::AddOverloadCandidate #135256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

shafik
Copy link
Collaborator

@shafik shafik commented Apr 10, 2025

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: #135086

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: llvm#135086
@shafik shafik added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Apr 10, 2025
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Apr 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 10, 2025

@llvm/pr-subscribers-clang

Author: Shafik Yaghmour (shafik)

Changes

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: #135086


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

1 Files Affected:

  • (modified) clang/lib/Sema/SemaOverload.cpp (+1)
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) {

@shafik shafik merged commit ffac140 into llvm:main Apr 11, 2025
14 checks passed
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…#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: llvm#135086
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 - ArgIdx in Sema::AddOverloadCandidate looks like it overflows
3 participants