gcc_attribute_var.c revision 1.8
11.8Srillig/*	$NetBSD: gcc_attribute_var.c,v 1.8 2023/03/28 14:44:34 rillig Exp $	*/
21.1Srillig# 3 "gcc_attribute_var.c"
31.1Srillig
41.1Srillig/*
51.1Srillig * Tests for the GCC __attribute__ for variables.
61.1Srillig *
71.1Srillig * https://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html
81.1Srillig */
91.1Srillig
101.8Srillig/* lint1-extra-flags: -X 351 */
111.8Srillig
121.1Srilligvoid
131.1Srilligwrite_to_page(unsigned index, char ch)
141.1Srillig{
151.1Srillig	static char page[4096]
161.1Srillig	    __attribute__((__aligned__(4096)));
171.1Srillig
181.1Srillig	page[index] = ch;
191.1Srillig}
201.1Srillig
211.1Srilligvoid
221.1Srilligplacement(
231.1Srillig    __attribute__((__deprecated__)) int before,
241.1Srillig    int __attribute__((__deprecated__)) between,
251.1Srillig    int after __attribute__((__deprecated__))
261.1Srillig);
271.1Srillig
281.2Srilligvoid println(void);
291.2Srillig
301.2Srillig/*
311.2Srillig * Since cgram.y 1.294 from 2021-07-10, lint did not accept declarations that
321.2Srillig * started with __attribute__, due to a newly and accidentally introduced
331.2Srillig * shift/reduce conflict in the grammar.
341.2Srillig *
351.2Srillig * A GCC extension allows statement of the form __attribute__((fallthrough)),
361.2Srillig * thus starting with __attribute__.  This is the 'shift' in the conflict.
371.2Srillig * The 'reduce' in the conflict was begin_type.
381.2Srillig *
391.2Srillig * Before cgram 1.294, the gcc_attribute was placed outside the pair of
401.2Srillig * begin_type/end_type, exactly to resolve this conflict.
411.2Srillig *
421.2Srillig * Conceptually, it made sense to put the __attribute__((unused)) between
431.2Srillig * begin_type and end_type, to make it part of the declaration-specifiers.
441.2Srillig * This change introduced the hidden conflict though.
451.2Srillig *
461.2Srillig * Interestingly, the number of shift/reduce conflicts did not change in
471.2Srillig * cgram 1.294, the conflicts were just resolved differently than before.
481.2Srillig *
491.2Srillig * To prevent this from happening again, make sure that declarations as well
501.2Srillig * as statements can start with gcc_attribute.
511.2Srillig */
521.2Srilligvoid
531.2Srilligambiguity_for_attribute(void)
541.2Srillig{
551.2Srillig	__attribute__((unused)) _Bool var1;
561.2Srillig
571.2Srillig	switch (1) {
581.2Srillig	case 1:
591.2Srillig		println();
601.3Srillig		/* expect+1: warning: 'var2' unused in function 'ambiguity_for_attribute' [192] */
611.2Srillig		__attribute__((unused)) _Bool var2;
621.2Srillig		__attribute__((fallthrough));
631.2Srillig		case 2:
641.2Srillig			println();
651.2Srillig	}
661.2Srillig}
671.2Srillig
681.4Srilligvoid
691.4Srilligattribute_after_array_brackets(
701.4Srillig    const char *argv[] __attribute__((__unused__))
711.4Srillig)
721.4Srillig{
731.4Srillig}
74