Home | History | Annotate | Line # | Download | only in lint1
gcc_attribute_label.c revision 1.3
      1 /*	$NetBSD: gcc_attribute_label.c,v 1.3 2022/04/28 21:38:38 rillig Exp $	*/
      2 # 3 "gcc_attribute_label.c"
      3 
      4 /*
      5  * Tests for the GCC __attribute__ for labels.
      6  *
      7  * https://gcc.gnu.org/onlinedocs/gcc/Label-Attributes.html
      8  */
      9 
     10 void dead(void);
     11 
     12 void
     13 test(int i)
     14 {
     15 	if (i < 1000)
     16 		goto hot;
     17 error:
     18 	__attribute__((__cold__));
     19 	dead();
     20 
     21 hot:
     22 	__attribute__((__hot__));
     23 	if (i < 0)
     24 		goto error;
     25 }
     26 
     27 /* GCC allows a label to be marked as (possibly) unused. */
     28 void
     29 unused_labels(int x)
     30 {
     31 	switch (x) {
     32 	case 3:
     33 		__attribute__((__unused__))
     34 		break;
     35 	case 4:
     36 		goto label;
     37 	label:
     38 		__attribute__((__unused__))
     39 		return;
     40 	}
     41 
     42 	/*
     43 	 * The GCC attributes may only occur after a label; they cannot occur
     44 	 * before an arbitrary statement.
     45 	 */
     46 	__attribute__((__unused__))
     47 	/* expect+1: error: syntax error 'return' [249] */
     48 	return;
     49 }
     50