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: add support for __alignof__ expr, ...



details:   https://anonhg.NetBSD.org/src/rev/78e531a18947
branches:  trunk
changeset: 366051:78e531a18947
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu May 12 00:28:01 2022 +0000

description:
lint: add support for __alignof__ expr, a GCC extension

Seen in lib/libc/gmon/gmon.c:153.

diffstat:

 tests/usr.bin/xlint/lint1/d_alignof.c   |   9 +--------
 tests/usr.bin/xlint/lint1/d_alignof.exp |  10 +++-------
 usr.bin/xlint/lint1/cgram.y             |   9 +++++++--
 3 files changed, 11 insertions(+), 17 deletions(-)

diffs (79 lines):

diff -r 9599b208c244 -r 78e531a18947 tests/usr.bin/xlint/lint1/d_alignof.c
--- a/tests/usr.bin/xlint/lint1/d_alignof.c     Thu May 12 00:18:35 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_alignof.c     Thu May 12 00:28:01 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_alignof.c,v 1.4 2022/05/12 00:18:35 rillig Exp $     */
+/*     $NetBSD: d_alignof.c,v 1.5 2022/05/12 00:28:01 rillig Exp $     */
 # 3 "d_alignof.c"
 
 /* https://gcc.gnu.org/onlinedocs/gcc/Alignment.html */
@@ -28,21 +28,14 @@
 unsigned long
 leading_and_trailing_alignof_expr(void)
 {
-       /* FIXME: '__alignof__' must be recognized. */
-       /* FIXME: '__alignof__ expr' must be recognized. */
-       /* expect+1: error: syntax error '3' [249] */
        return __alignof__ 3;
 }
-/* expect-1: warning: function leading_and_trailing_alignof_expr falls off bottom without returning value [217] */
 
 unsigned long
 leading_alignof_expr(void)
 {
-       /* FIXME: '__alignof expr' must be recognized. */
-       /* expect+1: error: syntax error '3' [249] */
        return __alignof 3;
 }
-/* expect-1: warning: function leading_alignof_expr falls off bottom without returning value [217] */
 
 unsigned long
 plain_alignof_expr(void)
diff -r 9599b208c244 -r 78e531a18947 tests/usr.bin/xlint/lint1/d_alignof.exp
--- a/tests/usr.bin/xlint/lint1/d_alignof.exp   Thu May 12 00:18:35 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_alignof.exp   Thu May 12 00:28:01 2022 +0000
@@ -1,10 +1,6 @@
 d_alignof.c(24): error: function 'alignof' implicitly declared to return int [215]
 d_alignof.c(24): error: syntax error 'short' [249]
 d_alignof.c(25): warning: function plain_alignof_type falls off bottom without returning value [217]
-d_alignof.c(34): error: syntax error '3' [249]
-d_alignof.c(35): warning: function leading_and_trailing_alignof_expr falls off bottom without returning value [217]
-d_alignof.c(43): error: syntax error '3' [249]
-d_alignof.c(44): warning: function leading_alignof_expr falls off bottom without returning value [217]
-d_alignof.c(53): error: 'alignof' undefined [99]
-d_alignof.c(53): error: syntax error '3' [249]
-d_alignof.c(54): warning: function plain_alignof_expr falls off bottom without returning value [217]
+d_alignof.c(46): error: 'alignof' undefined [99]
+d_alignof.c(46): error: syntax error '3' [249]
+d_alignof.c(47): warning: function plain_alignof_expr falls off bottom without returning value [217]
diff -r 9599b208c244 -r 78e531a18947 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Thu May 12 00:18:35 2022 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Thu May 12 00:28:01 2022 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.410 2022/04/30 22:31:23 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.411 2022/05/12 00:28:01 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.410 2022/04/30 22:31:23 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.411 2022/05/12 00:28:01 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -621,6 +621,11 @@
        | T_SIZEOF T_LPAREN type_name T_RPAREN {
                $$ = build_sizeof($3);
          }
+       /* GCC extension */
+       | T_ALIGNOF unary_expression {
+               lint_assert($2 != NULL);
+               $$ = build_alignof($2->tn_type);
+         }
        /* K&R ---, C90 ---, C99 ---, C11 6.5.3 */
        | T_ALIGNOF T_LPAREN type_name T_RPAREN {
                /* TODO: c11ism */



Home | Main Index | Thread Index | Old Index