diff --git a/clang/test/OpenMP/declare_variant_ast_x86_64.c b/clang/test/OpenMP/declare_variant_ast_x86_64.c new file mode 100644 --- /dev/null +++ b/clang/test/OpenMP/declare_variant_ast_x86_64.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-unknown %s -ast-dump | FileCheck %s +// expected-no-diagnostics + +#pragma omp begin declare variant match(device={arch(x86_64)}) + +void bar() {} + +// CHECK: FunctionDecl {{.*}} bar[device={arch(x86_64)}] 'void ()' + +#pragma omp end declare variant diff --git a/llvm/lib/Frontend/OpenMP/OMPContext.cpp b/llvm/lib/Frontend/OpenMP/OMPContext.cpp --- a/llvm/lib/Frontend/OpenMP/OMPContext.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPContext.cpp @@ -14,7 +14,9 @@ #include "llvm/Frontend/OpenMP/OMPContext.h" #include "llvm/ADT/SetOperations.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/ADT/Triple.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -58,9 +60,12 @@ // Add the appropriate device architecture trait based on the triple. #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str) \ - if (TraitSelector::TraitSelectorEnum == TraitSelector::device_arch) \ + if (TraitSelector::TraitSelectorEnum == TraitSelector::device_arch) { \ if (TargetTriple.getArch() == TargetTriple.getArchTypeForLLVMName(Str)) \ - ActiveTraits.set(unsigned(TraitProperty::Enum)); + ActiveTraits.set(unsigned(TraitProperty::Enum)); \ + if (Str == "x86_64" && TargetTriple.getArch() == Triple::x86_64) \ + ActiveTraits.set(unsigned(TraitProperty::Enum)); \ + } #include "llvm/Frontend/OpenMP/OMPKinds.def" // TODO: What exactly do we want to see as device ISA trait?