PR22714, Assembler preprocessor loses track of \@
[binutils-gdb.git] / gas / app.c
index d5a10c12d71c0f58ac5922fabe03c9ae80ab552b..9cafff055d9c5e731d912b4e6372c0d53862e995 100644 (file)
--- a/gas/app.c
+++ b/gas/app.c
@@ -1,5 +1,5 @@
 /* This is the Assembler Pre-Processor
-   Copyright (C) 1987-2014 Free Software Foundation, Inc.
+   Copyright (C) 1987-2018 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
@@ -55,6 +55,9 @@ static const char mri_pseudo[] = ".mri 0";
 static const char   symver_pseudo[] = ".symver";
 static const char * symver_state;
 #endif
+#ifdef TC_ARM
+static char last_char;
+#endif
 
 static char lex[256];
 static const char symbol_chars[] =
@@ -211,7 +214,7 @@ do_scrub_begin (int m68k_mri ATTRIBUTE_UNUSED)
 /* Saved state of the scrubber.  */
 static int state;
 static int old_state;
-static char *out_string;
+static const char *out_string;
 static char out_buf[20];
 static int add_newlines;
 static char *saved_input;
@@ -229,7 +232,7 @@ struct app_save
 {
   int          state;
   int          old_state;
-  char *       out_string;
+  const char * out_string;
   char         out_buf[sizeof (out_buf)];
   int          add_newlines;
   char *       saved_input;
@@ -242,6 +245,9 @@ struct app_save
 #if defined TC_ARM && defined OBJ_ELF
   const char * symver_state;
 #endif
+#ifdef TC_ARM
+  char last_char;
+#endif
 };
 
 char *
@@ -249,7 +255,7 @@ app_push (void)
 {
   struct app_save *saved;
 
-  saved = (struct app_save *) xmalloc (sizeof (*saved));
+  saved = XNEW (struct app_save);
   saved->state = state;
   saved->old_state = old_state;
   saved->out_string = out_string;
@@ -259,7 +265,7 @@ app_push (void)
     saved->saved_input = NULL;
   else
     {
-      saved->saved_input = (char *) xmalloc (saved_input_len);
+      saved->saved_input = XNEWVEC (char, saved_input_len);
       memcpy (saved->saved_input, saved_input, saved_input_len);
       saved->saved_input_len = saved_input_len;
     }
@@ -271,6 +277,9 @@ app_push (void)
 #if defined TC_ARM && defined OBJ_ELF
   saved->symver_state = symver_state;
 #endif
+#ifdef TC_ARM
+  saved->last_char = last_char;
+#endif
 
   /* do_scrub_begin() is not useful, just wastes time.  */
 
@@ -310,6 +319,9 @@ app_pop (char *arg)
 #if defined TC_ARM && defined OBJ_ELF
   symver_state = saved->symver_state;
 #endif
+#ifdef TC_ARM
+  last_char = saved->last_char;
+#endif
 
   free (arg);
 }
@@ -695,6 +707,7 @@ do_scrub_chars (size_t (*get) (char *, size_t), char *tostart, size_t tolen)
              state = 9;
              break;
            }
+         /* Fall through.  */
        case 17:
          /* We have seen "af" at the start of a symbol,
             a ' here is a part of that symbol.  */
@@ -1187,7 +1200,7 @@ do_scrub_chars (size_t (*get) (char *, size_t), char *tostart, size_t tolen)
                  state = -2;
                  break;
                }
-             else
+             else if (ch2 != EOF)
                {
                  UNGET (ch2);
                }
@@ -1284,14 +1297,14 @@ do_scrub_chars (size_t (*get) (char *, size_t), char *tostart, size_t tolen)
 #ifdef TC_ARM
          /* For the ARM, care is needed not to damage occurrences of \@
             by stripping the @ onwards.  Yuck.  */
-         if (to > tostart && *(to - 1) == '\\')
+         if ((to > tostart ? to[-1] : last_char) == '\\')
            /* Do not treat the @ as a start-of-comment.  */
            goto de_fault;
 #endif
 
 #ifdef WARN_COMMENTS
          if (!found_comment)
-           as_where (&found_comment_file, &found_comment);
+           found_comment_file = as_where (&found_comment);
 #endif
          do
            {
@@ -1321,8 +1334,8 @@ do_scrub_chars (size_t (*get) (char *, size_t), char *tostart, size_t tolen)
              else
                UNGET (quot);
            }
-         /* FALL THROUGH */
 #endif
+         /* Fall through.  */
 
        case LEX_IS_SYMBOL_COMPONENT:
          if (state == 10)
@@ -1464,6 +1477,10 @@ do_scrub_chars (size_t (*get) (char *, size_t), char *tostart, size_t tolen)
 
  fromeof:
   /* We have reached the end of the input.  */
+#ifdef TC_ARM
+  if (to > tostart)
+    last_char = to[-1];
+#endif
   return to - tostart;
 
  tofull:
@@ -1477,5 +1494,9 @@ do_scrub_chars (size_t (*get) (char *, size_t), char *tostart, size_t tolen)
   else
     saved_input = NULL;
 
+#ifdef TC_ARM
+  if (to > tostart)
+    last_char = to[-1];
+#endif
   return to - tostart;
 }