]> granicus.if.org Git - clang/commitdiff
Behave correctly if a constraint expression is invalid.
authorAnders Carlsson <andersca@mac.com>
Sat, 9 Feb 2008 19:57:29 +0000 (19:57 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 9 Feb 2008 19:57:29 +0000 (19:57 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46910 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseStmt.cpp
include/clang/Parse/Parser.h
test/Parser/asm.c

index f8ae4a05585067cd3f384d0a8c4248b44c4ef405..db91f0dec7e2124b7c04b6244f50934fadb42d46 100644 (file)
@@ -995,12 +995,15 @@ Parser::StmtResult Parser::ParseAsmStatement(bool &msAsm) {
     RParenLoc = ConsumeParen();
   } else {
     // Parse Outputs, if present. 
-    ParseAsmOperandsOpt(Names, Constraints, Exprs);
+    if (ParseAsmOperandsOpt(Names, Constraints, Exprs))
+        return true;
   
     NumOutputs = Names.size();
   
     // Parse Inputs, if present.
-    ParseAsmOperandsOpt(Names, Constraints, Exprs);
+    if (ParseAsmOperandsOpt(Names, Constraints, Exprs))
+        return true;
+      
     assert(Names.size() == Constraints.size() &&
            Constraints.size() == Exprs.size() 
            && "Input operand size mismatch!");
@@ -1048,16 +1051,16 @@ Parser::StmtResult Parser::ParseAsmStatement(bool &msAsm) {
 ///         asm-string-literal '(' expression ')'
 ///         '[' identifier ']' asm-string-literal '(' expression ')'
 ///
-void Parser::ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names,
+bool Parser::ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names,
                                  llvm::SmallVectorImpl<ExprTy*> &Constraints,
                                  llvm::SmallVectorImpl<ExprTy*> &Exprs) {
   // Only do anything if this operand is present.
-  if (Tok.isNot(tok::colon)) return;
+  if (Tok.isNot(tok::colon)) return false;
   ConsumeToken();
   
   // 'asm-operands' isn't present?
   if (!isTokenStringLiteral() && Tok.isNot(tok::l_square))
-    return;
+    return false;
   
   while (1) {   
     // Read the [id] if present.
@@ -1067,7 +1070,7 @@ void Parser::ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names,
       if (Tok.isNot(tok::identifier)) {
         Diag(Tok, diag::err_expected_ident);
         SkipUntil(tok::r_paren);
-        return;
+        return true;
       }
       
       IdentifierInfo *II = Tok.getIdentifierInfo();
@@ -1081,27 +1084,29 @@ void Parser::ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names,
     ExprResult Constraint = ParseAsmStringLiteral();
     if (Constraint.isInvalid) {
         SkipUntil(tok::r_paren);
-        return;
+        return true;
     }
     Constraints.push_back(Constraint.Val);
 
     if (Tok.isNot(tok::l_paren)) {
       Diag(Tok, diag::err_expected_lparen_after, "asm operand");
       SkipUntil(tok::r_paren);
-      return;
+      return true;
     }
     
     // Read the parenthesized expression.
     ExprResult Res = ParseSimpleParenExpression();
     if (Res.isInvalid) {
       SkipUntil(tok::r_paren);
-      return;
+      return true;
     }
     Exprs.push_back(Res.Val);
     // Eat the comma and continue parsing if it exists.
-    if (Tok.isNot(tok::comma)) return;
+    if (Tok.isNot(tok::comma)) return false;
     ConsumeToken();
   }
+
+  return true;
 }
 
 Parser::DeclTy *Parser::ParseFunctionStatementBody(DeclTy *Decl, 
index 1987e964ecf28654340235c933f43eb4d2892f6b..5a9eae03a59515d6977f8d99ebec6dc23f69f4cd 100644 (file)
@@ -410,7 +410,7 @@ private:
   StmtResult ParseObjCTryStmt(SourceLocation atLoc, bool &processAtKeyword);
   StmtResult ParseObjCThrowStmt(SourceLocation atLoc);
   StmtResult ParseObjCSynchronizedStmt(SourceLocation atLoc);
-  void ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names,
+  bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names,
                            llvm::SmallVectorImpl<ExprTy*> &Constraints,
                            llvm::SmallVectorImpl<ExprTy*> &Exprs);
 
index a09b545a8e03365f594a6ec997d57aa263c3e792..6a19acaaed643748e6925689a367cc869279036e 100644 (file)
@@ -3,3 +3,8 @@
 void f1() {
   asm ("ret" : : :); // expected-error {{expected string literal}}
 }
+
+void f2() {
+  asm("foo" : "=r" (a)); // expected-error {{use of undeclared identifier 'a'}}
+  asm("foo" : : "r" (b)); // expected-error {{use of undeclared identifier 'b'}} 
+}