Skip to content

[clang] Disable C++14 sized deallocation by default for MinGW targets #97232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions clang/lib/Driver/ToolChains/MinGW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,30 @@ void toolchains::MinGW::addClangTargetOptions(
}
}

// Default to not enabling sized deallocation, but let user provided options
// override it.
//
// If using sized deallocation, user code that invokes delete will end up
// calling delete(void*,size_t). If the user wanted to override the
// operator delete(void*), there may be a fallback operator
// delete(void*,size_t) which calls the regular operator delete(void*).
//
// However, if the C++ standard library is linked in the form of a DLL,
// and the fallback operator delete(void*,size_t) is within this DLL (which is
// the case for libc++ at least) it will only redirect towards the library's
// default operator delete(void*), not towards the user's provided operator
// delete(void*).
//
// This issue can be avoided, if the fallback operators are linked statically
// into the callers, even if the C++ standard library is linked as a DLL.
//
// This is meant as a temporary workaround until libc++ implements this
// technique, which is tracked in
// https://github.com/llvm/llvm-project/issues/96899.
if (!DriverArgs.hasArgNoClaim(options::OPT_fsized_deallocation,
options::OPT_fno_sized_deallocation))
CC1Args.push_back("-fno-sized-deallocation");

CC1Args.push_back("-fno-use-init-array");

for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
Expand Down
4 changes: 2 additions & 2 deletions clang/unittests/StaticAnalyzer/CallEventTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ TEST(CXXDeallocatorCall, SimpleDestructor) {
}
)",
Diags));
#if defined(_AIX) || defined(__MVS__)
// AIX and ZOS default to -fno-sized-deallocation.
#if defined(_AIX) || defined(__MVS__) || defined(__MINGW32__)
// AIX, ZOS and MinGW default to -fno-sized-deallocation.
EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 1\n");
#else
EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 2\n");
Expand Down
Loading