]> granicus.if.org Git - clang/commitdiff
Stop crashing on empty asm input constraints
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 16 Dec 2013 03:20:06 +0000 (03:20 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 16 Dec 2013 03:20:06 +0000 (03:20 +0000)
An empty string for an ASM input constraint is invalid, and will crash
during clang CodeGen.  Change TargetInfo::validateInputConstraint to
reject an empty string.

<rdar://problem/15552191>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@197362 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/TargetInfo.cpp
test/Sema/asm.c

index 5aa84afc4d0064b7429bafea09ee7d362019090d..d0ed6e6b161c964c3a152d029c0fe35d749f7cb4 100644 (file)
@@ -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:
index c81f16a3875d877667fad3cd4f5d2e0b81a460f7..1559b228c87a2347f3bd6cd7873ecd2eb1251c0a 100644 (file)
@@ -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() {