Index: lib/Sema/SemaStmtAsm.cpp =================================================================== --- lib/Sema/SemaStmtAsm.cpp +++ lib/Sema/SemaStmtAsm.cpp @@ -473,6 +473,8 @@ } SmallVector InputMatchedToOutput(OutputConstraintInfos.size(), ~0U); + SmallVector InputMatchedToOutputIdName( + OutputConstraintInfos.size()); for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) { TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i]; StringRef ConstraintStr = Info.getConstraintStr(); @@ -493,10 +495,21 @@ unsigned InputOpNo = i+NumOutputs; Expr *OutputExpr = Exprs[TiedTo]; Expr *InputExpr = Exprs[InputOpNo]; + StringRef InputIdentifierName; + // Extract the Identifier name in order to check that repeating constraints + // won't emit an error when they are the same + if (ImplicitCastExpr *implicitInputExpr = + dyn_cast(InputExpr)) + if (DeclRefExpr *DeclRefInputExpr = + dyn_cast(implicitInputExpr->getSubExpr())) + InputIdentifierName = + DeclRefInputExpr->getDecl()->getIdentifier()->getName(); + // Make sure no more than one input constraint matches each output. assert(TiedTo < InputMatchedToOutput.size() && "TiedTo value out of range"); - if (InputMatchedToOutput[TiedTo] != ~0U) { + if (InputMatchedToOutput[TiedTo] != ~0U && + !InputIdentifierName.equals(InputMatchedToOutputIdName[TiedTo])) { Diag(NS->getInputExpr(i)->getLocStart(), diag::err_asm_input_duplicate_match) << TiedTo; @@ -505,7 +518,9 @@ << TiedTo; return StmtError(); } + InputMatchedToOutput[TiedTo] = i; + InputMatchedToOutputIdName[TiedTo] = InputIdentifierName; if (OutputExpr->isTypeDependent() || InputExpr->isTypeDependent()) continue; Index: test/Sema/asm.c =================================================================== --- test/Sema/asm.c +++ test/Sema/asm.c @@ -248,7 +248,7 @@ : "m" (test16_baz)); // expected-error {{reference to a global register variable in asm output with a memory constraint 'm'}} } -int test17(int t0) +int test17(int t0, int t1) { int r0, r1; __asm ("addl %2, %2\n\t" @@ -256,7 +256,18 @@ : "=a" (r0), "=&r" (r1) : "1" (t0), // expected-note {{constraint '1' is already present here}} - "1" (t0)); // expected-error {{more than one input constraint matches the same output '1'}} + "1" (t1)); // expected-error {{more than one input constraint matches the same output '1'}} return r0 + r1; } +int test18(int t0) +{ + int r0, r1; + __asm ("addl %2, %2\n\t" + "movl $123, %0" + : "=a" (r0), + "=&r" (r1) + : "1" (t0), // no-error + "1" (t0)); // no-error + return r0 + r1; +} \ No newline at end of file