[PATCH] D12955: Fix assertion in inline assembler IR gen
Alexander Musman via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 21 03:42:12 PDT 2015
amusman updated this revision to Diff 35222.
amusman added a comment.
Added an assertion for TiedTo value.
http://reviews.llvm.org/D12955
Files:
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaStmtAsm.cpp
test/Sema/asm.c
Index: lib/Sema/SemaStmtAsm.cpp
===================================================================
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -420,6 +420,8 @@
diag::err_asm_unexpected_constraint_alternatives)
<< NumAlternatives << AltCount);
}
+ SmallVector<size_t, 4> InputMatchedToOutput(OutputConstraintInfos.size(),
+ ~0U);
for (unsigned i = 0, e = InputConstraintInfos.size(); i != e; ++i) {
TargetInfo::ConstraintInfo &Info = InputConstraintInfos[i];
StringRef ConstraintStr = Info.getConstraintStr();
@@ -441,6 +443,19 @@
Expr *OutputExpr = Exprs[TiedTo];
Expr *InputExpr = Exprs[InputOpNo];
+ // Make sure no more than one input constraint matches each output.
+ assert(TiedTo >= 0 && TiedTo < InputMatchedToOutput.size());
+ if (InputMatchedToOutput[TiedTo] != ~0U) {
+ Diag(NS->getInputExpr(i)->getLocStart(),
+ diag::err_asm_input_duplicate_match)
+ << TiedTo;
+ Diag(NS->getInputExpr(InputMatchedToOutput[TiedTo])->getLocStart(),
+ diag::note_asm_input_duplicate_first)
+ << TiedTo;
+ return StmtError();
+ }
+ InputMatchedToOutput[TiedTo] = i;
+
if (OutputExpr->isTypeDependent() || InputExpr->isTypeDependent())
continue;
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -6418,6 +6418,8 @@
def err_asm_non_addr_value_in_memory_constraint : Error <
"reference to a %select{bit-field|vector element|global register variable}0"
" in asm %select{input|output}1 with a memory constraint '%2'">;
+ def err_asm_input_duplicate_match : Error<
+ "more than one input constraint matches the same output '%0'">;
def warn_asm_label_on_auto_decl : Warning<
"ignored asm label '%0' on automatic variable">;
@@ -6432,6 +6434,8 @@
def note_asm_missing_constraint_modifier : Note<
"use constraint modifier \"%0\"">;
+ def note_asm_input_duplicate_first : Note<
+ "constraint '%0' is already present here">;
}
let CategoryName = "Semantic Issue" in {
Index: test/Sema/asm.c
===================================================================
--- test/Sema/asm.c
+++ test/Sema/asm.c
@@ -236,3 +236,15 @@
: "m" (test16_baz)); // expected-error {{reference to a global register variable in asm output with a memory constraint 'm'}}
}
+int test17(int t0)
+{
+ int r0, r1;
+ __asm ("addl %2, %2\n\t"
+ "movl $123, %0"
+ : "=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'}}
+ return r0 + r1;
+}
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12955.35222.patch
Type: text/x-patch
Size: 2931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150921/35fd7367/attachment.bin>
More information about the cfe-commits
mailing list