Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: concatenate string literals from l...



details:   https://anonhg.NetBSD.org/src/rev/d12fa0e75421
branches:  trunk
changeset: 362459:d12fa0e75421
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 27 19:32:51 2022 +0000

description:
lint: concatenate string literals from left to right

Previously, the string literals "1" "2" "3" "4" were concatenated in the
order "23", "234", "1234".  This influenced the location of the
diagnostics for traditional C (which doesn't know concatenation at all)
and for mixing regular strings and wide strings.

Now the diagnostics occur exactly where they are expected.  The first
string literal defines whether the whole string is regular or wide, and
any further string literals must match it.

In traditional C mode, there are more diagnostics than before, but that
doesn't hurt since they are still correct and nobody uses lint in
traditional C mode anyway.

diffstat:

 tests/usr.bin/xlint/lint1/msg_219.c   |  16 ++++++++++++----
 tests/usr.bin/xlint/lint1/msg_219.exp |  11 ++++++++---
 tests/usr.bin/xlint/lint1/msg_292.c   |  16 ++++------------
 tests/usr.bin/xlint/lint1/msg_292.exp |   6 +++---
 usr.bin/xlint/lint1/cgram.y           |  17 +++--------------
 5 files changed, 30 insertions(+), 36 deletions(-)

diffs (148 lines):

diff -r 5adef149b0cb -r d12fa0e75421 tests/usr.bin/xlint/lint1/msg_219.c
--- a/tests/usr.bin/xlint/lint1/msg_219.c       Sun Feb 27 19:22:29 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_219.c       Sun Feb 27 19:32:51 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_219.c,v 1.4 2022/02/27 18:57:16 rillig Exp $       */
+/*     $NetBSD: msg_219.c,v 1.5 2022/02/27 19:32:51 rillig Exp $       */
 # 3 "msg_219.c"
 
 
@@ -7,13 +7,21 @@
 /* lint1-flags: -t -w */
 
 char concat1[] = "one";
-char concat2[] = "one" "two";                  /* expect: 219 */
-char concat3[] = "one" "two" "three";          /* expect: 219 */
-char concat4[] = "one" "two" "three" "four";   /* expect: 219 */
+/* expect+1: warning: concatenated strings are illegal in traditional C [219] */
+char concat2[] = "one" "two";
+/* expect+2: warning: concatenated strings are illegal in traditional C [219] */
+/* expect+1: warning: concatenated strings are illegal in traditional C [219] */
+char concat3[] = "one" "two" "three";
+/* expect+3: warning: concatenated strings are illegal in traditional C [219] */
+/* expect+2: warning: concatenated strings are illegal in traditional C [219] */
+/* expect+1: warning: concatenated strings are illegal in traditional C [219] */
+char concat4[] = "one" "two" "three" "four";
 
 char concat4lines[] =
        "one"
        /* expect+1: warning: concatenated strings are illegal in traditional C [219] */
        "two"
+       /* expect+1: warning: concatenated strings are illegal in traditional C [219] */
        "three"
+       /* expect+1: warning: concatenated strings are illegal in traditional C [219] */
        "four";
diff -r 5adef149b0cb -r d12fa0e75421 tests/usr.bin/xlint/lint1/msg_219.exp
--- a/tests/usr.bin/xlint/lint1/msg_219.exp     Sun Feb 27 19:22:29 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_219.exp     Sun Feb 27 19:32:51 2022 +0000
@@ -1,4 +1,9 @@
-msg_219.c(10): warning: concatenated strings are illegal in traditional C [219]
 msg_219.c(11): warning: concatenated strings are illegal in traditional C [219]
-msg_219.c(12): warning: concatenated strings are illegal in traditional C [219]
-msg_219.c(17): warning: concatenated strings are illegal in traditional C [219]
+msg_219.c(14): warning: concatenated strings are illegal in traditional C [219]
+msg_219.c(14): warning: concatenated strings are illegal in traditional C [219]
+msg_219.c(18): warning: concatenated strings are illegal in traditional C [219]
+msg_219.c(18): warning: concatenated strings are illegal in traditional C [219]
+msg_219.c(18): warning: concatenated strings are illegal in traditional C [219]
+msg_219.c(23): warning: concatenated strings are illegal in traditional C [219]
+msg_219.c(25): warning: concatenated strings are illegal in traditional C [219]
+msg_219.c(27): warning: concatenated strings are illegal in traditional C [219]
diff -r 5adef149b0cb -r d12fa0e75421 tests/usr.bin/xlint/lint1/msg_292.c
--- a/tests/usr.bin/xlint/lint1/msg_292.c       Sun Feb 27 19:22:29 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_292.c       Sun Feb 27 19:32:51 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_292.c,v 1.3 2022/02/27 18:51:21 rillig Exp $       */
+/*     $NetBSD: msg_292.c,v 1.4 2022/02/27 19:32:51 rillig Exp $       */
 # 3 "msg_292.c"
 
 // Test for message: cannot concatenate wide and regular string literals [292]
@@ -19,21 +19,13 @@
 
 const char c_w_c_w_c_w[] =
        "c2"
+       /* expect+1: error: cannot concatenate wide and regular string literals [292] */
        L"w2"
-       /* expect+1: error: cannot concatenate wide and regular string literals [292] */
        "c  4"
+       /* expect+1: error: cannot concatenate wide and regular string literals [292] */
        L"w  4"
-       /* expect+1: error: cannot concatenate wide and regular string literals [292] */
        "c      8"
        /* expect+1: error: cannot concatenate wide and regular string literals [292] */
        L"w      8";
-/*
- * Concatenating L"w2" with "c4" fails, keeping L"w2".
- * Concatenating L"w2" with L"w4" succeeds, resulting in L"w2w4".
- * Concatenating L"w2w4" with "c8" fails, keeping L"w2w4".
- * Concatenating L"w2w4" with L"w8" succeeds, resulting in L"w2w4w8".
- * Concatenating "c2" with L"w2w4w8" fails, keeping "c2".
- * The size of "c2" is 3.
- */
-/* expect+1: error: negative array dimension (-3) [20] */
+/* expect+1: error: negative array dimension (-15) [20] */
 typedef int reveal_sizeof_c_w_c_w_c_w[-(int)sizeof(c_w_c_w_c_w)];
diff -r 5adef149b0cb -r d12fa0e75421 tests/usr.bin/xlint/lint1/msg_292.exp
--- a/tests/usr.bin/xlint/lint1/msg_292.exp     Sun Feb 27 19:22:29 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_292.exp     Sun Feb 27 19:32:51 2022 +0000
@@ -2,7 +2,7 @@
 msg_292.c(13): error: cannot concatenate wide and regular string literals [292]
 msg_292.c(15): error: cannot concatenate wide and regular string literals [292]
 msg_292.c(18): error: negative array dimension (-15) [20]
-msg_292.c(24): error: cannot concatenate wide and regular string literals [292]
-msg_292.c(27): error: cannot concatenate wide and regular string literals [292]
+msg_292.c(23): error: cannot concatenate wide and regular string literals [292]
+msg_292.c(26): error: cannot concatenate wide and regular string literals [292]
 msg_292.c(29): error: cannot concatenate wide and regular string literals [292]
-msg_292.c(39): error: negative array dimension (-3) [20]
+msg_292.c(31): error: negative array dimension (-15) [20]
diff -r 5adef149b0cb -r d12fa0e75421 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sun Feb 27 19:22:29 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sun Feb 27 19:32:51 2022 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.385 2022/02/27 11:40:29 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.386 2022/02/27 19:32:51 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.385 2022/02/27 11:40:29 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.386 2022/02/27 19:32:51 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -292,7 +292,6 @@
 %type  <y_sym>         identifier_sym
 %type  <y_name>        identifier
 %type  <y_string>      string
-%type  <y_string>      string2
 
 %type  <y_tnode>       primary_expression
 %type  <y_tnode>       generic_selection
@@ -405,21 +404,11 @@
 /* see C99 6.4.5, string literals are joined by 5.1.1.2 */
 string:
          T_STRING
-       | T_STRING string2 {
-               $$ = cat_strings($1, $2);
-         }
-       ;
-
-/* see C99 6.4.5, string literals are joined by 5.1.1.2 */
-string2:
-         T_STRING {
+       | string T_STRING {
                if (tflag) {
                        /* concatenated strings are illegal in traditional C */
                        warning(219);
                }
-               $$ = $1;
-         }
-       | string2 T_STRING {
                $$ = cat_strings($1, $2);
          }
        ;



Home | Main Index | Thread Index | Old Index