r356089 - [OPENMP]Disable ADL in C for user-defined reductions.
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 13 12:31:35 PDT 2019
Author: abataev
Date: Wed Mar 13 12:31:34 2019
New Revision: 356089
URL: http://llvm.org/viewvc/llvm-project?rev=356089&view=rev
Log:
[OPENMP]Disable ADL in C for user-defined reductions.
C does not support ADL, disable it for C to prevent compiler crash.
Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/declare_reduction_messages.c
Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=356089&r1=356088&r2=356089&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Wed Mar 13 12:31:34 2019
@@ -10958,35 +10958,37 @@ buildDeclareReductionRef(Sema &SemaRef,
}
}
// Perform ADL.
- argumentDependentLookup(SemaRef, ReductionId, Loc, Ty, Lookups);
- if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>(
- Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * {
- if (!D->isInvalidDecl() &&
- SemaRef.Context.hasSameType(D->getType(), Ty))
- return D;
- return nullptr;
- }))
- return SemaRef.BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(),
- VK_LValue, Loc);
- if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>(
- Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * {
- if (!D->isInvalidDecl() &&
- SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) &&
- !Ty.isMoreQualifiedThan(D->getType()))
- return D;
- return nullptr;
- })) {
- CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
- /*DetectVirtual=*/false);
- if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) {
- if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType(
- VD->getType().getUnqualifiedType()))) {
- if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(),
- /*DiagID=*/0) !=
- Sema::AR_inaccessible) {
- SemaRef.BuildBasePathArray(Paths, BasePath);
- return SemaRef.BuildDeclRefExpr(
- VD, VD->getType().getNonReferenceType(), VK_LValue, Loc);
+ if (SemaRef.getLangOpts().CPlusPlus) {
+ argumentDependentLookup(SemaRef, ReductionId, Loc, Ty, Lookups);
+ if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>(
+ Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * {
+ if (!D->isInvalidDecl() &&
+ SemaRef.Context.hasSameType(D->getType(), Ty))
+ return D;
+ return nullptr;
+ }))
+ return SemaRef.BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(),
+ VK_LValue, Loc);
+ if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>(
+ Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * {
+ if (!D->isInvalidDecl() &&
+ SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) &&
+ !Ty.isMoreQualifiedThan(D->getType()))
+ return D;
+ return nullptr;
+ })) {
+ CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
+ /*DetectVirtual=*/false);
+ if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) {
+ if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType(
+ VD->getType().getUnqualifiedType()))) {
+ if (SemaRef.CheckBaseClassAccess(
+ Loc, VD->getType(), Ty, Paths.front(),
+ /*DiagID=*/0) != Sema::AR_inaccessible) {
+ SemaRef.BuildBasePathArray(Paths, BasePath);
+ return SemaRef.BuildDeclRefExpr(
+ VD, VD->getType().getNonReferenceType(), VK_LValue, Loc);
+ }
}
}
}
Modified: cfe/trunk/test/OpenMP/declare_reduction_messages.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_reduction_messages.c?rev=356089&r1=356088&r2=356089&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/declare_reduction_messages.c (original)
+++ cfe/trunk/test/OpenMP/declare_reduction_messages.c Wed Mar 13 12:31:34 2019
@@ -41,7 +41,17 @@ int temp; // expected-note 6 {{'temp' de
#pragma omp declare reduction(fun8 : long : omp_out += omp_in) initializer(omp_priv = 23)) // expected-warning {{extra tokens at the end of '#pragma omp declare reduction' are ignored}} expected-error {{redefinition of user-defined reduction for type 'long'}}
#pragma omp declare reduction(fun9 : long : omp_out += omp_in) initializer(omp_priv = ) // expected-error {{expected expression}}
+struct S {
+ int s;
+};
+#pragma omp declare reduction(+: struct S: omp_out.s += omp_in.s) // initializer(omp_priv = { .s = 0 })
+
int fun(int arg) {
+ struct S s;// expected-note {{'s' defined here}}
+ s.s = 0;
+#pragma omp parallel for reduction(+ : s) // expected-error {{list item of type 'struct S' is not valid for specified reduction operation: unable to provide default initialization value}}
+ for (arg = 0; arg < 10; ++arg)
+ s.s += arg;
#pragma omp declare reduction(red : int : omp_out++)
{
#pragma omp declare reduction(red : int : omp_out++) // expected-note {{previous definition is here}}
More information about the cfe-commits
mailing list