Module Name:    src
Committed By:   rillig
Date:           Thu May 12 00:28:01 UTC 2022

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_alignof.c d_alignof.exp
        src/usr.bin/xlint/lint1: cgram.y

Log Message:
lint: add support for __alignof__ expr, a GCC extension

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


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/d_alignof.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/d_alignof.exp
cvs rdiff -u -r1.410 -r1.411 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/d_alignof.c
diff -u src/tests/usr.bin/xlint/lint1/d_alignof.c:1.4 src/tests/usr.bin/xlint/lint1/d_alignof.c:1.5
--- src/tests/usr.bin/xlint/lint1/d_alignof.c:1.4	Thu May 12 00:18:35 2022
+++ src/tests/usr.bin/xlint/lint1/d_alignof.c	Thu May 12 00:28:01 2022
@@ -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 @@ plain_alignof_type(void)
 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)

Index: src/tests/usr.bin/xlint/lint1/d_alignof.exp
diff -u src/tests/usr.bin/xlint/lint1/d_alignof.exp:1.2 src/tests/usr.bin/xlint/lint1/d_alignof.exp:1.3
--- src/tests/usr.bin/xlint/lint1/d_alignof.exp:1.2	Thu May 12 00:18:35 2022
+++ src/tests/usr.bin/xlint/lint1/d_alignof.exp	Thu May 12 00:28:01 2022
@@ -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]

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.410 src/usr.bin/xlint/lint1/cgram.y:1.411
--- src/usr.bin/xlint/lint1/cgram.y:1.410	Sat Apr 30 22:31:23 2022
+++ src/usr.bin/xlint/lint1/cgram.y	Thu May 12 00:28:01 2022
@@ -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 @@ unary_expression:
 	| 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 */

Reply via email to