- Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang-cl] Support /std:clatest #147284
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-cl] Support /std:clatest #147284
Conversation
cl.exe has /stdc:latest, analogous to /stdc++:latest, which sets the language mode to the latest standard. For C, that's C23. This adds support for the option. Fixes llvm#147233
| @llvm/pr-subscribers-clang-driver Author: Aaron Ballman (AaronBallman) Changescl.exe has /stdc:latest, analogous to /stdc++:latest, which sets the language mode to the latest standard. For C, that's C23. This adds support for the option. Fixes #147233 Full diff: https://github.com/llvm/llvm-project/pull/147284.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3d893e0aa8e2c..2052b43f48070 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -248,7 +248,9 @@ C Language Changes not valid in C++. - The ``[[clang::assume()]]`` attribute is now correctly recognized in C. The ``__attribute__((assume()))`` form has always been supported, so the fix is - specific to the attribute syntax used. + specific to the attribute syntax used.' +- The ``clang-cl`` driver now recognizes ``/stdc:latest`` and sets the language + mode to C23. #GH147233 C2y Feature Support ^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index fea4ee909ff46..8a30b7ea8144a 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7201,6 +7201,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, LanguageStandard = llvm::StringSwitch<StringRef>(StdArg->getValue()) .Case("c11", "-std=c11") .Case("c17", "-std=c17") + // TODO: add c23 when MSVC supports it. + .Case("clatest", "-std=c23") .Default(""); if (LanguageStandard.empty()) D.Diag(clang::diag::warn_drv_unused_argument) diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c index eb079895a0a88..57e16e8795a28 100644 --- a/clang/test/Driver/cl-options.c +++ b/clang/test/Driver/cl-options.c @@ -362,6 +362,12 @@ // RUN: %clang_cl -c -### /std:c11 -- %s 2>&1 | FileCheck -check-prefix CHECK-C11 %s // CHECK-C11: -std=c11 +// RUN: %clang_cl -c -### /std:c17 -- %s 2>&1 | FileCheck -check-prefix CHECK-C17 %s +// CHECK-C17: -std=c17 + +// RUN: %clang_cl -c -### /std:clatest -- %s 2>&1 | FileCheck -check-prefix CHECK-CLATEST %s +// CHECK-CLATEST: -std=c23 + // For some warning ids, we can map from MSVC warning to Clang warning. // RUN: %clang_cl -wd4005 -wd4100 -wd4910 -wd4996 -wd12345678 -### -- %s 2>&1 | FileCheck -check-prefix=Wno %s // Wno: "-cc1" |
| @llvm/pr-subscribers-clang Author: Aaron Ballman (AaronBallman) Changescl.exe has /stdc:latest, analogous to /stdc++:latest, which sets the language mode to the latest standard. For C, that's C23. This adds support for the option. Fixes #147233 Full diff: https://github.com/llvm/llvm-project/pull/147284.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3d893e0aa8e2c..2052b43f48070 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -248,7 +248,9 @@ C Language Changes not valid in C++. - The ``[[clang::assume()]]`` attribute is now correctly recognized in C. The ``__attribute__((assume()))`` form has always been supported, so the fix is - specific to the attribute syntax used. + specific to the attribute syntax used.' +- The ``clang-cl`` driver now recognizes ``/stdc:latest`` and sets the language + mode to C23. #GH147233 C2y Feature Support ^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index fea4ee909ff46..8a30b7ea8144a 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -7201,6 +7201,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, LanguageStandard = llvm::StringSwitch<StringRef>(StdArg->getValue()) .Case("c11", "-std=c11") .Case("c17", "-std=c17") + // TODO: add c23 when MSVC supports it. + .Case("clatest", "-std=c23") .Default(""); if (LanguageStandard.empty()) D.Diag(clang::diag::warn_drv_unused_argument) diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c index eb079895a0a88..57e16e8795a28 100644 --- a/clang/test/Driver/cl-options.c +++ b/clang/test/Driver/cl-options.c @@ -362,6 +362,12 @@ // RUN: %clang_cl -c -### /std:c11 -- %s 2>&1 | FileCheck -check-prefix CHECK-C11 %s // CHECK-C11: -std=c11 +// RUN: %clang_cl -c -### /std:c17 -- %s 2>&1 | FileCheck -check-prefix CHECK-C17 %s +// CHECK-C17: -std=c17 + +// RUN: %clang_cl -c -### /std:clatest -- %s 2>&1 | FileCheck -check-prefix CHECK-CLATEST %s +// CHECK-CLATEST: -std=c23 + // For some warning ids, we can map from MSVC warning to Clang warning. // RUN: %clang_cl -wd4005 -wd4100 -wd4910 -wd4996 -wd12345678 -### -- %s 2>&1 | FileCheck -check-prefix=Wno %s // Wno: "-cc1" |
| You've got the same typo (?) in a bunch of places. You have |
Good catch! Sheesh, fingers. Work! |
Those are all addressed. This is what I get for typing |
zmodem left a comment
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.
Thanks!
(For my curiosity: seems the flag was added to the MSVC docs in MicrosoftDocs/cpp-docs@0b7e40a)
cl.exe has /std:clatest, analogous to /std:c++latest, which sets the language mode to the latest standard. For C, that's C23. This adds support for the option.
Fixes #147233