Inline asm IR input register constraints don't have early clobber
authorEric Christopher <echristo@gmail.com>
Fri, 6 Feb 2015 18:44:18 +0000 (18:44 +0000)
committerEric Christopher <echristo@gmail.com>
Fri, 6 Feb 2015 18:44:18 +0000 (18:44 +0000)
modifiers on them. If we have a matching output constraint with
an early clobber make sure we don't propagate that to the input
constraint.

llvm-svn: 228422

clang/lib/CodeGen/CGStmt.cpp
clang/test/CodeGen/inline-asm-matching-constraint.c [new file with mode: 0644]

index 8e1c7f2..d921c0d 100644 (file)
@@ -1957,10 +1957,9 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
     InputConstraint = SimplifyConstraint(InputConstraint.c_str(), getTarget(),
                                          &OutputConstraintInfos);
 
-    InputConstraint =
-      AddVariableConstraints(InputConstraint,
-                            *InputExpr->IgnoreParenNoopCasts(getContext()),
-                            getTarget(), CGM, S, Info.earlyClobber());
+    InputConstraint = AddVariableConstraints(
+        InputConstraint, *InputExpr->IgnoreParenNoopCasts(getContext()),
+        getTarget(), CGM, S, false /* No EarlyClobber */);
 
     llvm::Value *Arg = EmitAsmInput(Info, InputExpr, Constraints);
 
diff --git a/clang/test/CodeGen/inline-asm-matching-constraint.c b/clang/test/CodeGen/inline-asm-matching-constraint.c
new file mode 100644 (file)
index 0000000..7d073b1
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -triple powerpc64le-linux-gnu | FileCheck %s
+// Sadly since this requires a register constraint to trigger we have to set
+// a target here.
+void a(void) {
+  register unsigned long __sc_0 __asm__("r0");
+  __asm__ __volatile__("mfcr %0" : "=&r"(__sc_0) : "0"(__sc_0));
+}
+
+// Check that we can generate code for this correctly. The matching input
+// constraint should not have an early clobber on it.
+// CHECK: call i64 asm sideeffect "mfcr $0", "=&{r0},{r0}"(i64 %0)