Home | History | Annotate | Line # | Download | only in lint1
emit.c revision 1.1
      1 /*	$NetBSD: emit.c,v 1.1 2021/04/18 20:02:56 rillig Exp $	*/
      2 # 3 "emit.c"
      3 
      4 /*
      5  * Test the symbol information that lint1 writes to a .ln file.  Using this
      6  * symbol information, lint2 later checks that the symbols are used
      7  * consistently across different translation units.
      8  */
      9 
     10 // omit the option '-g' to avoid having the GCC builtins in the .ln file.
     11 /* lint1-flags: -Sw */
     12 
     13 /*
     14  * Define some derived types.
     15  */
     16 
     17 struct struct_tag {
     18 	int member;
     19 };
     20 
     21 typedef struct {
     22 	int member;
     23 } struct_typedef;
     24 
     25 union union_tag {
     26 	int member;
     27 };
     28 
     29 typedef union {
     30 	int member;
     31 } union_typedef;
     32 
     33 enum enum_tag {
     34 	enum_tag_constant
     35 };
     36 
     37 typedef enum {
     38 	enum_typedef_constant
     39 } enum_typedef;
     40 
     41 /*
     42  * Variable declarations using the basic types (C99 6.2.5p14).
     43  *
     44  * Last synced with function outtype from emit1.c 1.43.
     45  */
     46 
     47 extern _Bool			extern__Bool;
     48 extern float _Complex 		extern__Complex_float;
     49 extern double _Complex		extern__Complex_double;
     50 extern long double _Complex	extern__Complex_long_double;
     51 extern char			extern_char;
     52 extern signed char		extern_signed_char;
     53 extern unsigned char		extern_unsigned_char;
     54 extern short			extern_short;
     55 extern signed short		extern_signed_short;
     56 extern unsigned short		extern_unsigned_short;
     57 extern int			extern_int;
     58 extern signed int		extern_signed_int;
     59 extern unsigned int		extern_unsigned_int;
     60 extern long			extern_long;
     61 extern signed long		extern_signed_long;
     62 extern unsigned long		extern_unsigned_long;
     63 extern long long		extern_long_long;
     64 extern signed long long		extern_signed_long_long;
     65 extern unsigned long long	extern_unsigned_long_long;
     66 extern float			extern_float;
     67 extern double			extern_double;
     68 extern long double		extern_long_double;
     69 
     70 /*
     71  * Variable declarations using derived types (C99 6.2.5p20).
     72  */
     73 
     74 extern void *			extern_pointer_to_void;
     75 extern int			extern_array_5_of_int[5];
     76 
     77 /*
     78  * Type tags are written to the .ln file as 'T kind length name', where 'kind'
     79  * is either 1, 2 or 3.  This is confusing at first since in 'T110struct_tag',
     80  * the apparent number 110 is to be read as 'tag kind 1, length 10'.
     81  */
     82 extern struct struct_tag	extern_struct_tag;
     83 extern struct_typedef		extern_struct_typedef;
     84 extern union union_tag		extern_union_tag;
     85 extern union_typedef		extern_union_typedef;
     86 extern enum enum_tag		extern_enum_tag;
     87 extern enum_typedef		extern_enum_typedef;
     88 
     89 extern struct {
     90 	int member;
     91 }				extern_anonymous_struct;
     92 extern union {
     93 	int member;
     94 }				extern_anonymous_union;
     95 extern enum {
     96 	anonymous_enum_constant
     97 }				extern_anonymous_enum;
     98 
     99 /*
    100  * Variable definitions.
    101  *
    102  * Static variables are not recorded in the .ln file.
    103  */
    104 
    105 extern int			declared_int;
    106 int				defined_int;
    107 static int			static_int;		/* expect: unused */
    108 
    109 /*
    110  * Type qualifiers.
    111  */
    112 
    113 extern const int		extern_const_int;
    114 extern volatile int		extern_volatile_int;
    115 extern const volatile int	extern_const_volatile_int;
    116 
    117 /*
    118  * Functions.
    119  */
    120 
    121 extern void return_void_unknown_parameters();
    122 extern /* implicit int */ return_implicit_int_unknown_parameters();
    123 
    124 /* For function declarations, the keyword 'extern' is optional. */
    125 extern void extern_return_void_no_parameters(void);
    126 /* implicit extern */ void return_void_no_parameters(void);
    127 static void static_return_void_no_parameters(void);	/* expect: declared */
    128 
    129 void taking_int(int);
    130 /* The 'const' parameter does not make a difference. */
    131 void taking_const_int(const int);
    132 void taking_int_double_bool(int, double, _Bool);
    133 void taking_struct_union_enum_tags(struct struct_tag, union union_tag,
    134     enum enum_tag);
    135 void taking_struct_union_enum_typedefs(struct_typedef, union_typedef,
    136     enum_typedef);
    137 
    138 void taking_varargs(const char *, ...);
    139 
    140 /*
    141  * This function does not affect anything outside this translation unit.
    142  * Naively there is no need to record this function in the .ln file, but it
    143  * is nevertheless recorded.  There's probably a good reason for recording
    144  * it.
    145  */
    146 static int static_function(void);			/* expect: declared */
    147