gcc(gnu), clang(llvm)コンパイルエラー・警告比較(8) R_11_0x.c。docker(162)
やってきました。
gcc(gnu) clang(llvm)コンパイルエラー比較
長らくごぶさたしていました。
MISRA の解説書は有料ですが、Codeは無償であげてくれています。
MISRA C:2012 Example-Suite
https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite
全体の記録は
Misra Example Suite at docker コンパイル完了までの道のり
https://qiita.com/kaizen_nagoya/items/71f04a0204d5a1114577
順にコンパイルエラーが出たものを比較し、
エラーを取るのなら取ってみます。
-Wall でコンパイルしています。
R_11_0x.c
$ clang
R_11_01.c:49:24: error: operand of type 'float' cannot be cast to a pointer type
fp16 fp4 = ( fp16 ) 1.0e6F; /* Non-compliant - float to function pointer */
^~~~~~
1 error generated.
R_11_04.c:27:20: warning: cast to 'uint8_t *' (aka 'unsigned char *') from smaller integer type 'int32_t' (aka 'int') [-Wint-to-pointer-cast]
uint8_t *q = ( uint8_t * ) addr; /* Non-compliant */
^
1 warning generated.
R_11_06.c:28:19: error: operand of type 'float' cannot be cast to a pointer type
p = ( void * ) 1024.0f; /* Non-compliant - undefined */
^~~~~~~
1 error generated.
R_11_07.c:28:24: error: pointer cannot be cast to type 'float32_t' (aka 'float')
f = ( float32_t ) p; /* Non-compliant */
^
R_11_07.c:29:24: error: operand of type 'float32_t' (aka 'float') cannot be cast to a pointer type
p = ( int16_t * ) f; /* Non-compliant */
^
2 errors generated.
R_11_09.c:34:13: warning: unused variable 'p3' [-Wunused-variable]
int32_t *p3 = MY_NULL_3; /* Compliant */
^
1 warning generated.
$ gcc
R_11_01.c: In function 'R_11_1':
R_11_01.c:49:4: error: cannot convert to a pointer type
49 | fp16 fp4 = ( fp16 ) 1.0e6F; /* Non-compliant - float to function pointer */
| ^~~~
R_11_01.c:58:9: warning: unused variable 'fp5' [-Wunused-variable]
58 | fp16 fp5 = f1; /* Compliant - exception */
| ^~~
R_11_01.c:49:9: warning: unused variable 'fp4' [-Wunused-variable]
49 | fp16 fp4 = ( fp16 ) 1.0e6F; /* Non-compliant - float to function pointer */
| ^~~
R_11_01.c:47:9: warning: unused variable 'fp3' [-Wunused-variable]
47 | fp16 fp3 = ( fp16 ) 0x8000; /* Non-compliant - integer to function pointer */
| ^~~
R_11_04.c: In function 'R_11_4':
R_11_04.c:26:20: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
26 | int32_t addr = ( int32_t ) &p; /* Non-compliant */
| ^
R_11_04.c:27:20: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
27 | uint8_t *q = ( uint8_t * ) addr; /* Non-compliant */
| ^
R_11_06.c: In function 'R_11_6':
R_11_06.c:28:4: error: cannot convert to a pointer type
28 | p = ( void * ) 1024.0f; /* Non-compliant - undefined */
| ^
R_11_06.c:30:8: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
30 | u = ( uint32_t ) p; /* Non-compliant - implementation-defined */
| ^
R_11_07.c: In function 'R_11_7':
R_11_07.c:28:6: error: pointer value used where a floating-point was expected
28 | f = ( float32_t ) p; /* Non-compliant */
| ^
R_11_07.c:29:6: error: cannot convert to a pointer type
29 | p = ( int16_t * ) f; /* Non-compliant */
| ^
R_11_09.c: In function 'R_11_9':
R_11_09.c:34:13: warning: unused variable 'p3' [-Wunused-variable]
34 | int32_t *p3 = MY_NULL_3; /* Compliant */
| ^~
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
Author And Source
この問題について(gcc(gnu), clang(llvm)コンパイルエラー・警告比較(8) R_11_0x.c。docker(162)), 我々は、より多くの情報をここで見つけました https://qiita.com/kaizen_nagoya/items/9962647a1b510825fa6e著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .