This patch from Chris Manghane changes the Go frontend to treat /* */
comments that contain newlines as though they were a newline, rather
than a space, with regard to semicolon insertion.  This fixes
https://golang.org/issue/11528 .  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE     (revision 226788)
+++ gcc/go/gofrontend/MERGE     (working copy)
@@ -1,4 +1,4 @@
-3bd90ea170b9c9aecedd37796acdd2712b29922b
+3b590ff53700963c1b8207a78594138e6a4e47f4
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/lex.cc
===================================================================
--- gcc/go/gofrontend/lex.cc    (revision 226510)
+++ gcc/go/gofrontend/lex.cc    (working copy)
@@ -600,8 +600,14 @@ Lex::next_token()
                {
                  this->lineoff_ = p + 2 - this->linebuf_;
                  Location location = this->location();
-                 if (!this->skip_c_comment())
+                  bool found_newline = false;
+                 if (!this->skip_c_comment(&found_newline))
                    return Token::make_invalid_token(location);
+                  if (found_newline && this->add_semi_at_eol_)
+                    {
+                      this->add_semi_at_eol_ = false;
+                      return this->make_operator(OPERATOR_SEMICOLON, 1);
+                    }
                  p = this->linebuf_ + this->lineoff_;
                  pend = this->linebuf_ + this->linesize_;
                }
@@ -1621,7 +1627,7 @@ Lex::one_character_operator(char c)
 // Skip a C-style comment.
 
 bool
-Lex::skip_c_comment()
+Lex::skip_c_comment(bool* found_newline)
 {
   while (true)
     {
@@ -1642,6 +1648,9 @@ Lex::skip_c_comment()
              return true;
            }
 
+          if (p[0] == '\n')
+            *found_newline = true;
+
          this->lineoff_ = p - this->linebuf_;
          unsigned int c;
          bool issued_error;
Index: gcc/go/gofrontend/lex.h
===================================================================
--- gcc/go/gofrontend/lex.h     (revision 226510)
+++ gcc/go/gofrontend/lex.h     (working copy)
@@ -469,7 +469,7 @@ class Lex
   one_character_operator(char);
 
   bool
-  skip_c_comment();
+  skip_c_comment(bool* found_newline);
 
   void
   skip_cpp_comment();

Reply via email to