C and C++


LANG.STRUCT.SE.IOE : Indeterminate Order of Evaluation

要旨

One of the following occurs in a statement-level expression, or between two sequence points.

プロパティ

クラス名 Indeterminate Order of Evaluation
日本語クラス名 Indeterminate Order of Evaluation
クラス分類 信頼性 (reliability)
ニーモニック LANG.STRUCT.SE.IOE
カテゴリー
MisraC2023 MisraC2023: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
Misra2012 Misra2012: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
Misra2004 Misra2004:12.2 The value of an expression shall be the same under any order of evaluation that the standard permits
AUTOSARC++14 AUTOSARC++14:A5-0-1 The value of an expression shall be the same under any order of evaluation that the standard permits.
MisraC++2008 MisraC++2008:5-0-1 The value of an expression shall be the same under any order of evaluation that the standard permits.
MisraC++2023 MisraC++2023:4.6.1 Operations on a memory location shall be sequenced appropriately
CWE CWE:758 Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
CERT-C CERT-C:EXP10-C Do not depend on the order of evaluation of subexpressions or the order in which side effects take place
JSF++ JSF++:204.1 The value of an expression shall be the same under any order of evaluation that the standard permits.
JPL JPL:18 Make the order of evaluation in compound expressions explicit.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Indeterminate Order of Evaluation"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

int lang_struct_se_ioe(int x){
    int rv1 = ++x - ++x; /* 'Indeterminate Order of Evaluation' warning issued here
                          * - two unsequenced writes to x
                          * The different orderings have different outcomes:
                          * - if the compiler chooses to perform the first increment
                          *   before the second, (++x - ++x) == -1
                          * - if the compiler chooses to perform the second increment
                          *   before the first, (++x - ++x) == 1
                          */
    int rv2 = ++x + ++x; /* 'Indeterminate Order of Evaluation' warning issued here
                          * - two unsequenced writes to x
                          * Ihe value of (++x + ++x) is the same under
                          * all possible sequencings, but a warning is
                          * issued regardless.
                          */
    int rv3 = (--x > 0) || (++x < 0);      /* ok: || is a sequence point */
    int rv4 = x + 2*x;                     /* ok: no writes to x */
    ++rv4;                                 /* ok: the value read from rv4 contributes to the value written to rv4 */
    return ++rv1 + ++rv2 + ++rv3 + ++rv4;  /* ok: each object is only incremented once */
}

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。