Module Name: src Committed By: rillig Date: Sun Feb 27 19:32:51 UTC 2022
Modified Files: src/tests/usr.bin/xlint/lint1: msg_219.c msg_219.exp msg_292.c msg_292.exp src/usr.bin/xlint/lint1: cgram.y Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_219.c \ src/tests/usr.bin/xlint/lint1/msg_219.exp cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_292.c \ src/tests/usr.bin/xlint/lint1/msg_292.exp cvs rdiff -u -r1.385 -r1.386 src/usr.bin/xlint/lint1/cgram.y Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/msg_219.c diff -u src/tests/usr.bin/xlint/lint1/msg_219.c:1.4 src/tests/usr.bin/xlint/lint1/msg_219.c:1.5 --- src/tests/usr.bin/xlint/lint1/msg_219.c:1.4 Sun Feb 27 18:57:16 2022 +++ src/tests/usr.bin/xlint/lint1/msg_219.c Sun Feb 27 19:32:51 2022 @@ -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"; Index: src/tests/usr.bin/xlint/lint1/msg_219.exp diff -u src/tests/usr.bin/xlint/lint1/msg_219.exp:1.4 src/tests/usr.bin/xlint/lint1/msg_219.exp:1.5 --- src/tests/usr.bin/xlint/lint1/msg_219.exp:1.4 Sun Feb 27 18:57:16 2022 +++ src/tests/usr.bin/xlint/lint1/msg_219.exp Sun Feb 27 19:32:51 2022 @@ -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] Index: src/tests/usr.bin/xlint/lint1/msg_292.c diff -u src/tests/usr.bin/xlint/lint1/msg_292.c:1.3 src/tests/usr.bin/xlint/lint1/msg_292.c:1.4 --- src/tests/usr.bin/xlint/lint1/msg_292.c:1.3 Sun Feb 27 18:51:21 2022 +++ src/tests/usr.bin/xlint/lint1/msg_292.c Sun Feb 27 19:32:51 2022 @@ -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 @@ typedef int reveal_sizeof_c_c_c_w_w_w[-( const char c_w_c_w_c_w[] = "c2" - L"w2" /* expect+1: error: cannot concatenate wide and regular string literals [292] */ + L"w2" "c 4" - L"w 4" /* expect+1: error: cannot concatenate wide and regular string literals [292] */ + L"w 4" "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)]; Index: src/tests/usr.bin/xlint/lint1/msg_292.exp diff -u src/tests/usr.bin/xlint/lint1/msg_292.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_292.exp:1.4 --- src/tests/usr.bin/xlint/lint1/msg_292.exp:1.3 Sun Feb 27 18:51:21 2022 +++ src/tests/usr.bin/xlint/lint1/msg_292.exp Sun Feb 27 19:32:51 2022 @@ -2,7 +2,7 @@ msg_292.c(11): error: cannot concatenate 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] Index: src/usr.bin/xlint/lint1/cgram.y diff -u src/usr.bin/xlint/lint1/cgram.y:1.385 src/usr.bin/xlint/lint1/cgram.y:1.386 --- src/usr.bin/xlint/lint1/cgram.y:1.385 Sun Feb 27 11:40:29 2022 +++ src/usr.bin/xlint/lint1/cgram.y Sun Feb 27 19:32:51 2022 @@ -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 @@ anonymize(sym_t *s) %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 @@ identifier: /* 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); } ;