[PATCH] D45965: [Targets] Implement getConstraintRegister for ARM and AArch64

Mikhail Maltsev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 23 07:47:34 PDT 2018


miyuki created this revision.
miyuki added a reviewer: eli.friedman.
Herald added subscribers: chrib, kristof.beyls, eraman, rengolin.
Herald added a reviewer: javed.absar.

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).


https://reviews.llvm.org/D45965

Files:
  lib/Basic/Targets/AArch64.h
  lib/Basic/Targets/ARM.h
  test/Sema/arm-asm.c
  test/Sema/arm64-inline-asm.c


Index: test/Sema/arm64-inline-asm.c
===================================================================
--- test/Sema/arm64-inline-asm.c
+++ test/Sema/arm64-inline-asm.c
@@ -7,3 +7,9 @@
 
   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}}
+}
Index: test/Sema/arm-asm.c
===================================================================
--- test/Sema/arm-asm.c
+++ test/Sema/arm-asm.c
@@ -10,3 +10,10 @@
   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}}
+}
Index: lib/Basic/Targets/ARM.h
===================================================================
--- lib/Basic/Targets/ARM.h
+++ lib/Basic/Targets/ARM.h
@@ -155,6 +155,11 @@
                              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;
Index: lib/Basic/Targets/AArch64.h
===================================================================
--- lib/Basic/Targets/AArch64.h
+++ lib/Basic/Targets/AArch64.h
@@ -82,6 +82,11 @@
                              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;
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45965.143556.patch
Type: text/x-patch
Size: 2405 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180423/5052d9b5/attachment.bin>


More information about the cfe-commits mailing list