Skip to content

[Clang][Sema] Fix out-of-bounds access #80978

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

Merged
merged 2 commits into from
Feb 7, 2024
Merged

[Clang][Sema] Fix out-of-bounds access #80978

merged 2 commits into from
Feb 7, 2024

Conversation

Sirraide
Copy link
Member

@Sirraide Sirraide commented Feb 7, 2024

Trying to compile a C-style variadic member function with an explicit object parameter was crashing in Sema because of an out-of-bounds access.

This fixes #80971.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Feb 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Feb 7, 2024

@llvm/pr-subscribers-clang

Author: None (Sirraide)

Changes

Trying to compile a C-style variadic member function with an explicit object parameter was crashing in Sema because of an out-of-bounds access.

This fixes #80971.


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaOverload.cpp (+1-1)
  • (modified) clang/test/SemaCXX/cxx2b-deducing-this.cpp (+10)
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6a04d68b4f0414..fc3d7d8dcf16e8 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7719,7 +7719,7 @@ bool Sema::CheckNonDependentConversions(
   unsigned Offset =
       Method && Method->hasCXXExplicitFunctionObjectParameter() ? 1 : 0;
 
-  for (unsigned I = 0, N = std::min(ParamTypes.size(), Args.size()); I != N;
+  for (unsigned I = 0, N = std::min(ParamTypes.size() - Offset, Args.size()); I != N;
        ++I) {
     QualType ParamType = ParamTypes[I + Offset];
     if (!ParamType->isDependentType()) {
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index aab35828096a8e..670e72944ee82d 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -636,3 +636,13 @@ struct D {
     }
 };
 }
+
+namespace GH80971 {
+struct S {
+  auto f(this auto self...) {  }
+};
+
+int bug() {
+  S{}.f(0);
+}
+}
\ No newline at end of file

@Sirraide
Copy link
Member Author

Sirraide commented Feb 7, 2024

CC @AaronBallman

Copy link

github-actions bot commented Feb 7, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@Sirraide
Copy link
Member Author

Sirraide commented Feb 7, 2024

If you’re wondering what the force-pushes are about, first I forgot to run git clang-format, then I was also missing a newline at the end of the test file...

@tbaederr tbaederr requested a review from cor3ntin February 7, 2024 12:44
Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@Sirraide
Copy link
Member Author

Sirraide commented Feb 7, 2024

LGTM, thanks!

I don’t have commit access, so you or someone else would have to merge it

@cor3ntin cor3ntin merged commit 52bf531 into llvm:main Feb 7, 2024
@Sirraide Sirraide deleted the 80971 branch February 8, 2024 08:38
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.

ICE when explicit object parameter be a function parameter pack
3 participants