[PATCH] D91747: [Clang] Add __STDCPP_THREADS__ to standard predefine macros
Zequan Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 19 17:07:59 PST 2020
zequanwu updated this revision to Diff 306561.
zequanwu added a comment.
Add a test case.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91747/new/
https://reviews.llvm.org/D91747
Files:
clang/include/clang/Frontend/FrontendOptions.h
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/CXX/cpp/cpp.predefined/p2.cpp
clang/test/Preprocessor/init-aarch64.c
Index: clang/test/Preprocessor/init-aarch64.c
===================================================================
--- clang/test/Preprocessor/init-aarch64.c
+++ clang/test/Preprocessor/init-aarch64.c
@@ -233,6 +233,7 @@
// AARCH64-NEXT: #define __SIZE_TYPE__ long unsigned int
// AARCH64-NEXT: #define __SIZE_WIDTH__ 64
// AARCH64_CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+// AARCH64_CXX: #define __STDCPP_THREADS__ 1
// AARCH64-NEXT: #define __STDC_HOSTED__ 1
// AARCH64-NEXT: #define __STDC_UTF_16__ 1
// AARCH64-NEXT: #define __STDC_UTF_32__ 1
Index: clang/test/CXX/cpp/cpp.predefined/p2.cpp
===================================================================
--- /dev/null
+++ clang/test/CXX/cpp/cpp.predefined/p2.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 %s -verify
+// expected-no-diagnostics
+
+#ifndef __STDCPP_THREADS__
+#error __STDCPP_THREADS__ is not defined
+#endif
Index: clang/lib/Frontend/InitPreprocessor.cpp
===================================================================
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -403,6 +403,12 @@
Builder.defineMacro("__STDCPP_DEFAULT_NEW_ALIGNMENT__",
Twine(TI.getNewAlign() / TI.getCharWidth()) +
TI.getTypeConstantSuffix(TI.getSizeType()));
+
+ // -- __STDCPP_THREADS__
+ // Defined, and has the value integer literal 1, if and only if a
+ // program can have more than one thread of execution.
+ if (!FEOpts.IsSingleThreadModel)
+ Builder.defineMacro("__STDCPP_THREADS__", "1");
}
// In C11 these are environment macros. In C++11 they are only defined
Index: clang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2027,6 +2027,8 @@
Opts.IncludeTimestamps = !Args.hasArg(OPT_fno_pch_timestamp);
Opts.UseTemporary = !Args.hasArg(OPT_fno_temp_file);
Opts.IsSystemModule = Args.hasArg(OPT_fsystem_module);
+ Opts.IsSingleThreadModel =
+ Args.getLastArgValue(OPT_mthread_model, "") == "single";
if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
Index: clang/include/clang/Frontend/FrontendOptions.h
===================================================================
--- clang/include/clang/Frontend/FrontendOptions.h
+++ clang/include/clang/Frontend/FrontendOptions.h
@@ -303,6 +303,9 @@
/// When using -emit-module, treat the modulemap as a system module.
unsigned IsSystemModule : 1;
+ /// Wheather using -mthread-model single.
+ unsigned IsSingleThreadModel : 1;
+
CodeCompleteOptions CodeCompleteOpts;
/// Specifies the output format of the AST.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91747.306561.patch
Type: text/x-patch
Size: 2863 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201120/0823dc82/attachment.bin>
More information about the cfe-commits
mailing list