[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)

via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 7 03:51:26 PST 2024


https://github.com/Sirraide created https://github.com/llvm/llvm-project/pull/80978

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.

>From 9c32a0ad9b85328b34545c8ec3a47611ecb4cd72 Mon Sep 17 00:00:00 2001
From: Sirraide <aeternalmail at gmail.com>
Date: Wed, 7 Feb 2024 12:49:18 +0100
Subject: [PATCH] [Clang][Sema] Fix out-of-bounds access

---
 clang/lib/Sema/SemaOverload.cpp            |  2 +-
 clang/test/SemaCXX/cxx2b-deducing-this.cpp | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

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



More information about the cfe-commits mailing list