From 570c357ded427b55c35ddfe4b5ff73e221ea1305 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Tue, 27 Jan 2009 20:38:24 +0000 Subject: [PATCH] If an input constraint refers to an output constraint, it should have the same constraint info as the output constraint. Fixes PR3417 llvm-svn: 63127 --- clang/include/clang/Basic/TargetInfo.h | 1 + clang/lib/Basic/TargetInfo.cpp | 5 +++++ clang/lib/CodeGen/CGStmt.cpp | 7 ++++++- clang/lib/Sema/SemaStmt.cpp | 8 +++++++- clang/test/CodeGen/asm.c | 9 +++++---- clang/test/Sema/asm.c | 2 +- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index da14365e4dd5..67d7e6381452 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/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/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 3ec3551ebb32..2b73582b7862 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/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/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 4adff72470d5..939ebec01e3d 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -932,7 +932,9 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { std::string InOutConstraints; std::vector InOutArgs; std::vector InOutArgTypes; - + + llvm::SmallVector 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/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 0001f649eedc..c01eceb4ba9e 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -849,6 +849,8 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, StringLiteral *AsmString = cast((Expr *)asmString.get()); StringLiteral **Clobbers = reinterpret_cast(clobbers.get()); + llvm::SmallVector 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/clang/test/CodeGen/asm.c b/clang/test/CodeGen/asm.c index 4ef97bde2ad3..26aa3bd61b3a 100644 --- a/clang/test/CodeGen/asm.c +++ b/clang/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/clang/test/Sema/asm.c b/clang/test/Sema/asm.c index fa9b125b6dd4..3acb58a015a2 100644 --- a/clang/test/Sema/asm.c +++ b/clang/test/Sema/asm.c @@ -59,4 +59,4 @@ void test5() void test6(long i) { asm("nop" : : "er"(i)); -} \ No newline at end of file +}