]> granicus.if.org Git - clang/commitdiff
[OPENMP] Do not consider address constant vars as possibly
authorAlexey Bataev <a.bataev@hotmail.com>
Mon, 25 Jun 2018 15:32:05 +0000 (15:32 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Mon, 25 Jun 2018 15:32:05 +0000 (15:32 +0000)
threadprivate.

Do not delay emission of the address constant variables in OpenMP mode
as they cannot be defined as threadprivate.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335483 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/OpenMP/constexpr_codegen.cpp [new file with mode: 0644]

index 6595694ebd533e6a8c3ab92ffa033037d21ac3b2..5a2f2a01d39ecb86d239b9dcf36f6f7b20670966 100644 (file)
@@ -1914,7 +1914,8 @@ bool CodeGenModule::MayBeEmittedEagerly(const ValueDecl *Global) {
   // If OpenMP is enabled and threadprivates must be generated like TLS, delay
   // codegen for global variables, because they may be marked as threadprivate.
   if (LangOpts.OpenMP && LangOpts.OpenMPUseTLS &&
-      getContext().getTargetInfo().isTLSSupported() && isa<VarDecl>(Global))
+      getContext().getTargetInfo().isTLSSupported() && isa<VarDecl>(Global) &&
+      !isTypeConstant(Global->getType(), false))
     return false;
 
   return true;
diff --git a/test/OpenMP/constexpr_codegen.cpp b/test/OpenMP/constexpr_codegen.cpp
new file mode 100644 (file)
index 0000000..f1fa4ac
--- /dev/null
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -verify -fopenmp -std=c++11 -triple x86_64-unknown-unknown -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
+
+// RUN: %clang_cc1 -verify -fopenmp-simd -std=c++11 -triple x86_64-unknown-unknown -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY1 %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s
+// SIMD-ONLY1-NOT: {{__kmpc|__tgt}}
+
+// expected-no-diagnostics
+//
+#ifndef HEADER
+#define HEADER
+
+// CHECK: @{{.*}}Foo{{.*}}bar{{.*}} = constant i32 1,
+
+// Section A - Define a class with a static constexpr data member.
+struct Foo {
+  static constexpr int bar = 1;
+};
+
+// Section B - ODR-use the data member.
+void F(const int &);
+void Test() { F(Foo::bar); }
+
+// Section C - Define the data member.
+constexpr int Foo::bar;
+#endif
+