r374057 - [OPENMP50]Allow functions in declare variant directive to have different
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 8 07:56:20 PDT 2019
Author: abataev
Date: Tue Oct 8 07:56:20 2019
New Revision: 374057
URL: http://llvm.org/viewvc/llvm-project?rev=374057&view=rev
Log:
[OPENMP50]Allow functions in declare variant directive to have different
C linkage.
After some discussion with OpenMP developers, it was decided that the
functions with the different C linkage can be used in declare variant
directive.
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/declare_variant_ast_print.cpp
cfe/trunk/test/OpenMP/declare_variant_implementation_vendor_codegen.cpp
cfe/trunk/test/OpenMP/declare_variant_messages.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=374057&r1=374056&r2=374057&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Oct 8 07:56:20 2019
@@ -9128,7 +9128,7 @@ public:
const PartialDiagnosticAt &NoteCausedDiagIDAt,
const PartialDiagnosticAt &NoSupportDiagIDAt,
const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported,
- bool ConstexprSupported);
+ bool ConstexprSupported, bool CLinkageMayDiffer);
/// Function tries to capture lambda's captured variables in the OpenMP region
/// before the original lambda is captured.
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=374057&r1=374056&r2=374057&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Oct 8 07:56:20 2019
@@ -9685,7 +9685,7 @@ bool Sema::areMultiversionVariantFunctio
const PartialDiagnosticAt &NoteCausedDiagIDAt,
const PartialDiagnosticAt &NoSupportDiagIDAt,
const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported,
- bool ConstexprSupported) {
+ bool ConstexprSupported, bool CLinkageMayDiffer) {
enum DoesntSupport {
FuncTemplates = 0,
VirtFuncs = 1,
@@ -9778,7 +9778,7 @@ bool Sema::areMultiversionVariantFunctio
if (OldFD->getStorageClass() != NewFD->getStorageClass())
return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << StorageClass;
- if (OldFD->isExternC() != NewFD->isExternC())
+ if (!CLinkageMayDiffer && OldFD->isExternC() != NewFD->isExternC())
return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << Linkage;
if (CheckEquivalentExceptionSpec(
@@ -9831,7 +9831,8 @@ static bool CheckMultiVersionAdditionalR
PartialDiagnosticAt(NewFD->getLocation(),
S.PDiag(diag::err_multiversion_diff)),
/*TemplatesSupported=*/false,
- /*ConstexprSupported=*/!IsCPUSpecificCPUDispatchMVType);
+ /*ConstexprSupported=*/!IsCPUSpecificCPUDispatchMVType,
+ /*CLinkageMayDiffer=*/false);
}
/// Check the validity of a multiversion function declaration that is the
Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=374057&r1=374056&r2=374057&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue Oct 8 07:56:20 2019
@@ -5109,7 +5109,8 @@ Sema::checkOpenMPDeclareVariantFunction(
PartialDiagnosticAt(VariantRef->getExprLoc(),
PDiag(diag::err_omp_declare_variant_diff)
<< FD->getLocation()),
- /*TemplatesSupported=*/true, /*ConstexprSupported=*/false))
+ /*TemplatesSupported=*/true, /*ConstexprSupported=*/false,
+ /*CLinkageMayDiffer=*/true))
return None;
return std::make_pair(FD, cast<Expr>(DRE));
}
Modified: cfe/trunk/test/OpenMP/declare_variant_ast_print.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_variant_ast_print.cpp?rev=374057&r1=374056&r2=374057&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/declare_variant_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_variant_ast_print.cpp Tue Oct 8 07:56:20 2019
@@ -201,3 +201,22 @@ void bazzzz() {
s.foo1();
static_f();
}
+
+// CHECK: int fn_linkage_variant();
+// CHECK: extern "C" {
+// CHECK: #pragma omp declare variant(fn_linkage_variant) match(implementation={vendor(xxx)})
+// CHECK: int fn_linkage();
+// CHECK: }
+int fn_linkage_variant();
+extern "C" {
+#pragma omp declare variant(fn_linkage_variant) match(implementation = {vendor(xxx)})
+int fn_linkage();
+}
+
+// CHECK: extern "C" int fn_linkage_variant1()
+// CHECK: #pragma omp declare variant(fn_linkage_variant1) match(implementation={vendor(xxx)})
+// CHECK: int fn_linkage1();
+extern "C" int fn_linkage_variant1();
+#pragma omp declare variant(fn_linkage_variant1) match(implementation = {vendor(xxx)})
+int fn_linkage1();
+
Modified: cfe/trunk/test/OpenMP/declare_variant_implementation_vendor_codegen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_variant_implementation_vendor_codegen.cpp?rev=374057&r1=374056&r2=374057&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/declare_variant_implementation_vendor_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_variant_implementation_vendor_codegen.cpp Tue Oct 8 07:56:20 2019
@@ -22,6 +22,8 @@
// CHECK-DAG: ret i32 7
// CHECK-DAG: ret i32 82
// CHECK-DAG: ret i32 83
+// CHECK-DAG: ret i32 85
+// CHECK-DAG: ret i32 86
// CHECK-NOT: ret i32 {{1|4|81|84}}
#ifndef HEADER
@@ -110,4 +112,14 @@ static int prio1_() { return 1; }
int int_fn() { return prio1_(); }
+int fn_linkage_variant() { return 85; }
+extern "C" {
+#pragma omp declare variant(fn_linkage_variant) match(implementation = {vendor(llvm)})
+int fn_linkage() { return 1; }
+}
+
+extern "C" int fn_linkage_variant1() { return 86; }
+#pragma omp declare variant(fn_linkage_variant1) match(implementation = {vendor(llvm)})
+int fn_linkage1() { return 1; }
+
#endif // HEADER
Modified: cfe/trunk/test/OpenMP/declare_variant_messages.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_variant_messages.cpp?rev=374057&r1=374056&r2=374057&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/declare_variant_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_variant_messages.cpp Tue Oct 8 07:56:20 2019
@@ -165,18 +165,6 @@ inline int fn_inline_variant1();
#pragma omp declare variant(fn_inline_variant1) match(xxx = {})
int fn_inline1();
-int fn_linkage_variant();
-extern "C" {
-// expected-error at +1 {{function with '#pragma omp declare variant' has a different linkage}}
-#pragma omp declare variant(fn_linkage_variant) match(xxx = {})
-int fn_linkage();
-}
-
-extern "C" int fn_linkage_variant1();
-// expected-error at +1 {{function with '#pragma omp declare variant' has a different linkage}}
-#pragma omp declare variant(fn_linkage_variant1) match(xxx = {})
-int fn_linkage1();
-
auto fn_deduced_variant() { return 0; }
#pragma omp declare variant(fn_deduced_variant) match(xxx = {})
int fn_deduced();
More information about the cfe-commits
mailing list