diff options
| author | Akira Hatanaka <ahatanaka@apple.com> | 2015-11-18 00:15:28 +0000 |
|---|---|---|
| committer | Akira Hatanaka <ahatanaka@apple.com> | 2015-11-18 00:15:28 +0000 |
| commit | 8c26ea663d433e7d9f51603d4e3170ef52eea2e5 (patch) | |
| tree | 9b1ceab8c5842e7b12007c3ea65057261b85b49c /clang/lib/Basic/Targets.cpp | |
| parent | cbf0b5e4b690c781c475c466a072d9d01fd71787 (diff) | |
| download | bcm5719-llvm-8c26ea663d433e7d9f51603d4e3170ef52eea2e5.tar.gz bcm5719-llvm-8c26ea663d433e7d9f51603d4e3170ef52eea2e5.zip | |
Produce a better diagnostic for global register variables.
Currently, when there is a global register variable in a program that
is bound to an invalid register, clang/llvm prints an error message that
is not very user-friendly.
This commit improves the diagnostic and moves the check that used to be
in the backend to Sema. In addition, it makes changes to error out if
the size of the register doesn't match the declared variable size.
e.g., volatile register int B asm ("rbp");
rdar://problem/23084219
Differential Revision: http://reviews.llvm.org/D13834
llvm-svn: 253405
Diffstat (limited to 'clang/lib/Basic/Targets.cpp')
| -rw-r--r-- | clang/lib/Basic/Targets.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 319a8d93116..648ef4b3d26 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -2358,6 +2358,20 @@ public: bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override; + bool validateGlobalRegisterVariable(StringRef RegName, + unsigned RegSize, + bool &HasSizeMismatch) const override { + // esp and ebp are the only 32-bit registers the x86 backend can currently + // handle. + if (RegName.equals("esp") || RegName.equals("ebp")) { + // Check that the register size is 32-bit. + HasSizeMismatch = RegSize != 32; + return true; + } + + return false; + } + bool validateOutputSize(StringRef Constraint, unsigned Size) const override; bool validateInputSize(StringRef Constraint, unsigned Size) const override; @@ -3974,6 +3988,22 @@ public: // for x32 we need it here explicitly bool hasInt128Type() const override { return true; } + + bool validateGlobalRegisterVariable(StringRef RegName, + unsigned RegSize, + bool &HasSizeMismatch) const override { + // rsp and rbp are the only 64-bit registers the x86 backend can currently + // handle. + if (RegName.equals("rsp") || RegName.equals("rbp")) { + // Check that the register size is 64-bit. + HasSizeMismatch = RegSize != 64; + return true; + } + + // Check if the register is a 32-bit register the backend can handle. + return X86TargetInfo::validateGlobalRegisterVariable(RegName, RegSize, + HasSizeMismatch); + } }; // x86-64 Windows target |

