Home | History | Annotate | Line # | Download | only in lint1
msg_129.c revision 1.3
      1 /*	$NetBSD: msg_129.c,v 1.3 2021/01/30 23:05:08 rillig Exp $	*/
      2 # 3 "msg_129.c"
      3 
      4 // Test for message: expression has null effect [129]
      5 
      6 /* lint1-extra-flags: -h */
      7 
      8 typedef unsigned char uint8_t;
      9 typedef unsigned int uint32_t;
     10 
     11 _Bool side_effect(void);
     12 
     13 /*
     14  * Before tree.c 1.198 from 2021-01-30, the nested comma operators were
     15  * wrongly reported as having no side effect.
     16  *
     17  * The bug was that has_side_effect did not properly examine the sub-nodes.
     18  * The ',' operator has m_has_side_effect == false since it depends on its
     19  * operands whether the ',' actually has side effects.  For nested ','
     20  * operators, the function did not evaluate the operands deeply but only did
     21  * a quick shallow test on the m_has_side_effect property.  Since that is
     22  * false, lint thought that the whole expression would have no side effect.
     23  */
     24 void
     25 uint8_buffer_write_uint32(uint8_t *c, uint32_t l)
     26 {
     27 	(*(c++) = (uint8_t)(l & 0xff),
     28 	    *(c++) = (uint8_t)((l >> 8L) & 0xff),
     29 	    *(c++) = (uint8_t)((l >> 16L) & 0xff),
     30 	    *(c++) = (uint8_t)((l >> 24L) & 0xff));
     31 }
     32 
     33 void
     34 operator_comma(void)
     35 {
     36 	side_effect(), 0;		/* the 0 is redundant */
     37 	0, side_effect();		/* expect: 129 */
     38 
     39 	if (side_effect(), 0)		/* the 0 controls the 'if' */
     40 		return;
     41 	if (0, side_effect())		/* expect: 129 */
     42 		return;
     43 }
     44