[clang] 45b360d - [clang] Disable C++14 sized deallocation by default for MinGW targets (#97232)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 1 14:03:18 PDT 2024


Author: Martin Storsjö
Date: 2024-07-02T00:03:15+03:00
New Revision: 45b360d4a2c751dd5afa0c676e2badf46cd29f01

URL: https://github.com/llvm/llvm-project/commit/45b360d4a2c751dd5afa0c676e2badf46cd29f01
DIFF: https://github.com/llvm/llvm-project/commit/45b360d4a2c751dd5afa0c676e2badf46cd29f01.diff

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

This reverts 130e93cc26ca9d3ac50ec5a92e3109577ca2e702 for the MinGW
target.

This avoids the issue that is discussed in
https://github.com/llvm/llvm-project/issues/96899 (and which is
summarized in the code comment). This is intended as a temporary
workaround until the issue is handled better within libc++.

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/MinGW.cpp
    clang/unittests/StaticAnalyzer/CallEventTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp
index 11e81ebde7eeb..c81a7ed170296 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -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,

diff  --git a/clang/unittests/StaticAnalyzer/CallEventTest.cpp b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
index 987162f9fdf34..d5ca72acaca29 100644
--- a/clang/unittests/StaticAnalyzer/CallEventTest.cpp
+++ b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
@@ -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");


        


More information about the cfe-commits mailing list