[analyzer] Placement new checker for arrays result in false positive
When placement new is used to create and array of elements at a specific location, a warning is falsely reported.
#include <new>
struct s {
int x;
};
int main() {
s arr[4];
new (arr + 1) s[1];
// ^~~~~~~~~~~
// warning: 12 bytes is possibly not enough for array allocation which requires 4 bytes. Current overhead requires the // size of 8 bytes [cplusplus.PlacementNew]
return 0;
}
The warning is only reported in case of arrays with both trunk and 14.0.0 clang.
Writing new (arr + 1) s doesn't end up with a warning, but new (arr + 1) s[1], new (arr + 1) s[2], etc. all do.
Feel free to check the snippet on godbolt: https://godbolt.org/z/dvz9nqPne. Compile only using --analyze.
@llvm/issue-subscribers-clang-static-analyzer
@martong this is your checker!
https://reviews.llvm.org/D129280
does not show this since 635e6d765303(https://github.com/llvm/llvm-project/pull/150161) due to bisection
I have looked through the issue and the commit in https://github.com/llvm/llvm-project/issues/56264#issuecomment-6208236382. The PR https://github.com/llvm/llvm-project/pull/150161 resolves the underlying issue which led to this ticket as well. https://github.com/llvm/llvm-project/pull/150161 does not add the test case listed in this issue to the test suite, but resolves the bug. I close this as completed.