やってきました。
gcc(gnu) clang(llvm)コンパイルエラー比較
長らくごぶさたしていました。
MISRA の解説書は有料ですが、Codeは無償であげてくれています。
MISRA C:2012 Example-Suite
https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite
<この項は書きかけです。順次追記します。>
This article is not completed. I will add some words in order.
全体の記録
Misra Example Suite at docker コンパイル完了までの道のり
https://qiita.com/kaizen_nagoya/items/71f04a0204d5a1114577
順にコンパイルエラーが出たものを比較し、
エラーを取るのなら取ってみます。
-Wall でコンパイルしています。
R_10_0x.c
まず、そのまんまだとコンパイルエラーが出た状況。
$ clang
R_10_01.c:52:16: error: invalid operands to binary expression ('float32_t' (aka 'float') and 'unsigned int')
f32b = f32a & 2U; /* Constraint Error, also breaks R.10.4 */
~~~~ ^ ~~
R_10_01.c:54:16: error: invalid operands to binary expression ('float32_t' (aka 'float') and 'int')
f32b = f32a << 2; /* Constraint Error */
~~~~ ^ ~
R_10_01.c:93:14: warning: shift count is negative [-Wshift-count-negative]
u8b = u8a << -1; /* Non-compliant; also breaks R.12.2 */
^ ~~
1 warning and 2 errors generated.
R_10_03.c:100:10: warning: implicit conversion from 'int' to 'int8_t' (aka 'signed char') changes value from 128 to -128 [-Wconstant-conversion]
s8a = K2; /* Non-compliant - Constant value does not fit */
~ ^~
R_10_03.c:119:28: warning: implicit conversion from 'int' to 'uint16_t' (aka 'unsigned short') changes value from 100000 to 34464 [-Wconstant-conversion]
u16a = (uint16_t)50000U + (uint16_t)50000U; /* Non-compliant */
~ ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
2 warnings generated.
R_10_04.c:61:13: warning: comparison of two values with different enumeration types ('enum enuma' and 'enum enumb') [-Wenum-compare]
if ( ena == enb ) /* Non-compliant - Enum<enumb> to enum<enuma> */
~~~ ^ ~~~
1 warning generated.
$ gcc
R_10_01.c: In function 'R_10_1':
R_10_01.c:52:16: error: invalid operands to binary & (have 'float32_t' {aka 'float'} and 'unsigned int')
52 | f32b = f32a & 2U; /* Constraint Error, also breaks R.10.4 */
| ^
R_10_01.c:54:16: error: invalid operands to binary << (have 'float32_t' {aka 'float'} and 'int')
54 | f32b = f32a << 2; /* Constraint Error */
| ^~
R_10_01.c:72:14: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
72 | blc = bla * blb; /* Non-compliant, returns standard type */
| ~~~~^~~~~
R_10_01.c:93:14: warning: left shift count is negative [-Wshift-count-negative]
93 | u8b = u8a << -1; /* Non-compliant; also breaks R.12.2 */
| ^~
R_10_03.c: In function 'R_10_3':
R_10_03.c:119:11: warning: unsigned conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} changes value from '100000' to '34464' [-Woverflow]
119 | u16a = (uint16_t)50000U + (uint16_t)50000U; /* Non-compliant */
| ^
R_10_04.c: In function 'R_10_4':
R_10_04.c:57:13: warning: comparison between 'enum enumb' and 'enum enuma' [-Wenum-compare]
57 | if ( enb > A1 ) /* Non-compliant - Enum<enuma> to enum<enumb> */
| ^
R_10_04.c:61:13: warning: comparison between 'enum enuma' and 'enum enumb' [-Wenum-compare]
61 | if ( ena == enb ) /* Non-compliant - Enum<enumb> to enum<enuma> */
| ^~
In file included from clear_lib.c:10:
clear_lib.c: In function 'g':
clear_lib.c:261:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
261 | PR1((int)p,d);
| ^
misra_c.h:66:54: note: in definition of macro 'PR1'
66 | #define PR1(a,b) (void)printf(" "#a " = %" #b "\n", a)
| ^
clear_lib.c: In function 'use_const_volatile_char_ptr':
clear_lib.c:274:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
274 | PR1((int)cv_cp,d);
| ^
misra_c.h:66:54: note: in definition of macro 'PR1'
66 | #define PR1(a,b) (void)printf(" "#a " = %" #b "\n", a)
| ^
./R_10.sh: 19: ./R_10.sh: R_10_01.c: not found
#ifdef DEBUG
で除外しちゃったら。
$ clang
R_10_01.c:95:14: warning: shift count is negative [-Wshift-count-negative]
u8b = u8a << -1; /* Non-compliant; also breaks R.12.2 */
^ ~~
R_10_01.c:140:18: warning: variable 'f32b' is uninitialized when used here [-Wuninitialized]
f32b = f32a + f32b;
^~~~
R_10_01.c:36:18: note: initialize the variable 'f32b' to silence this warning
float32_t f32b;
^
= 0.0
2 warnings generated.
R_10_03.c:100:10: warning: implicit conversion from 'int' to 'int8_t' (aka 'signed char') changes value from 128 to -128 [-Wconstant-conversion]
s8a = K2; /* Non-compliant - Constant value does not fit */
~ ^~
R_10_03.c:119:28: warning: implicit conversion from 'int' to 'uint16_t' (aka 'unsigned short') changes value from 100000 to 34464 [-Wconstant-conversion]
u16a = (uint16_t)50000U + (uint16_t)50000U; /* Non-compliant */
~ ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
2 warnings generated.
R_10_04.c:61:13: warning: comparison of two values with different enumeration types ('enum enuma' and 'enum enumb') [-Wenum-compare]
if ( ena == enb ) /* Non-compliant - Enum<enumb> to enum<enuma> */
~~~ ^ ~~~
1 warning generated.
$ gcc
R_10_01.c: In function 'R_10_1':
R_10_01.c:74:14: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
74 | blc = bla * blb; /* Non-compliant, returns standard type */
| ~~~~^~~~~
R_10_01.c:95:14: warning: left shift count is negative [-Wshift-count-negative]
95 | u8b = u8a << -1; /* Non-compliant; also breaks R.12.2 */
| ^~
R_10_01.c:140:9: warning: 'f32b' is used uninitialized in this function [-Wuninitialized]
140 | f32b = f32a + f32b;
| ~~~~~^~~~~~~~~~~~~
R_10_03.c: In function 'R_10_3':
R_10_03.c:119:11: warning: unsigned conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} changes value from '100000' to '34464' [-Woverflow]
119 | u16a = (uint16_t)50000U + (uint16_t)50000U; /* Non-compliant */
| ^
R_10_04.c: In function 'R_10_4':
R_10_04.c:57:13: warning: comparison between 'enum enumb' and 'enum enuma' [-Wenum-compare]
57 | if ( enb > A1 ) /* Non-compliant - Enum<enuma> to enum<enumb> */
| ^
R_10_04.c:61:13: warning: comparison between 'enum enuma' and 'enum enumb' [-Wenum-compare]
61 | if ( ena == enb ) /* Non-compliant - Enum<enumb> to enum<enuma> */
| ^~
In file included from clear_lib.c:10:
clear_lib.c: In function 'g':
clear_lib.c:263:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
263 | PR1((int)p,d);
| ^
misra_c.h:66:54: note: in definition of macro 'PR1'
66 | #define PR1(a,b) (void)printf(" "#a " = %" #b "\n", a)
| ^
clear_lib.c: In function 'use_const_volatile_char_ptr':
clear_lib.c:276:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
276 | PR1((int)cv_cp,d);
| ^
misra_c.h:66:54: note: in definition of macro 'PR1'
66 | #define PR1(a,b) (void)printf(" "#a " = %" #b "\n", a)
|
docker hubでの作業
docker hubからの起動はこちら。
$ docker run it kaizenjapan/misra_c_2012_example /bin/bash
#参考資料
仮説・検証(173)C言語(C++)に対する誤解、曲解、無理解、爽快。
[C][C++]の国際規格案の例題をコンパイルするときの課題7つ。
https://qiita.com/kaizen_nagoya/items/5f4b155030259497c4de
C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識
https://qiita.com/kaizen_nagoya/items/d89a48c1536a02ecdec9
MISRA C まとめ #include
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9
どうやって MISRA Example Suiteをコンパイルするか
https://qiita.com/kaizen_nagoya/items/fbdbff5ff696e2ca7f00
ISO/IEC TS 17961:2013 C Secure Coding Rules(1) All list(to be confirmed)
https://qiita.com/kaizen_nagoya/items/54e056195c4f11b850a1
Autosar Guidelines C++14 example code compile list
https://qiita.com/kaizen_nagoya/items/8ccbf6675c3494d57a76
C++ N4741, N4606, N3242 Source Compile Error List
https://qiita.com/kaizen_nagoya/items/2e736e04339b340ffb4d
自己参照
Error一覧 error(0)
https://qiita.com/kaizen_nagoya/items/48b6cbc8d68eae2c42b8
プログラマが知っていると良い「公序良俗」
https://qiita.com/kaizen_nagoya/items/9fe7c0dfac2fbd77a945
Ethernet 記事一覧 Ethernet(0)
https://qiita.com/kaizen_nagoya/items/88d35e99f74aefc98794
Wireshark 一覧 wireshark(0)、Ethernet(48)
https://qiita.com/kaizen_nagoya/items/fbed841f61875c4731d0
線網(Wi-Fi)空中線(antenna)(0) 記事一覧(118/300目標)
https://qiita.com/kaizen_nagoya/items/5e5464ac2b24bd4cd001
通信記事100
https://qiita.com/kaizen_nagoya/items/1d67de5e1cd207b05ef7
一覧の一覧( The directory of directories of mine.) Qiita(100)
https://qiita.com/kaizen_nagoya/items/7eb0e006543886138f39
<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>
This article is an individual impression based on the individual's experience. It has nothing to do with the organization or business to which I currently belong.
文書履歴(document history)
ver. 0.01 add URL 20240514
最後までおよみいただきありがとう4ざいました。
いいね 💚、フォローをお願いします。
Thank you very much for reading to the last sentence.
Please press the like icon 💚 and follow me for your happy life.