Skip to content

Commit be86fdb

Browse files
committed
[analyzer] Fix off-by-one in operator call parameter binding.
Member operator declarations and member operator expressions have different numbering of parameters and arguments respectively: one of them includes "this", the other does not. Account for this inconsistency when figuring out whether the parameter needs to be manually rebound from the Environment to the Store when entering a stack frame of an operator call, as opposed to being constructed with a constructor and as such already having the necessary Store bindings. Differential Revision: https://reviews.llvm.org/D69155
1 parent 689ce81 commit be86fdb

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/StaticAnalyzer/Core/CallEvent.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ static void addParameterValuesToBindings(const StackFrameContext *CalleeCtx,
519519

520520
// TODO: Support allocator calls.
521521
if (Call.getKind() != CE_CXXAllocator)
522-
if (Call.isArgumentConstructedDirectly(Idx))
522+
if (Call.isArgumentConstructedDirectly(Call.getASTArgumentIndex(Idx)))
523523
continue;
524524

525525
// TODO: Allocators should receive the correct size and possibly alignment,

clang/test/Analysis/temporaries.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -1231,3 +1231,19 @@ S bar3(int coin) {
12311231
return coin ? S() : foo(); // no-warning
12321232
}
12331233
} // namespace return_from_top_frame
1234+
1235+
#if __cplusplus >= 201103L
1236+
namespace arguments_of_operators {
1237+
struct S {
1238+
S() {}
1239+
S(const S &) {}
1240+
};
1241+
1242+
void test() {
1243+
int x = 0;
1244+
auto foo = [](S s, int &y) { y = 1; };
1245+
foo(S(), x);
1246+
clang_analyzer_eval(x == 1); // expected-warning{{TRUE}}
1247+
}
1248+
} // namespace arguments_of_operators
1249+
#endif // __cplusplus >= 201103L

0 commit comments

Comments
 (0)