[OpenCL] __cpp_threadsafe_static_init is by default undefined in OpenCL mode.

Definition of `__cpp_threadsafe_static_init` macro is controlled by
language option Opts.ThreadsafeStatics. This patch sets language
option to false by default in OpenCL mode, resulting in macro
`__cpp_threadsafe_static_init` being undefined. Default value can be
overridden using command line option -fthreadsafe-statics.

Change is supposed to address portability because not all OpenCL
vendors support thread safe implementation of static initialization.

Fixes llvm.org/PR48012

Differential Revision: https://reviews.llvm.org/D107163
This commit is contained in:
Justas Janickas 2021-07-27 12:21:35 +01:00
parent cd2387b56d
commit b13fc7311e
2 changed files with 13 additions and 1 deletions

View File

@ -6192,7 +6192,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// than 19.
if (!Args.hasFlag(options::OPT_fthreadsafe_statics,
options::OPT_fno_threadsafe_statics,
!IsWindowsMSVC || IsMSVC2015Compatible))
!types::isOpenCL(InputType) &&
(!IsWindowsMSVC || IsMSVC2015Compatible)))
CmdArgs.push_back("-fno-threadsafe-statics");
// -fno-delayed-template-parsing is default, except when targeting MSVC.

View File

@ -0,0 +1,11 @@
// RUN: %clang -### -c -DNO_THREADSAFE_STATICS %s 2>&1 | FileCheck --check-prefix=CHECK-NO-THREADSAFE-STATICS %s
// RUN: %clang -### -fno-threadsafe-statics -DNO_THREADSAFE_STATICS -c %s 2>&1 | FileCheck --check-prefix=CHECK-NO-THREADSAFE-STATICS %s
// CHECK-NO-THREADSAFE-STATICS: "-cc1"
// CHECK-NO-THREADSAFE-STATICS: "-fno-threadsafe-statics"
// CHECK-NO-THREADSAFE-STATICS-NOT: "-fthreadsafe-statics"
// RUN: %clang -### -fthreadsafe-statics -DTHREADSAFE_STATICS -c %s 2>&1 | FileCheck --check-prefix=CHECK-THREADSAFE-STATICS %s
// CHECK-THREADSAFE-STATICS: "-cc1"
// CHECK-THREADSAFE-STATICS-NOT: "-fno-threadsafe-statics"