Skip to content

Commit e8f4726

Browse files
committed
[Clang][RISCV] Recognize unsupport feature by supporting isValidFeatureName
1 parent b0276ec commit e8f4726

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,10 @@ bool RISCVTargetInfo::validateCpuSupports(StringRef Feature) const {
478478
// __riscv_feature_bits structure.
479479
return -1 != llvm::RISCVISAInfo::getRISCVFeaturesBitsInfo(Feature).second;
480480
}
481+
482+
bool RISCVTargetInfo::isValidFeatureName(StringRef Name) const {
483+
if (Name == "__RISCV_TargetAttrNeedOverride")
484+
return true;
485+
486+
return llvm::RISCVISAInfo::isSupportedExtensionFeature(Name);
487+
}

clang/lib/Basic/Targets/RISCV.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class RISCVTargetInfo : public TargetInfo {
130130
bool supportsCpuSupports() const override { return getTriple().isOSLinux(); }
131131
bool supportsCpuInit() const override { return getTriple().isOSLinux(); }
132132
bool validateCpuSupports(StringRef Feature) const override;
133+
bool isValidFeatureName(StringRef Name) const override;
133134
};
134135
class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
135136
public:

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,10 +2993,17 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
29932993
return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
29942994
<< Unknown << Tune << ParsedAttrs.Tune << Target;
29952995

2996-
if (Context.getTargetInfo().getTriple().isRISCV() &&
2997-
ParsedAttrs.Duplicate != "")
2998-
return Diag(LiteralLoc, diag::err_duplicate_target_attribute)
2999-
<< Duplicate << None << ParsedAttrs.Duplicate << Target;
2996+
if (Context.getTargetInfo().getTriple().isRISCV()) {
2997+
if (ParsedAttrs.Duplicate != "")
2998+
return Diag(LiteralLoc, diag::err_duplicate_target_attribute)
2999+
<< Duplicate << None << ParsedAttrs.Duplicate << Target;
3000+
for (const auto &Feature : ParsedAttrs.Features) {
3001+
auto CurFeature = StringRef(Feature);
3002+
if (!CurFeature.starts_with("+") && !CurFeature.starts_with("-"))
3003+
return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3004+
<< Unsupported << None << AttrStr << Target;
3005+
}
3006+
}
30003007

30013008
if (ParsedAttrs.Duplicate != "")
30023009
return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)

clang/test/Sema/attr-target-riscv.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@
44
int __attribute__((target("arch=rv64g"))) foo(void) { return 0; }
55
//expected-error@+1 {{redefinition of 'foo'}}
66
int __attribute__((target("arch=rv64gc"))) foo(void) { return 0; }
7+
8+
//expected-warning@+1 {{unsupported 'notafeature' in the 'target' attribute string; 'target' attribute ignored}}
9+
int __attribute__((target("arch=+notafeature"))) UnsupportFeature(void) { return 0; }
10+
11+
//expected-warning@+1 {{unsupported 'arch=+zba,zbb' in the 'target' attribute string; 'target' attribute ignored}}
12+
int __attribute__((target("arch=+zba,zbb"))) WithoutAddSigned(void) { return 0; }
13+
14+
//expected-warning@+1 {{unsupported 'arch=zba' in the 'target' attribute string; 'target' attribute ignored}}
15+
int __attribute__((target("arch=zba"))) WithoutAddSigned2(void) { return 0; }

0 commit comments

Comments
 (0)