diff options
author | Anders Carlsson <andersca@mac.com> | 2009-01-27 20:38:24 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-01-27 20:38:24 +0000 |
commit | 03eb543cf7ebee463b33b5802b83ac92c21770cf (patch) | |
tree | bd511c9b73b843b5170087e7c9aa9e890457bd98 | |
parent | 98abf4bd3526a00a0e5cf71a9462c181f97b1c81 (diff) |
If an input constraint refers to an output constraint, it should have the same constraint info as the output constraint. Fixes PR3417
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63127 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/TargetInfo.h | 1 | ||||
-rw-r--r-- | lib/Basic/TargetInfo.cpp | 5 | ||||
-rw-r--r-- | lib/CodeGen/CGStmt.cpp | 7 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 8 | ||||
-rw-r--r-- | test/CodeGen/asm.c | 9 | ||||
-rw-r--r-- | test/Sema/asm.c | 2 |
6 files changed, 25 insertions, 7 deletions
diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index da14365e4d..67d7e63814 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -201,6 +201,7 @@ public: bool validateInputConstraint(const char *Name, const std::string *OutputNamesBegin, const std::string *OutputNamesEnd, + ConstraintInfo* OutputConstraints, ConstraintInfo &info) const; bool resolveSymbolicName(const char *&Name, const std::string *OutputNamesBegin, diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 3ec3551ebb..2b73582b78 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -222,6 +222,7 @@ bool TargetInfo::resolveSymbolicName(const char *&Name, bool TargetInfo::validateInputConstraint(const char *Name, const std::string *OutputNamesBegin, const std::string *OutputNamesEnd, + ConstraintInfo* OutputConstraints, ConstraintInfo &info) const { info = CI_None; @@ -236,6 +237,10 @@ bool TargetInfo::validateInputConstraint(const char *Name, // Check if matching constraint is out of bounds. if (i >= NumOutputs) return false; + + // The constraint should have the same info as the respective + // output constraint. + info = (ConstraintInfo)(info|OutputConstraints[i]); } else if (!validateAsmConstraint(*Name, info)) { // FIXME: This error return is in place temporarily so we can // add more constraints as we hit it. Eventually, an unknown diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 4adff72470..939ebec01e 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -932,7 +932,9 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { std::string InOutConstraints; std::vector<llvm::Value*> InOutArgs; std::vector<const llvm::Type*> InOutArgTypes; - + + llvm::SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos; + for (unsigned i = 0, e = S.getNumOutputs(); i != e; i++) { std::string OutputConstraint(S.getOutputConstraint(i)->getStrData(), S.getOutputConstraint(i)->getByteLength()); @@ -942,6 +944,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { Info); assert(result && "Failed to parse output constraint"); result=result; + OutputConstraintInfos.push_back(Info); + // Simplify the output constraint. OutputConstraint = SimplifyConstraint(OutputConstraint.c_str() + 1, Target); @@ -993,6 +997,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { bool result = Target.validateInputConstraint(InputConstraint.c_str(), S.begin_output_names(), S.end_output_names(), + &OutputConstraintInfos[0], Info); result=result; assert(result && "Failed to parse input constraint"); diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 0001f649ee..c01eceb4ba 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -849,6 +849,8 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, StringLiteral *AsmString = cast<StringLiteral>((Expr *)asmString.get()); StringLiteral **Clobbers = reinterpret_cast<StringLiteral**>(clobbers.get()); + llvm::SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos; + // The parser verifies that there is a string literal here. if (AsmString->isWide()) return StmtError(Diag(AsmString->getLocStart(),diag::err_asm_wide_character) @@ -877,6 +879,8 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, diag::err_asm_invalid_lvalue_in_output) << OutputExpr->getSubExpr()->getSourceRange()); } + + OutputConstraintInfos.push_back(info); } for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) { @@ -891,7 +895,9 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, TargetInfo::ConstraintInfo info; if (!Context.Target.validateInputConstraint(InputConstraint.c_str(), &Names[0], - &Names[0] + NumOutputs, info)) { + &Names[0] + NumOutputs, + &OutputConstraintInfos[0], + info)) { return StmtError(Diag(Literal->getLocStart(), diag::err_asm_invalid_input_constraint) << InputConstraint); } diff --git a/test/CodeGen/asm.c b/test/CodeGen/asm.c index 4ef97bde2a..26aa3bd61b 100644 --- a/test/CodeGen/asm.c +++ b/test/CodeGen/asm.c @@ -22,7 +22,8 @@ void t4() __asm__ volatile ("":: "m"(a), "m"(b)); } - - - - +// PR3417 +void t5(int i) +{ + asm("nop" : "=r"(i) : "0"(t5)); +} diff --git a/test/Sema/asm.c b/test/Sema/asm.c index fa9b125b6d..3acb58a015 100644 --- a/test/Sema/asm.c +++ b/test/Sema/asm.c @@ -59,4 +59,4 @@ void test5() void test6(long i) { asm("nop" : : "er"(i)); -}
\ No newline at end of file +} |