]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
expr.c (struct op): Add location.
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Fri, 31 Oct 2008 22:00:37 +0000 (22:00 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Fri, 31 Oct 2008 22:00:37 +0000 (22:00 +0000)
2008-10-31  Manuel López-Ibáñez  <manu@gcc.gnu.org>

libcpp/
* expr.c (struct op): Add location.
(_cpp_parse_expr): Propagate locations throught the stack
of expressions.
(reduce): Likewise.
(check_promotion): Use explicit location in errors.

testsuite/
* gcc.dg/cpp/Wsignprom.c: Add column numbers.
* gcc.dg/cpp/if-mpar.c: Likewise.

From-SVN: r141503

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/cpp/Wsignprom.c
gcc/testsuite/gcc.dg/cpp/if-mpar.c
libcpp/ChangeLog
libcpp/expr.c

index 616e10b5bf22f2dae62d4d9761e9bd6e5c874a86..9051361982e19179598e192eb3906238d8e74994 100644 (file)
@@ -1,3 +1,8 @@
+2008-10-31  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       * gcc.dg/cpp/Wsignprom.c: Add column numbers.
+       * gcc.dg/cpp/if-mpar.c: Likewise.
+
 2008-10-31  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/37967
index 44b5667b3f283a6ecb5e92accbc6198a37afc69d..7cdbccb3cac978ab3def02608ef9c6d5af12df41 100644 (file)
@@ -1,26 +1,26 @@
 /* { dg-do preprocess } */
-/* { dg-options "-Wall" } */
+/* { dg-options "-Wall -fshow-column" } */
 
 /* Test that -Wall emits the warnings about integer promotion changing
    the sign of an operand.  */
 
-#if -1 > 0U  /* { dg-warning "changes sign when promoted" } */
+#if -1 > 0U  /* { dg-warning "5:changes sign when promoted" } */
 #endif
 
-#if 0U + -1  /* { dg-warning "changes sign when promoted" } */
+#if 0U + -1  /* { dg-warning "10:changes sign when promoted" } */
 #endif
 
-#if 0U * -1  /* { dg-warning "changes sign when promoted" } */
+#if 0U * -1  /* { dg-warning "10:changes sign when promoted" } */
 #endif
 
-#if 1U / -2  /* { dg-warning "changes sign when promoted" } */
+#if 1U / -2  /* { dg-warning "10:changes sign when promoted" } */
 #endif
 
-#if -1 % 1U  /* { dg-warning "changes sign when promoted" } */
+#if -1 % 1U  /* { dg-warning "5:changes sign when promoted" } */
 #endif
 
-#if 1 ? 0U : -1  /* { dg-warning "changes sign when promoted" } */
+#if 1 ? 0U : -1  /* { dg-warning "14:changes sign when promoted" } */
 #endif
 
-#if 1 ? -1 : 0U  /* { dg-warning "changes sign when promoted" } */
+#if 1 ? -1 : 0U  /* { dg-warning "9:changes sign when promoted" } */
 #endif
index df200bbbab4615b31d6caca258f9a874d59a8edd..633cefcb44202ea30bad52fe66bebc0e4e507232 100644 (file)
@@ -4,21 +4,27 @@
    missing parenthesis message.  */
 
 /* { dg-do preprocess } */
+/* { dg-options "-fshow-column" } */
+#if (1          /* { dg-error "5:missing '\\)'" "missing ')' no. 1" } */
+#endif
+
+#if 2 * (3 + 4 /* { dg-error "9:missing '\\)'" "missing ')' no. 2" } */
+#endif
 
-#if (1          /* { dg-error "missing '\\)'" "missing ')' no. 1" } */
+#if (2))       /* { dg-error "8:missing '\\('" "missing '(' no. 1" } */
 #endif
 
-#if 2 * (3 + 4 /* { dg-error "missing '\\)'" "missing ')' no. 2" } */
+#if )          /* { dg-error "5:missing '\\('" "missing '(' no. 2" } */
 #endif
 
-#if (2))       /* { dg-error "missing '\\('" "missing '(' no. 1" } */
+#if 4)         /* { dg-error "6:missing '\\('" "missing '(' no. 3" } */
 #endif
 
-#if )          /* { dg-error "missing '\\('" "missing '(' no. 2" } */
+#if (          /* { dg-error "5:missing '\\)'" "missing ')' no. 3" } */
 #endif
 
-#if 4)         /* { dg-error "missing '\\('" "missing '(' no. 3" } */
+#if ((2 + 3) + 5 /* { dg-error "5:missing '\\)'" "missing ')' no. 3" } */
 #endif
 
-#if (          /* { dg-error "missing '\\)'" "missing ')' no. 3" } */
+#if ((2 + 3 + 5 /* { dg-error "6:missing '\\)'" "missing ')' no. 3" } */
 #endif
index 278bb06d6b85b2dd989d14bed66ed988137110fc..1d0d28c7b4eb3e2a239e0b6e542ae8e2de1966d2 100644 (file)
@@ -1,3 +1,11 @@
+2008-10-31  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       * expr.c (struct op): Add location.
+       (_cpp_parse_expr): Propagate locations throught the stack
+       of expressions.
+       (reduce): Likewise.
+       (check_promotion): Use explicit location in errors.
+
 2008-10-05  Matthew Gingell  <gingell@adacore.com>
            Arnaud Charlet  <charlet@adacore.com>
 
index c0e3cbd8006fc9345e50589462937c3e061ce9e0..591308b3619a5f236e38446ec304a40d07db4a4b 100644 (file)
@@ -32,6 +32,7 @@ struct op
 {
   const cpp_token *token;      /* The token forming op (for diagnostics).  */
   cpp_num value;               /* The value logically "right" of op.  */
+  source_location loc;          /* The location of this value.         */
   enum cpp_ttype op;
 };
 
@@ -875,6 +876,7 @@ _cpp_parse_expr (cpp_reader *pfile, bool is_if)
       lex_count++;
       op.token = cpp_get_token (pfile);
       op.op = op.token->type;
+      op.loc = op.token->src_loc;
 
       switch (op.op)
        {
@@ -978,6 +980,7 @@ _cpp_parse_expr (cpp_reader *pfile, bool is_if)
 
       top->op = op.op;
       top->token = op.token;
+      top->loc = op.token->src_loc;
     }
 
   /* The controlling macro expression is only valid if we called lex 3
@@ -1031,6 +1034,7 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op)
        case CPP_NOT:
        case CPP_COMPL:
          top[-1].value = num_unary_op (pfile, top->value, top->op);
+         top[-1].loc = top->loc;
          break;
 
        case CPP_PLUS:
@@ -1040,6 +1044,7 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op)
        case CPP_COMMA:
          top[-1].value = num_binary_op (pfile, top[-1].value,
                                         top->value, top->op);
+         top[-1].loc = top->loc;
          break;
 
        case CPP_GREATER:
@@ -1048,12 +1053,14 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op)
        case CPP_LESS_EQ:
          top[-1].value
            = num_inequality_op (pfile, top[-1].value, top->value, top->op);
+         top[-1].loc = top->loc;
          break;
 
        case CPP_EQ_EQ:
        case CPP_NOT_EQ:
          top[-1].value
            = num_equality_op (pfile, top[-1].value, top->value, top->op);
+         top[-1].loc = top->loc;
          break;
 
        case CPP_AND:
@@ -1061,16 +1068,19 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op)
        case CPP_XOR:
          top[-1].value
            = num_bitwise_op (pfile, top[-1].value, top->value, top->op);
+         top[-1].loc = top->loc;
          break;
 
        case CPP_MULT:
          top[-1].value = num_mul (pfile, top[-1].value, top->value);
+         top[-1].loc = top->loc;
          break;
 
        case CPP_DIV:
        case CPP_MOD:
          top[-1].value = num_div_op (pfile, top[-1].value,
                                      top->value, top->op);
+         top[-1].loc = top->loc;
          break;
 
        case CPP_OR_OR:
@@ -1082,6 +1092,7 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op)
          top->value.high = 0;
          top->value.unsignedp = false;
          top->value.overflow = false;
+         top->loc = top[1].loc;
          continue;
 
        case CPP_AND_AND:
@@ -1093,16 +1104,20 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op)
          top->value.high = 0;
          top->value.unsignedp = false;
          top->value.overflow = false;
+         top->loc = top[1].loc;
          continue;
 
        case CPP_OPEN_PAREN:
          if (op != CPP_CLOSE_PAREN)
            {
-             cpp_error (pfile, CPP_DL_ERROR, "missing ')' in expression");
+             cpp_error_with_line (pfile, CPP_DL_ERROR, 
+                                  top->token->src_loc,
+                                  0, "missing ')' in expression");
              return 0;
            }
          top--;
          top->value = top[1].value;
+         top->loc = top[1].loc;
          return top;
 
        case CPP_COLON:
@@ -1111,9 +1126,13 @@ reduce (cpp_reader *pfile, struct op *top, enum cpp_ttype op)
            {
              pfile->state.skip_eval--;
              top->value = top[1].value;
+             top->loc = top[1].loc;
            }
          else
-           top->value = top[2].value;
+           {
+             top->value = top[2].value;
+             top->loc = top[2].loc;
+           }
          top->value.unsignedp = (top[1].value.unsignedp
                                  || top[2].value.unsignedp);
          continue;
@@ -1168,12 +1187,12 @@ check_promotion (cpp_reader *pfile, const struct op *op)
   if (op->value.unsignedp)
     {
       if (!num_positive (op[-1].value, CPP_OPTION (pfile, precision)))
-       cpp_error (pfile, CPP_DL_WARNING,
-                  "the left operand of \"%s\" changes sign when promoted",
-                  cpp_token_as_text (pfile, op->token));
+       cpp_error_with_line (pfile, CPP_DL_WARNING, op[-1].loc, 0,
+                            "the left operand of \"%s\" changes sign when promoted",
+                            cpp_token_as_text (pfile, op->token));
     }
   else if (!num_positive (op->value, CPP_OPTION (pfile, precision)))
-    cpp_error (pfile, CPP_DL_WARNING,
+    cpp_error_with_line (pfile, CPP_DL_WARNING, op->loc, 0,
               "the right operand of \"%s\" changes sign when promoted",
               cpp_token_as_text (pfile, op->token));
 }