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

Conversation

mstorsjo
Copy link
Member

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++.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Jun 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 30, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Martin Storsjö (mstorsjo)

Changes

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++.


Full diff: https://github.com/llvm/llvm-project/pull/97232.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/MinGW.cpp (+22)
  • (modified) clang/unittests/StaticAnalyzer/CallEventTest.cpp (+4)
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp
index 11e81ebde7eeb..945863a4a8d63 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -726,6 +726,28 @@ 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 7c4132788ca7e..ba5b3e4e05ad8 100644
--- a/clang/unittests/StaticAnalyzer/CallEventTest.cpp
+++ b/clang/unittests/StaticAnalyzer/CallEventTest.cpp
@@ -76,7 +76,11 @@ TEST(CXXDeallocatorCall, SimpleDestructor) {
     }
   )",
                                                          Diags));
+#ifdef __MINGW32__
+  EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 1\n");
+#else
   EXPECT_EQ(Diags, "test.CXXDeallocator: NumArgs: 2\n");
+#endif
 }
 
 } // namespace

Copy link

github-actions bot commented Jun 30, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@mstorsjo mstorsjo force-pushed the clang-no-sized-dealloc-mingw branch from 424eb0f to bc68b1b Compare June 30, 2024 21:05
This reverts 130e93c for the
MinGW target.

This avoids the issue that is discussed in
llvm#96899 (and which is
summarized in the code comment). This is intended as a temporary
workaround until the issue is handled better within libc++.
@mstorsjo mstorsjo force-pushed the clang-no-sized-dealloc-mingw branch from bc68b1b to a70379a Compare July 1, 2024 20:43
@mstorsjo mstorsjo merged commit 45b360d into llvm:main Jul 1, 2024
4 of 6 checks passed
@mstorsjo mstorsjo deleted the clang-no-sized-dealloc-mingw branch July 1, 2024 21:03
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 1, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-ubuntu-fast running on sie-linux-worker while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/1360

Here is the relevant piece of the build log for the reference:

Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: MC/MachO/empty-twice.ll' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
b'\xcf\xfa\xed\xfe\x07\x00\x00\x01\x03\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\xd8\x01\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\xd8\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x000\x01\x00\x00\x00\x00\x00\x00\xf8\x01\x00\x00\x00\x00\x00\x000\x01\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x07\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00__text\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00__TEXT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x98\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x90\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00__apple_names\x00\x00\x00__DWARF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x98\x00\x00\x00\x00\x00\x00\x00$\x00\x00\x00\x00\x00\x00\x00\x90\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00__apple_objc\x00\x00\x00\x00__DWARF\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbc\x00\x00\x00\x00\x00\x00\x00$\x00\x00\x00\x00\x00\x00\x00\xb4\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00__apple_namespac__DWARF\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0\x00\x00\x00\x00\x00\x00\x00$\x00\x00\x00\x00\x00\x00\x00\xd8\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00__apple_types\x00\x00\x00__DWARF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x00\x00\x00\x00,\x00\x00\x00\x00\x00\x00\x00\xfc\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00HSAH\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x06\x00\xff\xff\xff\xffHSAH\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x06\x00\xff\xff\xff\xffHSAH\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x06\x00\xff\xff\xff\xffHSAH\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x01\x00\x06\x00\x03\x00\x05\x00\x04\x00\x0b\x00\xff\xff\xff\xff'
--
Command Output (stderr):
--
RUN: at line 3: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc -mtriple=x86_64-apple-darwin -compile-twice -filetype=obj /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/MC/MachO/empty-twice.ll -o -
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc -mtriple=x86_64-apple-darwin -compile-twice -filetype=obj /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/MC/MachO/empty-twice.ll -o -
Running the pass manager twice changed the output.
Writing the result of the second run to the specified output
To generate the one-run comparison binary, just run without
the compile-twice option

--

********************


lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
…llvm#97232)

This reverts 130e93c for the MinGW
target.

This avoids the issue that is discussed in
llvm#96899 (and which is
summarized in the code comment). This is intended as a temporary
workaround until the issue is handled better within libc++.
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
…llvm#97232)

This reverts 130e93c for the MinGW
target.

This avoids the issue that is discussed in
llvm#96899 (and which is
summarized in the code comment). This is intended as a temporary
workaround until the issue is handled better within libc++.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants