MISRA C:2012 準拠の概要表
MathWorks® は、Simulink® モデルおよび Stateflow® チャートから Embedded Coder® で生成された C コードを MISRA™ C:2012 コーディング規約に照らして評価しています。この取り組みの結果を、以下の準拠概要表で参照できます。また、これらの表では、準拠するために使用される方法を示し、生成されたコードが準拠から逸脱する可能性がある方法についても説明します。
準拠 - ルールまたは命令への準拠は、コード生成プロセス、モデル化の推奨事項、またはモデル アドバイザー チェックに従うことで実現します。該当する場合は、命令またはルールを満たすために実行できる準拠方法やアクションに関連する情報を示す説明メモが表にリストされています。
逸脱 - ルールまたは命令は準拠していません。
これらの表は、『MISRA C:2012 Guidelines for the Use of C Language in Critical Systems』ドキュメントのセクション 5.3 の要件に従ってプロジェクトの MISRA C:2012 準拠表明を準備する際に使用できます。これらの表は、公開されている MISRA C:2012 メイン ドキュメント、MISRA C:2012 Amendment 1、MISRA C:2012 Amendment 2、および MISRA C:2012 Amendment 3 と一致します。Embedded Coder はマルチスレッディングとアトミック操作を含むコードを生成しないため、表には MISRA C:2012 Amendment 4 は含まれていません。
表内のカテゴリは、自動生成コード用に記載された MISRA C:2012 ガイドラインの付録 E に基づいています。必須カテゴリと必要カテゴリの場合のみ使用できます (勧告カテゴリと可読性カテゴリの場合は使用できません)。
メモ
Embedded Coder から生成されたコードは、これらのコーディング ガイドラインの大部分に適合します。これらの表のルールまたは命令に準拠していないステータスは、自動生成コード用に特定された必須カテゴリおよび必要カテゴリに分類されません。評価にはユーザー定義関数は含まれません。
実装
コンパイルとビルド
要件のトレーサビリティ
コード設計
| 命令a, b | 説明c | カテゴリ | 準拠 |
|---|---|---|---|
| 命令 4.1 | Run-time failures shall be minimized. | 必要 | 準拠:
|
| 命令 4.3 | Assembly language shall be encapsulated and isolated. | 必要 | 準拠:
|
| 命令 4.6 | typedefs that indicate size and signedness should be used in place of the basic numerical types. | 勧告 | 適用不可。 |
| 命令 4.7d | If a function returns error information, then that error information shall be tested. | 必要 | 準拠:
逸脱:
|
| 命令 4.10 | Precautions shall be taken in order to prevent the contents of a header file being included more than once. | 必要 | 準拠 |
| 命令 4.11 | The validity of values passed to library functions shall be checked. | 必要 | 準拠:
|
| 命令 4.12 | Dynamic memory allocation shall not be used. | 必要 | 準拠:
|
| 命令 4.14 | The validity of values received from external sources shall be checked. | 必要 | 準拠 |
| 命令 4.15 | Evaluation of floating-point expressions shall not lead to the undetected generation of infinities and NaNs. | 必要 | 準拠 |
a Directive 4.14 is from MISRA Amendment 1. b Directive 4.15 is from MISRA Amendment 3. c Copyright © The MISRA Consortium Limited, 2022. d Polyspace® Bug Finder™ might report a violation of Directive 4.7 for user-defined functions when there is no knowledge about whether the return value contains error information. | |||
標準 C 環境
| ルールa, b | 説明c | カテゴリ | 準拠 |
|---|---|---|---|
| 1.1 | The program shall contain no violations of the standard C syntax and constraints, and shall not exceed the implementation's translation limits. | 必要 | 準拠 |
| 1.3 | There shall be no occurrence of undefined or critical unspecified behaviour. | 必要 | 準拠 |
| 1.4 | Emergent language features shall not be used. | 必要 | 準拠 |
| 1.5 | Obsolescent language features shall not be used. | 必要 | 非準拠 |
a Rule 1.4 is from MISRA Amendment 2. b Rule 1.5 is from MISRA Amendment 3. c Copyright © The MISRA Consortium Limited, 2022. | |||
未使用コード
コメント
文字セットと字句規則
識別子
| ルール | 説明a | カテゴリb | 準拠 |
|---|---|---|---|
| 5.1 | External identifiers shall be distinct. | 必要 | 準拠:
|
| 5.2 | Identifiers declared in the same scope and name space shall be distinct. | 必要 | 準拠:
|
| 5.3 | An identifier declared in an inner scope shall not hide an identifier declared in an outer scope. | 勧告 | 非準拠 |
| 5.4 | Macro identifiers shall be distinct. | 必要 | 準拠:
|
| 5.5 | Identifiers shall be distinct from macro names. | 必要 | 準拠:
|
| 5.6 | A typedef name shall be a unique identifier. | 必要 | 準拠:
|
| 5.7 | A tag name shall be a unique identifier. | 必要 | 準拠:
|
| 5.8 | Identifiers that define objects or functions with external linkage shall be unique. | 必要 | 準拠:
|
a Copyright © The MISRA Consortium Limited, 2022. b Guideline identifies Rule 5.3 as Required for manually generated code. | |||
型
リテラルと定数
| ルールa | 説明b | カテゴリc | 準拠 |
|---|---|---|---|
| 7.1 | Octal constants shall not be used. | 勧告 | 準拠 |
| 7.2 | A "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned type. | 可読性 | 準拠 |
| 7.3 | The lowercase character "l" shall not be used in a literal suffix. | 可読性 | 準拠 |
| 7.4 | A string literal shall not be assigned to an object unless the object's type is "pointer to const-qualified char". | 必要 | 準拠 |
| 7.5 | The argument of an integer constant macro shall have an appropriate form. | 必須 | 準拠 |
a Rule 7.5 is from MISRA Amendment 3. b Copyright © The MISRA Consortium Limited, 2022. c Guideline identifies Rules 7.1, 7.2, and 7.3 as Required for manually generated code. | |||
宣言と定義
| ルールa | 説明b | カテゴリc | 準拠 |
|---|---|---|---|
| 8.1 | Types shall be explicitly specified. | 必要 | 準拠 |
| 8.2 | Function types shall be in prototype form with named parameters. | 必要 | 準拠:
|
| 8.3 | All declarations of an object or function shall use the same names and type qualifiers. | 必要 | 準拠 |
| 8.4 | A compatible declaration shall be visible when an object or function with external linkage is defined. | 勧告 | 非準拠 |
| 8.5 | An external object or function shall be declared once in one and only one file. | 勧告 | 非準拠 |
| 8.6 | An identifier with external linkage shall have exactly one external definition. | 必要 | 準拠 |
| 8.8 | The static storage class specifier shall be used in all declarations of objects and functions that have internal linkage. | 必要 | 準拠 |
| 8.10 | An inline function shall be declared with the static storage class. | 必要 | 準拠 |
| 8.12 | Within an enumerator list, the value of an implicitly-specified enumeration constant shall be unique. | 必要 | 準拠:
|
| 8.14 | The restrict type qualifier shall not be used. | 勧告 | 準拠 |
| 8.15 | All declarations of an object with an explicit alignment specification shall specify the same alignment. | 必要 | 準拠 |
a Rule 8.15 is from MISRA Amendment 3. b Copyright © The MISRA Consortium Limited, 2022. c Guideline identifies Rule 8.4, 8.5, and 8.14 as Required for manually generated code. | |||
初期化
| ルール | 説明a | カテゴリb | 準拠 |
|---|---|---|---|
| 9.1 | The value of an object with automatic storage duration shall not be read before it has been set. | 必須 | 準拠:
|
| 9.2 | The initializer for an aggregate or union shall be enclosed in braces. | 可読性 | 非準拠 |
| 9.3 | Arrays shall not be partially initialized. | 可読性 | 非準拠 |
| 9.4 | An element of an object shall not be initialized more than once. | 必要 | 準拠 |
| 9.5 | Where designated initializers are used to initialize an array object the size of the array shall be specified explicitly. | 可読性 | 準拠 |
a Copyright © The MISRA Consortium Limited, 2022. b Guideline identifies Rule 9.2, 9.3, and 9.5 as Required for manually generated code. | |||
実質的な型モデル
| ルール | 説明a | カテゴリb | 準拠 |
|---|---|---|---|
| 10.1 | Operands shall not be of an inappropriate essential type. | 勧告 | 非準拠
|
| 10.2 | Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations. | 勧告 | 準拠 |
| 10.3 | The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category. | 勧告 | 準拠
|
| 10.4 | Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category. | 勧告 | 非準拠
|
| 10.6 | The value of a composite expression shall not be assigned to an object with wider essential type. | 勧告 | 非準拠 |
| 10.7 | If a composite expression is used as one operand of an operator in which the usual arithmetic conversions are performed then the other operand shall not have wider essential type. | 勧告 | 非準拠 |
| 10.8 | The value of a composite expression shall not be cast to a different essential type category or a wider essential type. | 勧告 | 非準拠 |
a Copyright © The MISRA Consortium Limited, 2022. b Guideline identifies Rule 10.1, 10.2, 10.3, 10.4, 10.6, 10.7, and 10.8 as Required for manually generated code. | |||
ポインター型の変換
| ルール | 説明a | カテゴリb | 準拠 |
|---|---|---|---|
| 11.1 | Conversions shall not be performed between a pointer to a function and any other type. | 必要 | 準拠 |
| 11.2 | Conversions shall not be performed between a pointer to an incomplete type and any other type. | 必要 | 準拠 |
| 11.3 | A cast shall not be performed between a pointer to object type and a pointer to a different object type. | 必要 | 準拠:
|
| 11.6 | A cast shall not be performed between pointer to void and an arithmetic type. | 必要 | 準拠 |
| 11.7 | A cast shall not be performed between pointer to object and a non-integer arithmetic type. | 必要 | 準拠 |
| 11.8 | A cast shall not remove any const or volatile qualification from the type pointed to by a pointer. | 必要 | 準拠:
|
| 11.9 | The macro NULL shall be the only permitted form of integer null pointer constant. | 可読性 | 非準拠 |
a Copyright © The MISRA Consortium Limited, 2022. b Guideline identifies Rule 11.9 as Required for manually generated code. | |||
式
| ルールa | 説明b | カテゴリ | 準拠 |
|---|---|---|---|
| 12.2 | The right hand operand of a shift operator shall lie in the range zero to one less than the width in bits of the essential type of the left hand operand. | 必要 | 準拠:
|
| 12.5 | The sizeof operator shall not have an operand which is a function parameter declared as "array of type". | 必須 | 準拠 |
a Rule 12.5 is from MISRA Amendment 1. b Copyright © The MISRA Consortium Limited, 2022. | |||
副作用
| ルール | 説明a | カテゴリ | 準拠 |
|---|---|---|---|
| 13.1 | Initializer lists shall not contain persistent side effects. | 必要 | 準拠 |
| 13.2 | The value of an expression and its persistent side effects shall be the same under all permitted evaluation orders. | 必要 | 準拠:
|
| 13.5 | The right hand operand of a logical && or || operator shall not contain persistent side effects. | 必要 | 準拠:
逸脱:
|
| 13.6 | The operand of the sizeof operator shall not contain any expression which has potential side effects. | 必要 | 準拠 |
a Copyright © The MISRA Consortium Limited, 2022. | |||
コントロール ステートメントの式
| ルール | 説明a | カテゴリb | 準拠 |
|---|---|---|---|
| 14.1 | A loop counter shall not have essentially floating type. | 勧告 | 非準拠 |
| 14.2 | A for loop shall be well-formed. | 可読性 | 準拠:
|
| 14.3 | Controlling expressions shall not be invariant. | 必要 | 準拠:
|
| 14.4 | The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type. | 勧告 | 非準拠 |
a Copyright © The MISRA Consortium Limited, 2022. b Guideline identifies Rule 14.1, 14.2, and 14.4 as Required for manually generated code. | |||
フロー制御
| ルール | 説明a | カテゴリb | 準拠 |
|---|---|---|---|
| 15.2 | The goto statement shall jump to a label declared later in the same function. | 勧告 | 準拠 |
| 15.3 | Any label referenced by a goto statement shall be declared in the same block, or in any block enclosing the goto statement. | 勧告 | 準拠 |
| 15.6 | The body of an iteration-statement or a selection-statement shall be a compound-statement. | 必要 | 準拠 |
| 15.7 | All if ... else if constructs shall be terminated with an else statement. | 可読性 | 準拠 |
a Copyright © The MISRA Consortium Limited, 2022. b Guideline identifies Rule 15.2, 15.3, and 15.7 as Required for manually generated code. | |||
switch ステートメント
| ルール | 説明a | カテゴリb | 準拠 |
|---|---|---|---|
| 16.1 | All switch statements shall be well-formed. | 勧告 | 非準拠 |
| 16.2 | A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement. | 勧告 | 準拠 |
| 16.3 | An unconditional break statement shall terminate every switch-clause. | 勧告 | 準拠 |
| 16.4 | Every switch statement shall have a default label. | 勧告 | 準拠:
|
| 16.5 | A default label shall appear as either the first or the last switch label of a switch statement. | 勧告 | 準拠 |
| 16.6 | Every switch statement shall have at least two switch-clauses. | 勧告 | 準拠 |
| 16.7 | A switch-expression shall not have essentially Boolean type. | 勧告 | 準拠 |
a Copyright © The MISRA Consortium Limited, 2022. b Guideline identifies Rule 16.1, 16.2, 16.3, 16.4, 16.5, 16.6, and 16.7 as Required for manually generated code. | |||
関数
| ルールa | 説明b | カテゴリc | 準拠 |
|---|---|---|---|
| 17.1 | The features of <stdarg.h> shall not be used. | 必要 | 準拠 |
| 17.2 | Functions shall not call themselves, either directly or indirectly. | 必要 | 準拠:
|
| 17.3 | A function shall not be declared implicitly. | 必須 | 準拠:
|
| 17.4 | All exit paths from a function with non-void return type shall have an explicit return statement with an expression. | 必須 | 準拠 |
| 17.5 | The function argument corresponding to a parameter declared to have an array type shall have an appropriate number of elements. | 必要 | 準拠 |
| 17.6 | The declaration of an array parameter shall not contain the static keyword between the [ ]. | 必須 | 準拠 |
| 17.7 | The value returned by a function having non-void return type shall be used. | 可読性 | 非準拠 |
| 17.9 | A function declared with a _Noreturn function specifier shall not return to its caller. | 必須 | 準拠 |
| 17.10 | A function declared with a _Noreturn function specifier shall have void return type. | 必要 | 準拠 |
| 17.13 | A function type shall not be type qualified. | 必要 | 準拠 |
a Rule 17.9, 17.10 and 17.13 are from MISRA Amendment 3. b Copyright © The MISRA Consortium Limited, 2022. c Guideline identifies Rule 17.7 as Required for manually generated code. | |||
ポインターと配列
| ルールa | 説明b | カテゴリ | 準拠 |
|---|---|---|---|
| 18.1 | A pointer resulting from arithmetic on a pointer operand shall address an element of the same array as that pointer operand. | 必要 | 準拠 |
| 18.2 | Subtraction between pointers shall only be applied to pointers that address elements of the same array. | 必要 | 準拠 |
| 18.3 | The relational operators >, >=, < and <= shall not be applied to objects of pointer type except where they point into the same object. | 必要 | 準拠 |
| 18.6 | The address of an object with automatic storage shall not be copied to another object that persists after the first object has ceased to exist. | 必要 | 準拠 |
| 18.7 | Flexible array members shall not be declared. | 必要 | 準拠 |
| 18.8 | Variable-length array types shall not be used. | 必要 | 準拠 |
| 18.9 | An object with temporary lifetime shall not undergo array-to-pointer conversion. | 必要 | 準拠 |
a Rule 18.9 is from MISRA Amendment 1. b Copyright © The MISRA Consortium Limited, 2022. | |||
重複するストレージ
プリプロセッサ命令
| ルール | 説明a | カテゴリ | 準拠 |
|---|---|---|---|
| 20.2 | The ', " or \ characters and the /* or // character sequences shall not occur in a header file name. | 必要 | 準拠 |
| 20.3 | The #include directive shall be followed by either a <filename> or "filename" sequence. | 必要 | 準拠 |
| 20.4 | A macro shall not be defined with the same name as a keyword. | 必要 | 準拠 |
| 20.6 | Tokens that look like a preprocessing directive shall not occur within a macro argument. | 必要 | 準拠 |
| 20.7 | Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses. | 必要 | 準拠 |
| 20.8 | The controlling expression of a #if or #elif preprocessing directive shall evaluate to 0 or 1. | 必要 | 準拠 |
| 20.9 | All identifiers used in the controlling expression of #if or #elif preprocessing directives shall be #define'd before evaluation. | 必要 | 準拠 |
| 20.11 | A macro parameter immediately following a # operator shall not immediately be followed by a ## operator. | 必要 | 準拠 |
| 20.12 | A macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as an operand to these operators. | 必要 | 準拠 |
| 20.13 | A line whose first token is # shall be a valid preprocessing directive. | 必要 | 準拠 |
| 20.14 | All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if, #ifdef or #ifndef directive to which they are related. | 必要 | 準拠 |
a Copyright © The MISRA Consortium Limited, 2022. | |||
標準ライブラリ
| ルールa, b, c | 説明d | カテゴリ | 準拠 |
|---|---|---|---|
| 21.1 | #define and #undef shall not be used on a reserved identifier or reserved macro name. | 必要 | 準拠:
|
| 21.2 | A reserved identifier or reserved macro name shall not be declared. | 必要 | 準拠:
|
| 21.3 | The memory allocation and deallocation functions of <stdlib.h> shall not be used. | 必要 | 準拠:
|
| 21.4 | The standard header file <setjmp.h> shall not be used. | 必要 | 準拠 |
| 21.5 | The standard header file <signal.h> shall not be used. | 必要 | 準拠 |
| 21.6 | The Standard Library input/output functions shall not be used. | 必要 | 準拠:
|
| 21.7 | The Standard Library functions atof, atoi, atol and atoll of <stdlib.h> shall not be used. | 必要 | 準拠 |
| 21.8 | The Standard Library termination functions of <stdlib.h> shall not be used. | 必要 | 準拠 |
| 21.9 | The Standard Library functions bsearch and qsort of <stdlib.h> shall not be used. | 必要 | 準拠 |
| 21.10 | The Standard Library time and date functions shall not be used. | 必要 | 準拠 |
| 21.12 | The standard header file <fenv.h> shall not be used. | 必要 | 準拠 |
| 21.13 | Any value passed to a function in <ctype.h> shall be representable as an unsigned char or be the value EOF. | 必須 | 準拠 |
| 21.14 | The Standard Library function memcmp shall not be used to compare null terminated strings. | 必要 | 準拠 |
| 21.15 | The pointer arguments to the Standard Library functions memcpy, memmove and memcmp shall be pointers to qualified or unqualified versions of compatible types. | 必要 | 準拠 |
| 21.16 | The pointer arguments to the Standard Library function memcmp shall point to either a pointer type, an essentially signed type, an essentially unsigned type, an essentially Boolean type or an essentially enum type. | 必要 | 準拠 |
| 21.17 | Use of the string handling functions from <string.h> shall not result in accesses beyond the bounds of the objects referenced by their pointer parameters. | 必須 | 準拠 |
| 21.18 | The size_t argument passed to any function in <string.h> shall have an appropriate value. | 必須 | 準拠 |
| 21.19 | The pointers returned by the Standard Library functions localeconv, getenv, setlocale or, strerror shall only be used as if they have pointer to const-qualified type. | 必須 | 準拠 |
| 21.20 | The pointer returned by the Standard Library functions asctime, ctime, gmtime, localtime, localeconv, getenv, setlocale or strerror shall not be used following a subsequent call to the same function. | 必須 | 準拠 |
| 21.21 | The Standard Library function system of <stdlib.h> shall not be used. | 必要 | 準拠 |
| 21.22 | All operand arguments to any type-generic macros declared in <tgmath.h> shall have an appropriate essential type. | 必須 | 準拠 |
| 21.23 | All operand arguments to any multi-argument type-generic macros declared in <tgmath.h> shall have the same standard type. | 必要 | 準拠 |
| 21.24 | The random number generator functions of <stdlib.h> shall not be used. | 必要 | 非準拠 |
a Rule 21.13, 21.14, 21.15, 21.16, 21.17, 21.18, 21.19, 21.20 is from MISRA Amendment 1. b Rule 21.21 is from MISRA Amendment 2. c Rule 21.12, 21.22, 21.23 and 21.24 are from MISRA Amendment 3. d Copyright © The MISRA Consortium Limited, 2022. | |||
リソース
| ルールa | 説明b | カテゴリ | 準拠 |
|---|---|---|---|
| 22.1 | All resources obtained dynamically by means of Standard Library functions shall be explicitly released. | 必要 | 準拠 |
| 22.2 | A block of memory shall only be freed if it was allocated by means of a Standard Library function. | 必須 | 準拠 |
| 22.3 | The same file shall not be open for read and write access at the same time on different streams. | 必要 | 準拠 |
| 22.4 | There shall be no attempt to write to a stream which has been opened as read-only. | 必須 | 準拠 |
| 22.5 | A pointer to a FILE object shall not be dereferenced. | 必須 | 準拠 |
| 22.6 | The value of a pointer to a FILE shall not be used after the associated stream has been closed. | 必須 | 準拠 |
| 22.7 | The macro EOF shall only be compared with the unmodified return value from any Standard Library function capable of returning EOF. | 必要 | 準拠 |
| 22.8 | The value of errno shall be set to zero prior to a call to an errno-setting-function. | 必要 | 準拠 |
| 22.9 | The value of errno shall be tested against zero after calling an errno-setting-function. | 必要 | 準拠 |
| 22.10 | The value of errno shall only be tested when the last function to be called was an errno-setting-function. | 必要 | 準拠 |
a Rule 22.7, 22.8, 22.9, and 22.10 is from MISRA Amendment 1. b Copyright © The MISRA Consortium Limited, 2022. | |||
総称選択
| ルールa | 説明b | カテゴリ | 準拠 |
|---|---|---|---|
| 23.2 | A generic selection that is not expanded from a macro shall not contain potential side effects in the controlling expression. | 必要 | 準拠 |
| 23.4 | A generic association shall list an appropriate type. | 必要 | 準拠 |
| 23.6 | The controlling expression of a generic selection shall have an essential type that matches its standard type. | 必要 | 準拠 |
| 23.8 | A default association shall appear as either the first or the last association of a generic selection. | 必要 | 準拠 |
a Rule 23.2, 23.4, 23.6, and 23.8 are from MISRA Amendment 3. b Copyright © The MISRA Consortium Limited, 2022. | |||
説明メモ
命令 1.1 に関する説明メモ
Embedded Coder の処理系定義の動作については、ランタイム環境オプションの構成を参照してください。コンパイラのドキュメンテーションはスコープ外です。
SavedCharacterEncoding モデル パラメーターを使用して、文字セット エンコードを管理します。詳細については、slCharacterEncoding を参照してください。
[モデル コンフィギュレーション パラメーター] ダイアログ ボックスの [ハードウェア実行] ペインで、整数除算方法を構成します。詳細については、ランタイム環境オプションの構成を参照してください。
以下を行うと、Embedded Coder によってプラグマが生成されます。
メモリ セクションの使用を選択する。メモリ セクションの使用を選択するを参照してください。
どちらの場合も、プラグマの用途をドキュメント化する必要があります。詳細については、Control Data and Function Placement in Memory by Inserting Pragmasを参照してください。
ビットフィールドの生成を有効にするには、次のようにします。
次のモデル コンフィギュレーション パラメーターのうち少なくとも 1 つを選択します。
定義済みのビットフィールドを含むカスタム ストレージ クラスを作成します。詳細については、カスタム ストレージ クラス デザイナーを使用したストレージ クラスの作成を参照してください。
モデルで、あるデータ型から別のデータ型への変換が使用されている場合、Polyspace Bug Finder は命令 1.1 の違反を報告する場合があります。
浮動小数点入力を指定して eig 関数を使用すると、非準拠のコードが生成されます。
命令 3.1 に関する説明メモ
要件とモデル要素をリンクできます。このようなリンクを生成された C コードに含めて、要件ドキュメントからモデル要素および生成コードへのトレーサビリティを提供します。詳細については、モデル要素に関連付けられている Requirements Toolbox リンクの表示およびSimulink での要件の表示とリンク (Requirements Toolbox)を参照してください。
命令 4.1 に関する説明メモ
Polyspace Bug Finder を使用してランタイム エラーを特定でき、Polyspace Code Prover™ を使用してランタイム エラーがないことを証明できます。詳細については、以下を参照してください。
Simulink Design Verifier を使用して、設計エラーをモデル レベルで検出できます。詳細については、モデルにおける設計エラーの解析 (Simulink Design Verifier)を参照してください。
オーバーフロー違反を処理するには、Simulink モデルでのオーバーフローの処理 (Fixed-Point Designer)を参照してください。
命令 4.3 に関する説明メモ
Embedded Coder はアセンブリ言語コードを直接呼び出しません。S-Function、コード置換ライブラリ、Stateflow、および MATLAB® ブロックでアセンブリ言語関数の呼び出しを追加できます。これらの呼び出しはExternal C Functionsの呼び出しとしてドキュメント化します。このような場合、カプセル化を行う必要があります。
詳細については、以下を参照してください。
命令 4.6 に関する説明メモ
Embedded Coder には、命令 4.6 と互換性のある 3 つのオプションが用意されています。以下が可能です。
生成された
rtwtypes.hファイルで定義された指定幅の整数データ型 (uint8_Tなど) を使用する typedef を使用する。stdint.hからの指定幅の整数データ型 (uint8_tなど) を使用する。固定幅の整数データ型のカスタム名を指定する。
1 番目と 2 番目のオプションを使用すると、生成されたコードに指定幅でない整数が含まれる可能性があります。たとえば、生成された main ファイルまたは Stateflow カウンター変数内の int_T や int などです。整数を指定幅の整数に置き換えるには、データ型置換を使用します。
AUTOSAR コードを生成するようにモデルを構成すると、Embedded Coder は、指定幅の整数データ型のみを使用するコードを生成します。
詳細については、以下を参照してください。
命令 4.11 に関する説明メモ
この命令の要件を満たすために、"入力パラメーターが無効な値を受け取れないことを静的に実証する" ことができます。
Polyspace Code Prover を使用してパラメーター範囲を解析し、値が範囲外であるために発生するランタイム エラーがないことを証明できます。詳細については、Embedded Coder によって生成されたコードに対する Polyspace 解析の実行 (Polyspace Code Prover)を参照してください。
ルール 2.1 に関する説明メモ
Polyspace Bug Finder は、Stateflow からのユーザー定義関数の違反を報告する場合があります。
サブシステムの [関数のパッケージ化] パラメーターを [再利用可能な関数] または [再利用できない関数] にすると、サブシステムは関数が空になる場合でも関数を生成します。これは、MISRA C:2012 Rule 2.1 の違反に当たります。
ルール 5.1、5.2、5.4、5.5、5.6、5.7 および 5.8 に関する説明メモ
Embedded Coder は、実装によって設定される文字数を制限するよう構成できます。詳細については、[識別子の最大の長さ] を参照してください。
変数のタイプ (ローカル スコープ変数、グローバル スコープ変数、マクロなど) ごとに一意の名前を確保するには、命名規則を実装します。詳細については、[モデル コンフィギュレーション パラメーター: コード生成識別子] を参照してください。
長い識別子の場合は、共有ユーティリティを使用することをお勧めします。詳細については、共有ユーティリティ コードの生成を参照してください。
ルール 8.2 に関する説明メモ
モデル参照内の Send または Receive ブロックを使用して生成されたコードには、引数名のない関数宣言が含まれる場合があります。以下に例を示します。
typedef struct {
void *host;
void (*RecvData)(void *, real_T *, int32_T, int32_T *);
} RecvData_real_T;ルール 8.12 に関する説明メモ
Embedded Coder は列挙データの使用をサポートしています。列挙の定義に使用するファイルは手動でも自動でも生成できます。Embedded Coder によって生成された列挙を定義するファイルは、設計上 MISRA C:2012 ルール 8.12 に準拠しています。定義ファイルを手動で作成する場合、準拠を確保する必要があります。詳細については、Simulink モデルでの列挙型データの使用を参照してください。
ルール 9.1 に関する説明メモ
Simulink Support Package for Raspberry Pi® Hardware、C2000™ Microcontroller Blockset (または同様の構成) などのサポート パッケージ用に構成された Simulink モデルでは、非準拠のコードが生成されることがあります。
メモ
Embedded Coder を使用して生成されたコードで使用されるドライバーなどのサードパーティ ファイルは、評価では考慮されません。
ルール 10.1、10.3、および 10.4 に関する説明メモ
Functional Mockup Unit (FMU) version 1.0 を使用すると、非準拠コードになる可能性があります。
ルール 11.8 に関する説明メモ
モデルで使用しているストレージ クラスに修飾子 Const または Volatile が設定されている場合、Polyspace はモデルの生成コードがルール 11.8 に違反していることを示す場合があります。
ルール 12.2 に関する説明メモ
シミュレーション診断で Simulink モデルからのオーバーフローが報告された場合、コード ジェネレーターは MISRA に準拠したコードを生成しないことがあります。
ルール 13.2 に関する説明メモ
volatile 変数を使用すると、非準拠コードになる場合があります。
ルール 17.3 および 21.2 に関する説明メモ
モデル コンフィギュレーション パラメーター [ターゲット ハードウェアの命令セット拡張を活用] が [なし] 以外に設定されている場合、生成されるコードが MISRA C:2012 ルールに違反する場合があります。
ヘッダー ファイルの欠落エラーが発生した場合は、欠落しているヘッダーを rtw/c/src ディレクトリからプロジェクト フォルダーに手動でコピーし、生成されたコードを MATLAB なしでビルドできるようにすることで、エラーを解決できます。
ルール 21.1 に関する説明メモ
Polyspace Bug Finder がルール 21.1 の違反を報告した場合、set_param(model, 'DataTypeReplacement', 'CDataTypesFixedWidth') を実行します。
ルール 21.2 に関する説明メモ
識別子の長さが [識別子の最大の長さ] で設定された制限を超えている場合、Embedded Coder は一部のトークンを展開せず、先頭にアンダースコア (_) が付く場合があります。結果の識別子は予約された識別子として扱われ、MISRA C:2012 ルールに違反する場合があります。
バージョン履歴
MISRA C:2012 Amendment 2 (AMD2) および Amendment 3 (AMD3) を概要表に追加
R2024b 以降
概要表に、MISRA C:2012 Amendment 2 (AMD2) および Amendment 3 (AMD3) ガイドラインの準拠ステータスが含まれるようになりました。
MISRA C:2012 概要表に、すべての必須カテゴリと必要カテゴリを追加
R2023b 以降
概要表に、MISRA C:2012 のすべての必須カテゴリおよび必要カテゴリのガイドラインの準拠ステータスが含まれるようになりました。