|
4031 | 4031 | "<p>Rule 2.1, Rule 14.2</p>" |
4032 | 4032 | ] |
4033 | 4033 | } |
| 4034 | + }, |
| 4035 | + |
| 4036 | + "MISRA12_13.2": { |
| 4037 | + "tags": ["Language: C", "Standard: MISRA C 2012", "Category: Required", "Expressions"], |
| 4038 | + "key": "sti.SequencePointSideEffects", |
| 4039 | + "test": "MISRA12_13.2", |
| 4040 | + "name": "Published Standards/MISRA C 2012/13.2 The value of an expression and its persistent side effects shall be the same under all permitted evaluation orders", |
| 4041 | + "desc": { |
| 4042 | + "html": [ |
| 4043 | + "<p><b>Amplification</b></p>", |
| 4044 | + "<p>Between any two adjacent sequence points:</p>", |
| 4045 | + "<ol>", |
| 4046 | + " <li>No object shall be modified more than once;</li>", |
| 4047 | + " <li>All parts of the expression are considered when determining whether an object is read or modified, irrespective of any known values.</li>", |
| 4048 | + " <li>No object shall be both modified and read unless any such read of the object's value contributes towards computing the value to be stored into the object;</li>", |
| 4049 | + " <li>There shall be no more than one modification access with <i>volatile</i>-qualified or atomic type;</li>", |
| 4050 | + " <li>There shall be no more than one read access with <i>volatile</i>-qualified type;</li>", |
| 4051 | + " <li>There shall be no more than one read access to an object with atomic type.</li>", |
| 4052 | + "</ol>", |
| 4053 | + "<p><i>Note 1:</i> An object might be accessed indirectly, by means of a pointer or a called function, as well as being accessed directly by the expression.</p>", |
| 4054 | + "<p><i>Note 2:</i> This Amplification is intentionally stricter than the headline of the rule. As a result, expressions such as <code>x = x = 0;</code> are not permitted by this rule even though the value and the <i>persistent side effects</i>, provided that x is not <i>volatile</i>, are independent of the order of evaluation or <i>side effects</i>.</p>", |
| 4055 | + "<p><b>Rationale</b></p>", |
| 4056 | + "<p>The C Standard gives considerable flexibility to compilers when evaluating expressions. Most operators can have their operands evaluated in any order. The main exceptions are the logical AND, logical OR, conditional and comma operators, which act as sequence points between their operands.</p>", |
| 4057 | + "<p>Many of the common instances of unpredictable behaviour, associated with expression evaluation, can be avoided by following the advice given by this rule. However, in order to simplify this rule, it does restrict some forms which are well-defined.</p>", |
| 4058 | + "<p><b>Example</b></p>", |
| 4059 | + "<p>When the <code>COPY_ELEMENT</code> macro is invoked in this non-compliant example, <code>i</code> is read twice and modified twice. It is unspecified whether the order of operations on <code>i</code> is read-modify-read-modify or read-read-modify-modify.</p>", |
| 4060 | + "<pre><code language=\"C\">#define COPY_ELEMENT( index ) ( a[( index )] = b[( index )] )", |
| 4061 | + "", |
| 4062 | + "COPY_ELEMENT ( i++ );</code></pre>", |
| 4063 | + "<p>The order of evaluation of function arguments is unspecified, as is the order in which <i>side effects</i> occur, as shown in this non-compliant example.</p>", |
| 4064 | + "<pre><code language=\"C\">uint16_t i = 0;", |
| 4065 | + "", |
| 4066 | + "/*", |
| 4067 | + " * Unspecified whether this call is equivalent to:", |
| 4068 | + " * f ( 0, 0 )", |
| 4069 | + " * or f ( 0, 1 )", |
| 4070 | + " */", |
| 4071 | + "f ( i++, i );</code></pre>", |
| 4072 | + "<p><b>Implementation</b></p>", |
| 4073 | + "<p>This is a conservative implementation of MISRA's \"Undecidable, System\" rule. It analyses each full expression and splits it on sequence-point operators (<code>&&</code>, <code>||</code>, <code>?:</code>, <code>,</code>) into independent sub-regions. Within each region, plain variable accesses are classified as modifications (assignment LHS, compound-assignment LHS, <code>++</code> / <code>--</code> operand) or reads. A variable is flagged when:</p>", |
| 4074 | + "<ul>", |
| 4075 | + " <li>It is modified more than once (subrule 1) — e.g. <code>i++ + i++</code>, <code>x = x = 0</code>.</li>", |
| 4076 | + " <li>It is modified once and also read where the read is not part of computing the new value (subrule 3) — e.g. <code>a[i] = i++</code>, <code>f(i, i++)</code>.</li>", |
| 4077 | + "</ul>", |
| 4078 | + "<p>Subrules 4–6 (additional <i>volatile</i> and atomic constraints) and indirect access via pointers or function calls (Note 1) are not analysed. Modifications targeting expressions that are not plain variable references (members, array elements, dereferences) are not tracked.</p>", |
| 4079 | + "<p><b>See also</b></p>", |
| 4080 | + "<p>Dir 4.9, Rule 13.1, Rule 13.3, Rule 13.4</p>" |
| 4081 | + ] |
| 4082 | + } |
| 4083 | + }, |
| 4084 | + |
| 4085 | + "MISRA23_13.2": { |
| 4086 | + "tags": ["Language: C", "Standard: MISRA C 2023", "Category: Required", "Expressions"], |
| 4087 | + "key": "sti.SequencePointSideEffects", |
| 4088 | + "test": "MISRA12_13.2", |
| 4089 | + "name": "Published Standards/MISRA C 2023/13.2 The value of an expression and its persistent side effects shall be the same under all permitted evaluation orders", |
| 4090 | + "desc": { |
| 4091 | + "html": [ |
| 4092 | + "<p><b>Amplification</b></p>", |
| 4093 | + "<p>Between any two adjacent sequence points:</p>", |
| 4094 | + "<ol>", |
| 4095 | + " <li>No object shall be modified more than once;</li>", |
| 4096 | + " <li>All parts of the expression are considered when determining whether an object is read or modified, irrespective of any known values.</li>", |
| 4097 | + " <li>No object shall be both modified and read unless any such read of the object's value contributes towards computing the value to be stored into the object;</li>", |
| 4098 | + " <li>There shall be no more than one modification access with <i>volatile</i>-qualified or atomic type;</li>", |
| 4099 | + " <li>There shall be no more than one read access with <i>volatile</i>-qualified type;</li>", |
| 4100 | + " <li>There shall be no more than one read access to an object with atomic type.</li>", |
| 4101 | + "</ol>", |
| 4102 | + "<p><i>Note 1:</i> An object might be accessed indirectly, by means of a pointer or a called function, as well as being accessed directly by the expression.</p>", |
| 4103 | + "<p><i>Note 2:</i> This Amplification is intentionally stricter than the headline of the rule. As a result, expressions such as <code>x = x = 0;</code> are not permitted by this rule even though the value and the <i>persistent side effects</i>, provided that x is not <i>volatile</i>, are independent of the order of evaluation or <i>side effects</i>.</p>", |
| 4104 | + "<p><b>Implementation</b></p>", |
| 4105 | + "<p>Conservative subset: see MISRA C 2012 Rule 13.2 entry for details.</p>", |
| 4106 | + "<p><b>See also</b></p>", |
| 4107 | + "<p>Dir 4.9, Rule 13.1, Rule 13.3, Rule 13.4</p>" |
| 4108 | + ] |
| 4109 | + } |
| 4110 | + }, |
| 4111 | + |
| 4112 | + "MISRA25_13.2": { |
| 4113 | + "tags": ["Language: C", "Standard: MISRA C 2025", "Category: Required", "Expressions"], |
| 4114 | + "key": "sti.SequencePointSideEffects", |
| 4115 | + "test": "MISRA12_13.2", |
| 4116 | + "name": "Published Standards/MISRA C 2025/13.2 The value of an expression and its persistent side effects shall be the same under all permitted evaluation orders and shall be independent from thread interleaving", |
| 4117 | + "desc": { |
| 4118 | + "html": [ |
| 4119 | + "<p><b>Amplification</b></p>", |
| 4120 | + "<p>Between any two adjacent sequence points:</p>", |
| 4121 | + "<ol>", |
| 4122 | + " <li>No object shall be modified more than once;</li>", |
| 4123 | + " <li>All parts of the expression are considered when determining whether an object is read or modified, irrespective of any known values.</li>", |
| 4124 | + " <li>No object shall be both modified and read unless any such read of the object's value contributes towards computing the value to be stored into the object;</li>", |
| 4125 | + " <li>There shall be no more than one modification access with <i>volatile</i>-qualified or atomic type;</li>", |
| 4126 | + " <li>There shall be no more than one read access with <i>volatile</i>-qualified type;</li>", |
| 4127 | + " <li>There shall be no more than one read access to an object with atomic type.</li>", |
| 4128 | + "</ol>", |
| 4129 | + "<p><i>Note 1:</i> An object might be accessed indirectly, by means of a pointer or a called function, as well as being accessed directly by the expression.</p>", |
| 4130 | + "<p><i>Note 2:</i> This Amplification is intentionally stricter than the headline of the rule. As a result, expressions such as <code>x = x = 0;</code> are not permitted by this rule even though the value and the <i>persistent side effects</i>, provided that x is not <i>volatile</i>, are independent of the order of evaluation or <i>side effects</i>.</p>", |
| 4131 | + "<p><b>Implementation</b></p>", |
| 4132 | + "<p>Conservative subset: see MISRA C 2012 Rule 13.2 entry for details. The thread-interleaving aspect of the 2025 rule (subrules 4–6 covering volatile and atomic types) is not analysed.</p>", |
| 4133 | + "<p><b>See also</b></p>", |
| 4134 | + "<p>Dir 4.9, Rule 13.1, Rule 13.3, Rule 13.4</p>" |
| 4135 | + ] |
| 4136 | + } |
4034 | 4137 | } |
4035 | 4138 | } |
0 commit comments