Skip to content

Commit b925806

Browse files
author
miaozhiyuan
committed
[clang][ExprEngineCXX] Fix crash on dereference invalid
return value of getAdjustedParameterIndex()
1 parent 2fe81ed commit b925806

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,13 @@ SVal ExprEngine::computeObjectUnderConstruction(
354354
// Operator arguments do not correspond to operator parameters
355355
// because this-argument is implemented as a normal argument in
356356
// operator call expressions but not in operator declarations.
357-
const TypedValueRegion *TVR = Caller->getParameterLocation(
358-
*Caller->getAdjustedParameterIndex(Idx), BldrCtx->blockCount());
357+
std::optional<unsigned int> Index =
358+
Caller->getAdjustedParameterIndex(Idx);
359+
if (!Index) {
360+
return std::nullopt;
361+
}
362+
const TypedValueRegion *TVR =
363+
Caller->getParameterLocation(*Index, BldrCtx->blockCount());
359364
if (!TVR)
360365
return std::nullopt;
361366

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -std=c++23 -verify %s
2+
// expected-no-diagnostics
3+
4+
struct S
5+
{
6+
constexpr auto operator==(this auto, S)
7+
{
8+
return true;
9+
}
10+
};
11+
12+
int main()
13+
{
14+
return S {} == S {};
15+
}

0 commit comments

Comments
 (0)