From: Duncan P. N. Exon Smith Date: Mon, 16 Dec 2013 03:20:06 +0000 (+0000) Subject: Stop crashing on empty asm input constraints X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff1554738da8fed4bbb53fecab7f369d56a0cd66;p=clang Stop crashing on empty asm input constraints An empty string for an ASM input constraint is invalid, and will crash during clang CodeGen. Change TargetInfo::validateInputConstraint to reject an empty string. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197362 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 5aa84afc4d..d0ed6e6b16 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -482,6 +482,9 @@ bool TargetInfo::validateInputConstraint(ConstraintInfo *OutputConstraints, ConstraintInfo &Info) const { const char *Name = Info.ConstraintStr.c_str(); + if (!*Name) + return false; + while (*Name) { switch (*Name) { default: diff --git a/test/Sema/asm.c b/test/Sema/asm.c index c81f16a387..1559b228c8 100644 --- a/test/Sema/asm.c +++ b/test/Sema/asm.c @@ -13,6 +13,9 @@ void f() { asm ("foo\n" : "=a" (i) : "[" (i)); // expected-error {{invalid input constraint '[' in asm}} asm ("foo\n" : "=a" (i) : "[foo" (i)); // expected-error {{invalid input constraint '[foo' in asm}} asm ("foo\n" : "=a" (i) : "[symbolic_name]" (i)); // expected-error {{invalid input constraint '[symbolic_name]' in asm}} + + asm ("foo\n" : : "" (i)); // expected-error {{invalid input constraint '' in asm}} + asm ("foo\n" : "=a" (i) : "" (i)); // expected-error {{invalid input constraint '' in asm}} } void clobbers() {