diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp index ff07402a29bba..92ce3fa2225c8 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp @@ -10,7 +10,6 @@ // //===----------------------------------------------------------------------===// -#include "clang/AST/ASTContext.h" #include "clang/AST/AttrIterator.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/ParentMap.h" @@ -716,11 +715,7 @@ void ExprEngine::handleConstructor(const Expr *E, // actually make things worse. Placement new makes this tricky as well, // since it's then possible to be initializing one part of a multi- // dimensional array. - const CXXRecordDecl *TargetHeldRecord = - cast(CE->getType()->getAsRecordDecl()); - - if (!TargetHeldRecord || !TargetHeldRecord->isEmpty()) - State = State->bindDefaultZero(Target, LCtx); + State = State->bindDefaultZero(Target, LCtx); } Bldr.generateNode(CE, N, State, /*tag=*/nullptr, diff --git a/clang/test/Analysis/issue-137252.cpp b/clang/test/Analysis/issue-137252.cpp deleted file mode 100644 index 6ca3e20ccbbca..0000000000000 --- a/clang/test/Analysis/issue-137252.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus -verify %s -// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus -verify %s -DEMPTY_CLASS -// UNSUPPORTED: system-windows -// expected-no-diagnostics - -// This test reproduces the issue that previously the static analyzer -// initialized an [[no_unique_address]] empty field to zero, -// over-writing a non-empty field with the same offset. - -namespace std { -#ifdef EMPTY_CLASS - - struct default_delete {}; - template -#else - // Class with methods and static members is still empty: - template - class default_delete { - T dump(); - static T x; - }; - template > -#endif - class unique_ptr { - [[no_unique_address]] _Tp * __ptr_; - [[no_unique_address]] _Dp __deleter_; - - public: - explicit unique_ptr(_Tp* __p) noexcept - : __ptr_(__p), - __deleter_() {} - - ~unique_ptr() { - delete __ptr_; - } - }; -} - -struct X {}; - -int main() -{ - // Previously a leak falsely reported here. It was because the - // Static Analyzer engine simulated the initialization of - // `__deleter__` incorrectly. The engine assigned zero to - // `__deleter__`--an empty record sharing offset with `__ptr__`. - // The assignment over wrote `__ptr__`. - std::unique_ptr a(new X()); - return 0; -}