Skip to content

Commit 45b360d

Browse files
authored
[clang] Disable C++14 sized deallocation by default for MinGW targets (#97232)
This reverts 130e93c for the MinGW target. This avoids the issue that is discussed in #96899 (and which is summarized in the code comment). This is intended as a temporary workaround until the issue is handled better within libc++.
1 parent 938cbdb commit 45b360d

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

clang/lib/Driver/ToolChains/MinGW.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,30 @@ void toolchains::MinGW::addClangTargetOptions(
726726
}
727727
}
728728

729+
// Default to not enabling sized deallocation, but let user provided options
730+
// override it.
731+
//
732+
// If using sized deallocation, user code that invokes delete will end up
733+
// calling delete(void*,size_t). If the user wanted to override the
734+
// operator delete(void*), there may be a fallback operator
735+
// delete(void*,size_t) which calls the regular operator delete(void*).
736+
//
737+
// However, if the C++ standard library is linked in the form of a DLL,
738+
// and the fallback operator delete(void*,size_t) is within this DLL (which is
739+
// the case for libc++ at least) it will only redirect towards the library's
740+
// default operator delete(void*), not towards the user's provided operator
741+
// delete(void*).
742+
//
743+
// This issue can be avoided, if the fallback operators are linked statically
744+
// into the callers, even if the C++ standard library is linked as a DLL.
745+
//
746+
// This is meant as a temporary workaround until libc++ implements this
747+
// technique, which is tracked in
748+
// https://github.com/llvm/llvm-project/issues/96899.
749+
if (!DriverArgs.hasArgNoClaim(options::OPT_fsized_deallocation,
750+
options::OPT_fno_sized_deallocation))
751+
CC1Args.push_back("-fno-sized-deallocation");
752+
729753
CC1Args.push_back("-fno-use-init-array");
730754

731755
for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,

clang/unittests/StaticAnalyzer/CallEventTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ TEST(CXXDeallocatorCall, SimpleDestructor) {
7676
}
7777
)",
7878
Diags));
79-
#if defined(_AIX) || defined(__MVS__)
80-
// AIX and ZOS default to -fno-sized-deallocation.
79+
#if defined(_AIX) || defined(__MVS__) || defined(__MINGW32__)
80+
// AIX, ZOS and MinGW default to -fno-sized-deallocation.
8181
EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 1\n");
8282
#else
8383
EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 2\n");

0 commit comments

Comments
 (0)