Keil Logo

_Bool and pc_lint

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Author
erik malund
Posted
21-Feb-2018 21:16 GMT
Toolset
ARM
New! _Bool and pc_lint

trying to use pc-lint with MISRA 2012 I have tried to change in stdbool

    #define bool _Bool
//typedef _Bool bool;


makes no difference

any suggestions?

I get the below type of 'report' all over the place.

bool bIsFahrenheit = false;
^
..\Src\statemachine.c(34,0): Note 970: Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory]

                   ^
..\Src\statemachine.c(34,0): Note 9075: external symbol 'bIsFahrenheit' defined without a prior declaration [MISRA 2012 Rule 8.4, required]

#... ve -e921 */(_Bool) 0/*lint -restore */
                     ^
..\Src\statemachine.c(34,0): Note 970: Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory]


Author
Robert Rostohar
Posted
22-Feb-2018 05:41 GMT
Toolset
ARM
New! RE: _Bool and pc_lint

One way is to define a typdef for bool and use that instead. MISRA should be happy with it.

#include <stdbool.h>
typedef bool bool_t;
#define FALSE                   ((bool_t)0)
#define TRUE                    ((bool_t)1)

bool_t bIsFahrenheit = FALSE;
Author
erik malund
Posted
22-Feb-2018 14:14 GMT
Toolset
ARM
New! RE: _Bool and pc_lint
    #define bool _Bool
//typedef _Bool bool;
typedef bool bool_t;


was that what you ment?
if so, it makes it worse

..\Src\statemachine.c(69,0): Note 970: Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory]

bool_t align_mode = false;
                  ^
..\Src\statemachine.c(70,0): Note 9075: external symbol 'align_mode' defined without a prior declaration [MISRA 2012 Rule 8.4, required]

#... e -e921 */(_Bool) 0/*lint -restore */
                    ^
..\Src\statemachine.c(70,0): Note 970: Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory]

        if (align_mode == false)
#... t -save -e921 */(_Bool) 0/*lint -restore */
                          ^
..\Src\statemachine.c(84,0): Note 970: Use of modifier or type '_Bool' outside of a typedef [MISRA 2012 Directive 4.6, advisory]

        if (align_mode == false)
                          ^
..\Src\statemachine.c(84,0): Info 731: Boolean argument to equal/not equal


Author
Kevin from Support
Posted
23-Feb-2018 16:56 GMT
Toolset
ARM
New! RE: _Bool and pc_lint

Hello Erik,

Have you used this tool to play around with your code:

http://gimpel-online.com//cgi-bin/genPage.py?srcFile=misra3.c&cgiScript=analyseCode.py&title=MISRA+C+2012+Example+%28C%29&intro=This+example+shows+how+FlexeLint%2FPC-lint+addresses+certain+MISRA+C+2012+guidelines.&compilerOption=online32.lnt+au-misra3.lnt+lib-unmisra.lnt&includeOption={{quotedIncludeOption}}

When you put your code in there, it links the error message pages:
http://gimpel-online.com/MsgRef.html#970 In that entry it says:
"You may enable this message and then suppress the message for individual types to obtain special effects. For example the following will enable the message for all but bool." +e970 -esym(970,bool)

=====

As for the "MISRA 2012 Directive 4.6, advisory" line in the error message, there is a good discussion here:

https://stackoverflow.com/questions/30607456/does-misra-c-2012-say-not-to-use-bool

In that page they say: "Directive 4.6 says "typedefs that indicate size and signedness should be used in place of the basic numerical types"."

Also in that page, one of the posters disagrees with Gimpel's interpretation of Directive 4.6. You might want to check with Gimpel on their forum about this.

Author
Kevin from Support
Posted
23-Feb-2018 17:34 GMT
Toolset
ARM
New! RE: _Bool and pc_lint

Vaguely relevant links to promote cross-linky-ness

Modifications that may be needed to the default lint config file. You might have to make your own tweaks as well:

http://www.keil.com/pack/doc/CMSIS/RTOS2/html/misraCompliance5.html

http://www.keil.com/pack/doc/CMSIS/Core/html/coreMISRA_Exceptions_pg.html

You can set the ARM Compiler 6 to emit "MISRA compatible" warnings. See:

http://www.keil.com/support/man/docs/uv4/uv4_dg_armclang_cmp.htm

Discussions at

http://www.keil.com/forum/24035/

http://www.keil.com/forum/63388/

Author
Hans-Bernhard Broeker
Posted
24-Feb-2018 21:23 GMT
Toolset
ARM
New! RE: _Bool and pc_lint

The change you applied really has to make a difference. If it didn't, the most likely reason is that the line you edited was not actually the one where bool was defined, in that run of the compiler. You'll have to watch out for other copies of <stdbool.h> lying around in the configured #include path seen by PC-lint, or other headers that believe they should be doing their own definitions. Note that PC-lint has some fall-back definitions of standard library elements of its own. This message fragment in particular

#... ve -e921 */(_Bool) 0/*lint -restore */

suggests to me that you're currently finding PC-lint's definition of "false" (from au-misra3.lnt).

Author
erik malund
Posted
26-Feb-2018 19:18 GMT
Toolset
ARM
New! RE: _Bool and pc_lint

You'll have to watch out for other copies of <stdbool.h> lying around in the configured #include path seen by PC-lint,

