summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-02-21 22:09:29 +0000
committerChris Lattner <sabre@nondot.org>2011-02-21 22:09:29 +0000
commit93ede02045c99d2163f1c63dbf323761a30388bf (patch)
treec3cfe8deeb96438a3def6bb4f9b38529ca5d234f /clang/lib/Sema/SemaStmt.cpp
parent5e8603d1b9136ea9771b738376eaa44e36dc8d86 (diff)
downloadbcm5719-llvm-93ede02045c99d2163f1c63dbf323761a30388bf.tar.gz
bcm5719-llvm-93ede02045c99d2163f1c63dbf323761a30388bf.zip
add one more case of mismatched input/output constraints.
When the mismatch is due to a larger input operand that is a constant, truncate it down to the size of the output. This allows us to accept some cases in the linux kernel and elsewhere. Pedantically speaking, we generate different code than GCC, though I can't imagine how it would matter: Clang: movb $-1, %al frob %al GCC: movl $255, %eax frob %al llvm-svn: 126148
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 6801dd4c2eb..3815deae58f 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -1542,8 +1542,9 @@ StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, bool IsSimple,
if (!Info.hasTiedOperand()) continue;
unsigned TiedTo = Info.getTiedOperand();
+ unsigned InputOpNo = i+NumOutputs;
Expr *OutputExpr = Exprs[TiedTo];
- Expr *InputExpr = Exprs[i+NumOutputs];
+ Expr *InputExpr = Exprs[InputOpNo];
QualType InTy = InputExpr->getType();
QualType OutTy = OutputExpr->getType();
if (Context.hasSameType(InTy, OutTy))
@@ -1588,7 +1589,7 @@ StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, bool IsSimple,
// If this is a reference to the input and if the input was the smaller
// one, then we have to reject this asm.
- if (isOperandMentioned(i+NumOutputs, Pieces)) {
+ if (isOperandMentioned(InputOpNo, Pieces)) {
// This is a use in the asm string of the smaller operand. Since we
// codegen this by promoting to a wider value, the asm will get printed
// "wrong".
@@ -1607,6 +1608,19 @@ StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, bool IsSimple,
OutputConstraintInfos[TiedTo].allowsRegister())
continue;
+ // Either both of the operands were mentioned or the smaller one was
+ // mentioned. One more special case that we'll allow: if the tied input is
+ // integer, unmentioned, and is a constant, then we'll allow truncating it
+ // down to the size of the destination.
+ if (InputDomain == AD_Int && OutputDomain == AD_Int &&
+ !isOperandMentioned(InputOpNo, Pieces) &&
+ InputExpr->isEvaluatable(Context)) {
+ ImpCastExprToType(InputExpr, OutTy, CK_IntegralCast);
+ Exprs[InputOpNo] = InputExpr;
+ NS->setInputExpr(i, InputExpr);
+ continue;
+ }
+
Diag(InputExpr->getLocStart(),
diag::err_asm_tying_incompatible_types)
<< InTy << OutTy << OutputExpr->getSourceRange()
OpenPOWER on IntegriCloud