diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 6ef306d27e75..947cbfc3f6d2 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -350,6 +350,10 @@ bool TargetInfo::validateInputConstraint(ConstraintInfo *OutputConstraints, if (i >= NumOutputs) return false; + // A number must refer to an output only operand. + if (OutputConstraints[i].isReadWrite()) + return false; + // The constraint should have the same info as the respective // output constraint. Info.setTiedOperand(i, OutputConstraints[i]); diff --git a/clang/test/Sema/asm.c b/clang/test/Sema/asm.c index 52611faf3dbc..73d081ddd385 100644 --- a/clang/test/Sema/asm.c +++ b/clang/test/Sema/asm.c @@ -79,3 +79,9 @@ int test7(unsigned long long b) { // asm volatile (""); // expected-warning {{meaningless 'volatile' on asm outside function}} + +// PR3904 +int test8(int i) { + // A number in an input constraint can't point to a read-write constraint. + asm ("" : "+r" (i), "=r"(i) : "0" (i)); // expected-error{{invalid input constraint '0' in asm}} +}