-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[clang] __STDC_NO_THREADS__ is no longer necessary for VS 2022 1939 and above #117149
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
[clang] __STDC_NO_THREADS__ is no longer necessary for VS 2022 1939 and above #117149
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang Author: Dipesh Sharma (dipeshs809) ChangesSince
Closes #115529 Full diff: https://github.com/llvm/llvm-project/pull/117149.diff 2 Files Affected:
diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h
index 949c8f5d448bcf..114a5d34a008bd 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -144,6 +144,7 @@ class LangOptionsBase {
MSVC2019_5 = 1925,
MSVC2019_8 = 1928,
MSVC2022_3 = 1933,
+ MSVC2022_9 = 1939,
};
enum SYCLMajorVersion {
diff --git a/clang/lib/Basic/Targets/OSTargets.cpp b/clang/lib/Basic/Targets/OSTargets.cpp
index 88c054150ab224..f8d974e9979e4d 100644
--- a/clang/lib/Basic/Targets/OSTargets.cpp
+++ b/clang/lib/Basic/Targets/OSTargets.cpp
@@ -248,8 +248,19 @@ static void addVisualCDefines(const LangOptions &Opts, MacroBuilder &Builder) {
Builder.defineMacro("_KERNEL_MODE");
Builder.defineMacro("_INTEGRAL_MAX_BITS", "64");
- Builder.defineMacro("__STDC_NO_THREADS__");
-
+ // Define __STDC_NO_THREADS__ based on MSVC version, threads.h availability,
+ // and language standard.
+ if (!Opts.isCompatibleWithMSVC(LangOptions::MSVC2022_9)) {
+ Builder.defineMacro("__STDC_NO_THREADS__");
+ } else {
+#if defined(__has_include) && !__has_include(<threads.h>)
+ Builder.defineMacro("__STDC_NO_THREADS__");
+#endif
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L
+ Builder.defineMacro("__STDC_NO_THREADS__");
+#endif
+ }
+ // Builder.defineMacro("__STDC_NO_THREADS__");
// Starting with VS 2022 17.1, MSVC predefines the below macro to inform
// users of the execution character set defined at compile time.
// The value given is the Windows Code Page Identifier:
|
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.
Thank you for working on this! Please be sure to add some test coverage for the changes to clang/test/Headers
and a release note in clang/docs/ReleaseNotes.rst
.
#if defined(__has_include) && !__has_include(<threads.h>) | ||
Builder.defineMacro("__STDC_NO_THREADS__"); | ||
#endif | ||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ < 201112L | ||
Builder.defineMacro("__STDC_NO_THREADS__"); | ||
#endif |
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.
These changes are looking at the host compiler's behavior when building Clang, not the state of the system on which Clang is running, so they won't do what you expect.
Trying to determine if the system has a threads.h header on the search path is possible, but would be really tricky to do from here because this function doesn't have access to what's needed to do that work.
As for checking for C11, that can be done via !Opts.C11
Thanks for the review. I'll incorporate the changes suggested and come back to you. |
a8dfbec
to
c55e4ee
Compare
8d1758e
to
76a484f
Compare
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.
I found a few minor nits, but I think we're pretty close!
clang/test/Preprocessor/depricate-threads-macro-defination-msvc1939.c
Outdated
Show resolved
Hide resolved
clang/test/Preprocessor/depricate-threads-macro-defination-msvc1939.c
Outdated
Show resolved
Hide resolved
clang/test/Preprocessor/depricate-threads-macro-defination-msvc1939.c
Outdated
Show resolved
Hide resolved
clang/test/Preprocessor/depricate-threads-macro-defination-msvc1939.c
Outdated
Show resolved
Hide resolved
76a484f
to
e89b89f
Compare
@AaronBallman Thanks for reviewing the PR, have incorporated the changes. |
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.
LGTM thank you for the fix!
@dipeshs809 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Since
__STDC_NO_THREADS__
is a reserved identifier,MSVC version < 17.9
<threads.h>
is unavailable!__has_include(<threads.h>)
is__has_include
is defined.Closes #115529