Skip to content

Commit c8c5830

Browse files
committed
Fix diag for read-only target features
Currently the diag is emitted even when there is no target feature specified on command line for OpenMP. This is because the function to initialize feature map is also used with cached feature string. The fix is to only diag when the feature map is initialized with feature strings from command line options. Reviewed by: Joseph Huber, Matt Arsenault, Johannes Doerfert Differential Revision: https://reviews.llvm.org/D153123
1 parent f1bb534 commit c8c5830

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

clang/lib/Basic/TargetInfo.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,6 @@ bool TargetInfo::initFeatureMap(
528528
// Apply the feature via the target.
529529
if (Name[0] != '+' && Name[0] != '-')
530530
Diags.Report(diag::warn_fe_backend_invalid_feature_flag) << Name;
531-
else if (isReadOnlyFeature(Name.substr(1)))
532-
Diags.Report(diag::warn_fe_backend_readonly_feature_flag) << Name;
533531
else
534532
setFeatureEnabled(Features, Name.substr(1), Name[0] == '+');
535533
}

clang/lib/Basic/Targets.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "Targets/X86.h"
4343
#include "Targets/XCore.h"
4444
#include "clang/Basic/Diagnostic.h"
45+
#include "clang/Basic/DiagnosticFrontend.h"
4546
#include "llvm/ADT/StringExtras.h"
4647
#include "llvm/TargetParser/Triple.h"
4748

@@ -816,6 +817,13 @@ TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
816817

817818
// Compute the default target features, we need the target to handle this
818819
// because features may have dependencies on one another.
820+
llvm::erase_if(Opts->FeaturesAsWritten, [&](StringRef Name) {
821+
if (Target->isReadOnlyFeature(Name.substr(1))) {
822+
Diags.Report(diag::warn_fe_backend_readonly_feature_flag) << Name;
823+
return true;
824+
}
825+
return false;
826+
});
819827
if (!Target->initFeatureMap(Opts->FeatureMap, Diags, Opts->CPU,
820828
Opts->FeaturesAsWritten))
821829
return nullptr;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: x86-registered-target
2+
// REQUIRES: amdgpu-registered-target
3+
// REQUIRES: clang-target-64-bits
4+
5+
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx1030 \
6+
// RUN: -fopenmp -nogpulib -fopenmp-is-device -verify %s
7+
// expected-no-diagnostics
8+
9+
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx1030 \
10+
// RUN: -fopenmp -nogpulib -target-feature -image-insts \
11+
// RUN: -fopenmp-is-device -emit-llvm -S -o - %s 2>&1 | FileCheck %s
12+
// CHECK: warning: feature flag '-image-insts' is ignored since the feature is read only
13+
14+
#pragma omp begin declare variant match(device = {arch(amdgcn)})
15+
void foo();
16+
#pragma omp end declare variant

0 commit comments

Comments
 (0)