1 /* $NetBSD: gcc_attribute_label.c,v 1.4 2023/03/28 14:44:34 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 /* lint1-extra-flags: -X 351 */ 11 12 void dead(void); 13 14 void test(int i)15test(int i) 16 { 17 if (i < 1000) 18 goto hot; 19 error: 20 __attribute__((__cold__)); 21 dead(); 22 23 hot: 24 __attribute__((__hot__)); 25 if (i < 0) 26 goto error; 27 } 28 29 /* GCC allows a label to be marked as (possibly) unused. */ 30 void unused_labels(int x)31unused_labels(int x) 32 { 33 switch (x) { 34 case 3: 35 __attribute__((__unused__)) 36 break; 37 case 4: 38 goto label; 39 label: 40 __attribute__((__unused__)) 41 return; 42 } 43 44 /* 45 * The GCC attributes may only occur after a label; they cannot occur 46 * before an arbitrary statement. 47 */ 48 __attribute__((__unused__)) 49 /* expect+1: error: syntax error 'return' [249] */ 50 return; 51 } 52