-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Headers: prefer corecrt_malloc.h
to malloc.h
#131668
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-platform-windows @llvm/pr-subscribers-backend-x86 Author: Saleem Abdulrasool (compnerd) ChangesThis allows us to target a lower level library (corecrt) rather than the higher level library (ucrt) which can be helpful in mordularising the SDK. Full diff: https://github.com/llvm/llvm-project/pull/131668.diff 1 Files Affected:
diff --git a/clang/lib/Headers/mm_malloc.h b/clang/lib/Headers/mm_malloc.h
index d32fe59416277..4052995fff5cd 100644
--- a/clang/lib/Headers/mm_malloc.h
+++ b/clang/lib/Headers/mm_malloc.h
@@ -13,7 +13,7 @@
#include <stdlib.h>
#ifdef _WIN32
-#include <malloc.h>
+#include <corecrt_malloc.h>
#else
#ifndef __cplusplus
extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
|
This allows us to target a lower level library (corecrt) rather than the higher level library (ucrt) which can be helpful in modularising the SDK.
You can test this locally with the following command:git-clang-format --diff 2e6402ca2c6c33ccf41d74383a8e3afb82489410 8415be6e59aa2f8a23a3e484b1c8053f4d0c7206 --extensions h -- clang/lib/Headers/mm_malloc.h View the diff from clang-format here.diff --git a/clang/lib/Headers/mm_malloc.h b/clang/lib/Headers/mm_malloc.h
index addb598f62..93c98bae27 100644
--- a/clang/lib/Headers/mm_malloc.h
+++ b/clang/lib/Headers/mm_malloc.h
@@ -13,11 +13,11 @@
#include <stdlib.h>
#ifdef _WIN32
-# if defined(__MINGW32__)
-# include <malloc.h>
-# else
-# include <corecrt_malloc.h>
-# endif
+#if defined(__MINGW32__)
+#include <malloc.h>
+#else
+#include <corecrt_malloc.h>
+#endif
#else
#ifndef __cplusplus
extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok to me.
I don't know about whether this really works as expected with corecrt_malloc.h
or not, but I would expect you to have tested it.
We could look into adding corecrt_malloc.h
in mingw-w64 as well, and then we could simplify this after a couple of years maybe.
Right. I'm not 100% certain if it fully solves the issue that I am encountering yet, however, this seems like a good thing to do nonetheless. The header inclusion is present to avoid forward declaring _ACRTIMP
void __cdecl _aligned_free(
_Pre_maybenull_ _Post_invalid_ void* _Block
);
_Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size)
_ACRTIMP _CRTALLOCATOR _CRTRESTRICT
void* __cdecl _aligned_malloc(
_In_ _CRT_GUARDOVERFLOW size_t _Size,
_In_ size_t _Alignment
); It is easy for us to miss some of the annotations as corecrt evolves which is why the header inclusion is preferable to retain if we can manage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI failure on Windows looks potentially related. Also, can you validate that this change actually solves the issue for you regarding modules?
I don't think that this fully fixes the issue as it doesn't completely break the cycle. |
This allows us to target a lower level library (corecrt) rather than the higher level library (ucrt) which can be helpful in mordularising the SDK.