gcc(gnu), clang(llvm)コンパイルエラー・警告比較(12) R_17_03.c。docker(165)


やってきました。

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_17_3x.c

$ clang 
R_17_01.c:38:19: warning: passing an object that undergoes default argument promotion to 'va_start' has undefined
      behavior [-Wvarargs]
   va_start ( ap, n );             /* Non-compliant */
                  ^
R_17_01.c:32:26: note: parameter of type 'uint16_t' (aka 'unsigned short') is declared here
static void f ( uint16_t n, ... )
                         ^
1 warning generated.
R_17_03.c:28:20: warning: implicit declaration of function 'power' is invalid in C99 [-Wimplicit-function-declaration]
   float64_t sq1 = power ( 1, 2.0 );    /* Non-compliant  */
                   ^
1 warning generated.
R_17_04.c:34:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
R_17_04.c:42:6: error: non-void function 'lookup' should return a value [-Wreturn-type]
     return;
     ^
1 warning and 1 error generated.
R_17_06.c:43:8: warning: array argument is too small; contains 10 elements, callee requires at least 20 [-Warray-bounds]
   x = total ( 10U, v1 ); /* Undefined: v1 has 10 elements but needs at least 20 */
       ^            ~~
R_17_06.c:22:40: note: callee declares array parameter as static here
                        const uint16_t a [ static 20 ] /* Non-compliant */ )
                                       ^ ~~~~~~~~~~~~~
1 warning generated.

$ gcc 
R_17_03.c: In function 'R_17_3':
R_17_03.c:28:20: warning: implicit declaration of function 'power' [-Wimplicit-function-declaration]
   28 |    float64_t sq1 = power ( 1, 2.0 );    /* Non-compliant  */
      |                    ^~~~~
R_17_04.c: In function 'lookup':
R_17_04.c:42:6: warning: 'return' with no value, in function returning non-void [-Wreturn-type]
   42 |      return;
      |      ^~~~~~
R_17_04.c:37:17: note: declared here
   37 | static uint16_t lookup ( const uint16_t table[ 5 ], uint16_t v )
      |                 ^~~~~~
R_17_04.c: In function 'absolute':
R_17_04.c:34:1: warning: control reaches end of non-void function [-Wreturn-type]
   34 | }
      | ^
In file included from clear_lib.c:10:
clear_lib.c: In function 'g':
clear_lib.c:269:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  269 |  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:282:6: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  282 |  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)
      |                                                      ^
/usr/bin/ld: /tmp/cc8kFGRM.o: in function `R_17_3':
R_17_03.c:(.text+0x1f): undefined reference to `power'
collect2: error: ld returned 1 exit status

root@fe9e7da2ab2f:/tmp/misra/Example-Suite# 

gccとclangでコンパイルエラーと警告に別れた。