r331164 - [Targets] Implement getConstraintRegister for ARM and AArch64
Mikhail Maltsev via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 30 02:11:08 PDT 2018
Author: miyuki
Date: Mon Apr 30 02:11:08 2018
New Revision: 331164
URL: http://llvm.org/viewvc/llvm-project?rev=331164&view=rev
Log:
[Targets] Implement getConstraintRegister for ARM and AArch64
Summary:
The getConstraintRegister method is used by semantic checking of
inline assembly statements in order to diagnose conflicts between
clobber list and input/output lists. Currently ARM and AArch64 don't
override getConstraintRegister, so conflicts between registers
assigned to variables in asm labels and clobber lists are not
diagnosed. Such conflicts can cause assertion failures in the back end
and even miscompilations.
This patch implements getConstraintRegister for ARM and AArch64
targets. Since these targets don't have single-register constraints,
the implementation is trivial and just returns the register specified
in an asm label (if any).
Reviewers: eli.friedman, javed.absar, thopre
Reviewed By: thopre
Subscribers: rengolin, eraman, rogfer01, myatsina, kristof.beyls, cfe-commits, chrib
Differential Revision: https://reviews.llvm.org/D45965
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/Targets/AArch64.h
cfe/trunk/lib/Basic/Targets/ARM.h
cfe/trunk/test/Sema/arm-asm.c
cfe/trunk/test/Sema/arm64-inline-asm.c
Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=331164&r1=331163&r2=331164&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Mon Apr 30 02:11:08 2018
@@ -629,6 +629,12 @@ public:
StringRef getNormalizedGCCRegisterName(StringRef Name,
bool ReturnCanonical = false) const;
+ /// \brief Extracts a register from the passed constraint (if it is a
+ /// single-register constraint) and the asm label expression related to a
+ /// variable in the input or output list of an inline asm statement.
+ ///
+ /// This function is used by Sema in order to diagnose conflicts between
+ /// the clobber list and the input/output lists.
virtual StringRef getConstraintRegister(StringRef Constraint,
StringRef Expression) const {
return "";
Modified: cfe/trunk/lib/Basic/Targets/AArch64.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AArch64.h?rev=331164&r1=331163&r2=331164&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/AArch64.h (original)
+++ cfe/trunk/lib/Basic/Targets/AArch64.h Mon Apr 30 02:11:08 2018
@@ -82,6 +82,11 @@ public:
std::string &SuggestedModifier) const override;
const char *getClobbers() const override;
+ StringRef getConstraintRegister(StringRef Constraint,
+ StringRef Expression) const override {
+ return Expression;
+ }
+
int getEHDataRegisterNumber(unsigned RegNo) const override;
};
Modified: cfe/trunk/lib/Basic/Targets/ARM.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/ARM.h?rev=331164&r1=331163&r2=331164&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/ARM.h (original)
+++ cfe/trunk/lib/Basic/Targets/ARM.h Mon Apr 30 02:11:08 2018
@@ -156,6 +156,11 @@ public:
std::string &SuggestedModifier) const override;
const char *getClobbers() const override;
+ StringRef getConstraintRegister(StringRef Constraint,
+ StringRef Expression) const override {
+ return Expression;
+ }
+
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
int getEHDataRegisterNumber(unsigned RegNo) const override;
Modified: cfe/trunk/test/Sema/arm-asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/arm-asm.c?rev=331164&r1=331163&r2=331164&view=diff
==============================================================================
--- cfe/trunk/test/Sema/arm-asm.c (original)
+++ cfe/trunk/test/Sema/arm-asm.c Mon Apr 30 02:11:08 2018
@@ -10,3 +10,10 @@ void test_64bit_r(void) {
long long foo = 0, bar = 0;
asm volatile("INST %0, %1" : "=r"(foo) : "r"(bar));
}
+
+void test_clobber_conflict(void) {
+ register int x asm("r1");
+ asm volatile("nop" :: "r"(x) : "%r1"); // expected-error {{conflicts with asm clobber list}}
+ asm volatile("nop" :: "l"(x) : "%r1"); // expected-error {{conflicts with asm clobber list}}
+ asm volatile("nop" : "=r"(x) :: "%r1"); // expected-error {{conflicts with asm clobber list}}
+}
Modified: cfe/trunk/test/Sema/arm64-inline-asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/arm64-inline-asm.c?rev=331164&r1=331163&r2=331164&view=diff
==============================================================================
--- cfe/trunk/test/Sema/arm64-inline-asm.c (original)
+++ cfe/trunk/test/Sema/arm64-inline-asm.c Mon Apr 30 02:11:08 2018
@@ -7,3 +7,9 @@ void foo() {
asm volatile("USE(%0)" :: "z"(0)); // expected-warning {{value size does not match register size specified by the constraint and modifier}} expected-note {{use constraint modifier "w"}}
}
+
+void test_clobber_conflict(void) {
+ register long x asm("x1");
+ asm volatile("nop" :: "r"(x) : "%x1"); // expected-error {{conflicts with asm clobber list}}
+ asm volatile("nop" : "=r"(x) :: "%x1"); // expected-error {{conflicts with asm clobber list}}
+}
More information about the cfe-commits
mailing list