Skip to content

[cherry-pick swift/release/6.0][clang][headers] Including stddef.h always redefines NULL #9003

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

Conversation

ian-twilightcoder
Copy link

stddef.h always includes __stddef_null.h. This is fine in modules because it's not possible to re-include the pcm, and it's necessary to export the _Builtin_stddef.null submodule. However, without modules it causes NULL to always get redefined which disrupts some C++ code. Rework the inclusion of __stddef_null.h so that with not building with modules it's only included if __need_NULL is set by the includer, or it's the first time stddef.h is being included.

rdar://131450006

…ways redefines NULL

stddef.h always includes __stddef_null.h. This is fine in modules because it's not possible to re-include the pcm, and it's necessary to export the _Builtin_stddef.null submodule. However, without modules it causes NULL to always get redefined which disrupts some C++ code. Rework the inclusion of __stddef_null.h so that with not building with modules it's only included if __need_NULL is set by the includer, or it's the first time stddef.h is being included.

rdar://131450006
@ian-twilightcoder
Copy link
Author

@swift-ci test

@ian-twilightcoder
Copy link
Author

Explanation: This fixes a regression from llvm#90676 where including <stddef.h> multiple times will overwrite the declaration of NULL. This breaks compiling gcc with clang.
Radar (and possibly SR Issue): rdar://131450006
Scope: This affects code that defines their own version of NULL, and then includes <stddef.h>.
Risk: None anticipated, this restores the previous behavior where NULL only gets redefined when __need_NULL is set by the includer.
Testing: Local testing, CI.
Reviewed By: Aaron Ballman (AaronBallman)

@ian-twilightcoder
Copy link
Author

@swift-ci test llvm

@cyndyishida cyndyishida requested a review from fredriss July 23, 2024 23:47
@ian-twilightcoder
Copy link
Author

LLVM test failures look unrelated. Several clang: error: unknown argument '-emit-llvm-only'; did you mean '-Xclang -emit-llvm-only'? ones and then ExtractAPI/enum.c is failing but that looks unrelated too.

@fredriss fredriss merged commit b8858da into swiftlang:swift/release/6.0 Jul 24, 2024
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants