Skip to content

Commit 3affa9c

Browse files
author
git apple-llvm automerger
committed
Merge commit 'f7d088b61686' from llvm.org/main into next
2 parents 37d2cf8 + f7d088b commit 3affa9c

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,15 @@ bool RISCVTargetInfo::validateCpuSupports(StringRef Feature) const {
486486
bool RISCVTargetInfo::isValidFeatureName(StringRef Name) const {
487487
return llvm::RISCVISAInfo::isSupportedExtensionFeature(Name);
488488
}
489+
490+
bool RISCVTargetInfo::validateGlobalRegisterVariable(
491+
StringRef RegName, unsigned RegSize, bool &HasSizeMismatch) const {
492+
if (RegName == "ra" || RegName == "sp" || RegName == "gp" ||
493+
RegName == "tp" || RegName.starts_with("x") || RegName.starts_with("a") ||
494+
RegName.starts_with("s") || RegName.starts_with("t")) {
495+
unsigned XLen = getTriple().isArch64Bit() ? 64 : 32;
496+
HasSizeMismatch = RegSize != XLen;
497+
return true;
498+
}
499+
return false;
500+
}

clang/lib/Basic/Targets/RISCV.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ class RISCVTargetInfo : public TargetInfo {
131131
bool supportsCpuInit() const override { return getTriple().isOSLinux(); }
132132
bool validateCpuSupports(StringRef Feature) const override;
133133
bool isValidFeatureName(StringRef Name) const override;
134+
135+
bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
136+
bool &HasSizeMismatch) const override;
134137
};
135138
class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
136139
public:

clang/test/Sema/riscv-asm.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// RUN: %clang_cc1 %s -triple riscv32 -verify -fsyntax-only
22
// RUN: %clang_cc1 %s -triple riscv64 -verify -fsyntax-only
33

4-
// expected-no-diagnostics
5-
64
void i (void) {
75
asm volatile ("" ::: "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7");
86
asm volatile ("" ::: "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15");
@@ -26,3 +24,18 @@ void f (void) {
2624
asm volatile ("" ::: "fa6", "fa7", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7");
2725
asm volatile ("" ::: "fs8", "fs9", "fs10", "fs11", "ft8", "ft9", "ft10", "ft11");
2826
}
27+
28+
register char i1 __asm__ ("x1"); // expected-error {{size of register 'x1' does not match variable size}}
29+
#if __riscv_xlen == 32
30+
register long long ll2 __asm__ ("x2"); // expected-error {{size of register 'x2' does not match variable size}}
31+
register int i2 __asm__ ("x3");
32+
#endif
33+
register long l3 __asm__ ("x4");
34+
register long ra __asm__ ("ra");
35+
register long sp __asm__ ("sp");
36+
register int *gp __asm__ ("gp");
37+
register char *tp __asm__ ("tp");
38+
register long a7 __asm__ ("a7");
39+
register long s11 __asm__ ("s11");
40+
register long t5 __asm__ ("t5");
41+
register long* f1 __asm__ ("f1"); // expected-error {{register 'f1' unsuitable for global register variables on this target}}

0 commit comments

Comments
 (0)