there are no stdbool in the project directory
these are the ones in the keil directory

C:\keil_v5\ARM\ARMCC\include
C:\keil_v5\ARM\ARMCLANG\include
C:\keil_v5\ARM\ARMCLANG\include\libcxx
C:\keil_v5\ARM\ARMCLANG\lib\clang\5.0.0\include

this is the includes in the project options
../Inc;../Drivers/STM32F0xx_HAL_Driver/Inc;../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F0xx/Include;../Drivers/CMSIS/Include;../Touch-user;../Middleware-touch/inc;../Lcd;..\Images

it seems the Keil directory links are automsatic
2) if yes, how do I modify w/o getting compile errors

computer control string from project options:
--c99 -c --cpu Cortex-M0 -D__MICROLIB -g -O0 --apcs=interwork --split_sections -I ../Inc -I ../Drivers/STM32F0xx_HAL_Driver/Inc -I ../Drivers/STM32F0xx_HAL_Driver/Inc/Legacy -I ../Drivers/CMSIS/Device/ST/STM32F0xx/Include -I ../Drivers/CMSIS/Include -I ../Touch-user -I ../Middleware-touch/inc -I ../Lcd -I ../Images
-I./RTE/_GP_TMO
-IC:/Keil_v5/ARM/PACK/ARM/CMSIS/5.0.1/CMSIS/Include
-IC:/Keil_v5/ARM/PACK/Keil/STM32F0xx_DFP/1.5.0/Device/Include
-D__UVISION_VERSION="524" -D_RTE_ -DSTM32F091xC -DUSE_HAL_DRIVER -DSTM32F091xC -DTMO
-o .\Obj\*.o --omf_browse .\Obj\*.crf --depend .\Obj\*.d

erik

Author
Hans-Bernhard Broeker
Posted
26-Feb-2018 21:10 GMT
Toolset
ARM
New! RE: _Bool and pc_lint

it seems the Keil directory links are automsatic

For the Keil compiler itself: evidently. For PC-Lint: not so much. Unless the IDE adds its own -i"$(KEILDIR)/ARM..." flags to the PC-lint call automatically, you'll have to do that yourself, in the configuration of the lint integration.

Author
erik malund
Posted
27-Feb-2018 18:52 GMT
Toolset
ARM
New! RE: _Bool and pc_lint

typedef unsigned int uint32_t; (stdint) no lint problem
typedef _Bool bool; (stdbool modified) lint problem.

the lint issue must be in a difference of what is assigned by the compiler

Author
Kevin from Support
Posted
5-Mar-2018 20:49 GMT
Toolset
ARM
New! RE: _Bool and pc_lint

Hello Erik,

I looked in the "MISRA C:2012 Technical Corrigendum 1 Technical clarification of MISRA C:2012 June 2017" guide at:

https://www.misra.org.uk/LinkClick.aspx?fileticket=-BRmxs8omoM%3D&tabid=57

On Page 7, regarding Directive 4.6, they are using examples of not using plain char instead of signed or unsigned char.

So if you want to it may be OK to use +e970 -esym(970,bool) in your code to have Lint ignore booleans.

... but I am not a language lawyer, so I say ask on: Ask on https://www.misra.org.uk/forum to be safe

Or on Gimpbel's forum. Not quite the same issue you had, but here was a customer using the C++ MISRA standard, and running into issues with C types and MISRA warnings:

http://www.gimpel.com/Discussion.cfm?ThreadID=3394

Author
Kevin from Support
Posted
5-Mar-2018 20:51 GMT
Toolset
ARM
New! RE: _Bool and pc_lint

oops instead of "in your code" I should have said use

  +e970 -esym(970,bool)

in your copy of the MISRA-2012 lint configuration file MISRA_C_2012_Config.lnt

Author
Kevin from Support
Posted
5-Mar-2018 20:17 GMT
Toolset
ARM
New! RE: _Bool and pc_lint

Hello Erik,

Hello, are you using MDK-ARM version 5.24?
Are you using ARM Compiler 6 to compiler? Or ARM Compiler 5?

If so, did you run your code using our C:\Keil_v5\UV4\Lint\Config\MISRA_C_2012_Config.lnt file?
-This file has some additional MISRA 2012 settings.

You can follow these steps to setup PC-Lint for MISRA C 2012 support:

http://www.keil.com/support/man/docs/uv4/uv4_ut_pclint_config.htm

If you are running MDK-ARM 5.23, the Misra_C files were in the wrong place. See:

http://www.keil.com/support/docs/3905.htm

Author
erik malund
Posted
6-Mar-2018 00:30 GMT
Toolset
ARM
New! RE: _Bool and pc_lint

I'm off this week, will be back next

Author
erik malund
Posted
13-Mar-2018 14:04 GMT
Toolset
ARM
New! RE: _Bool and pc_lint

Hello, are you using MDK-ARM version 5.24?
5.24.1
Are you using ARM Compiler 6 to compiler? Or ARM Compiler 5?
??? Armcc 5.06 build 528

If so, did you run your code using our C:\Keil_v5\UV4\Lint\Config\MISRA_C_2012_Config.lnt file?
-This file has some additional MISRA 2012 settings.

will have a look

You can follow these steps to setup PC-Lint for MISRA C 2012 support:
I do not want to suppress a lint warning that may, in some cases, be valid

Erik

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.