This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGad9e98b8efa0: [OpenMP] Do not propagate match extensions to nested contexts (authored by jdoerfert). Herald added subscribers: llvm-commits, hiraditya. Herald added a project: LLVM.
Changed prior to commit: https://reviews.llvm.org/D95764?vs=320371&id=330141#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95764/new/ https://reviews.llvm.org/D95764 Files: clang/include/clang/Basic/AttrDocs.td clang/lib/Parse/ParseOpenMP.cpp clang/test/OpenMP/begin_declare_variant_nested_propagation.c llvm/lib/Frontend/OpenMP/OMPContext.cpp Index: llvm/lib/Frontend/OpenMP/OMPContext.cpp =================================================================== --- llvm/lib/Frontend/OpenMP/OMPContext.cpp +++ llvm/lib/Frontend/OpenMP/OMPContext.cpp @@ -168,8 +168,13 @@ // For kind "any" a single match is enough but we ignore non-matched // properties. if (MK == MK_ANY) { - if (WasFound) + if (WasFound) { + LLVM_DEBUG( + dbgs() << "[" << DEBUG_TYPE << "] Property " + << getOpenMPContextTraitPropertyName(Property, "") + << " was in the OpenMP context and match kind is any.\n";); return true; + } return None; } Index: clang/test/OpenMP/begin_declare_variant_nested_propagation.c =================================================================== --- /dev/null +++ clang/test/OpenMP/begin_declare_variant_nested_propagation.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple=x86_64-pc-win32 -verify -fopenmp -x c -std=c99 -fms-extensions -Wno-pragma-pack %s +// expected-no-diagnostics + +#pragma omp begin declare variant match(user={condition(1)}, device={kind(cpu)}, implementation={extension(match_any)}) +#pragma omp begin declare variant match(device = {kind(cpu, fpga)}) + this is never reached +#pragma omp end declare variant +#pragma omp end declare variant + +#pragma omp begin declare variant match(user={condition(1)}, device={kind(cpu)}, implementation={extension(match_any)}) +#pragma omp begin declare variant match(device = {kind(cpu, fpga)}, implementation={vendor(llvm)}) + this is never reached +#pragma omp end declare variant +#pragma omp end declare variant Index: clang/lib/Parse/ParseOpenMP.cpp =================================================================== --- clang/lib/Parse/ParseOpenMP.cpp +++ clang/lib/Parse/ParseOpenMP.cpp @@ -21,6 +21,7 @@ #include "clang/Parse/RAIIObjectsForParser.h" #include "clang/Sema/Scope.h" #include "llvm/ADT/PointerIntPair.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/UniqueVector.h" #include "llvm/Frontend/OpenMP/OMPContext.h" @@ -1463,7 +1464,29 @@ // TODO: Keep some source location in the TI to provide better diagnostics. // TODO: Perform some kind of equivalence check on the condition and score // expressions. - for (const OMPTraitSet &ParentSet : ParentTI->Sets) { + auto StripImplementation = [](const OMPTraitSet &TSet) -> OMPTraitSet { + if (TSet.Kind != llvm::omp::TraitSet::implementation) + return TSet; + OMPTraitSet Set = TSet; + for (OMPTraitSelector &Selector : Set.Selectors) { + if (Selector.Kind != llvm::omp::TraitSelector::implementation_extension) + continue; + // Do not propagate match extensions to nested contexts. + llvm::erase_if(Selector.Properties, [](const OMPTraitProperty &Property) { + return ( + Property.Kind == + llvm::omp::TraitProperty::implementation_extension_match_any || + Property.Kind == + llvm::omp::TraitProperty::implementation_extension_match_all || + Property.Kind == + llvm::omp::TraitProperty::implementation_extension_match_none); + }); + return Set; + } + return Set; + }; + for (const OMPTraitSet &PSet : ParentTI->Sets) { + const OMPTraitSet ParentSet = StripImplementation(PSet); bool MergedSet = false; for (OMPTraitSet &Set : TI.Sets) { if (Set.Kind != ParentSet.Kind) Index: clang/include/clang/Basic/AttrDocs.td =================================================================== --- clang/include/clang/Basic/AttrDocs.td +++ clang/include/clang/Basic/AttrDocs.td @@ -4014,7 +4014,8 @@ match for an OpenMP context. The default is ``all``, with ``none`` no trait in the selector is allowed to be in the OpenMP context, with ``any`` a single trait in both the selector and OpenMP context is sufficient. Only a single match -extension trait is allowed per context selector. +extension trait is allowed per context selector. Note that match extensions are +not propagated to nested selectors like the standard defines it for other traits. The disable extensions remove default effects of the ``begin declare variant`` applied to a definition. If ``disable_implicit_base`` is given, we will not introduce an implicit base function for a variant if no base function was
Index: llvm/lib/Frontend/OpenMP/OMPContext.cpp =================================================================== --- llvm/lib/Frontend/OpenMP/OMPContext.cpp +++ llvm/lib/Frontend/OpenMP/OMPContext.cpp @@ -168,8 +168,13 @@ // For kind "any" a single match is enough but we ignore non-matched // properties. if (MK == MK_ANY) { - if (WasFound) + if (WasFound) { + LLVM_DEBUG( + dbgs() << "[" << DEBUG_TYPE << "] Property " + << getOpenMPContextTraitPropertyName(Property, "") + << " was in the OpenMP context and match kind is any.\n";); return true; + } return None; } Index: clang/test/OpenMP/begin_declare_variant_nested_propagation.c =================================================================== --- /dev/null +++ clang/test/OpenMP/begin_declare_variant_nested_propagation.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple=x86_64-pc-win32 -verify -fopenmp -x c -std=c99 -fms-extensions -Wno-pragma-pack %s +// expected-no-diagnostics + +#pragma omp begin declare variant match(user={condition(1)}, device={kind(cpu)}, implementation={extension(match_any)}) +#pragma omp begin declare variant match(device = {kind(cpu, fpga)}) + this is never reached +#pragma omp end declare variant +#pragma omp end declare variant + +#pragma omp begin declare variant match(user={condition(1)}, device={kind(cpu)}, implementation={extension(match_any)}) +#pragma omp begin declare variant match(device = {kind(cpu, fpga)}, implementation={vendor(llvm)}) + this is never reached +#pragma omp end declare variant +#pragma omp end declare variant Index: clang/lib/Parse/ParseOpenMP.cpp =================================================================== --- clang/lib/Parse/ParseOpenMP.cpp +++ clang/lib/Parse/ParseOpenMP.cpp @@ -21,6 +21,7 @@ #include "clang/Parse/RAIIObjectsForParser.h" #include "clang/Sema/Scope.h" #include "llvm/ADT/PointerIntPair.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/UniqueVector.h" #include "llvm/Frontend/OpenMP/OMPContext.h" @@ -1463,7 +1464,29 @@ // TODO: Keep some source location in the TI to provide better diagnostics. // TODO: Perform some kind of equivalence check on the condition and score // expressions. - for (const OMPTraitSet &ParentSet : ParentTI->Sets) { + auto StripImplementation = [](const OMPTraitSet &TSet) -> OMPTraitSet { + if (TSet.Kind != llvm::omp::TraitSet::implementation) + return TSet; + OMPTraitSet Set = TSet; + for (OMPTraitSelector &Selector : Set.Selectors) { + if (Selector.Kind != llvm::omp::TraitSelector::implementation_extension) + continue; + // Do not propagate match extensions to nested contexts. + llvm::erase_if(Selector.Properties, [](const OMPTraitProperty &Property) { + return ( + Property.Kind == + llvm::omp::TraitProperty::implementation_extension_match_any || + Property.Kind == + llvm::omp::TraitProperty::implementation_extension_match_all || + Property.Kind == + llvm::omp::TraitProperty::implementation_extension_match_none); + }); + return Set; + } + return Set; + }; + for (const OMPTraitSet &PSet : ParentTI->Sets) { + const OMPTraitSet ParentSet = StripImplementation(PSet); bool MergedSet = false; for (OMPTraitSet &Set : TI.Sets) { if (Set.Kind != ParentSet.Kind) Index: clang/include/clang/Basic/AttrDocs.td =================================================================== --- clang/include/clang/Basic/AttrDocs.td +++ clang/include/clang/Basic/AttrDocs.td @@ -4014,7 +4014,8 @@ match for an OpenMP context. The default is ``all``, with ``none`` no trait in the selector is allowed to be in the OpenMP context, with ``any`` a single trait in both the selector and OpenMP context is sufficient. Only a single match -extension trait is allowed per context selector. +extension trait is allowed per context selector. Note that match extensions are +not propagated to nested selectors like the standard defines it for other traits. The disable extensions remove default effects of the ``begin declare variant`` applied to a definition. If ``disable_implicit_base`` is given, we will not introduce an implicit base function for a variant if no base function was
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits