[clang] [Clang][Sema] Fix out-of-bounds access (PR #80978)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 7 03:51:56 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (Sirraide)
<details>
<summary>Changes</summary>
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
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/80978
More information about the cfe-commits
mailing list