> On Jun 1, 2016, at 1:12 PM, Marvin H?user <[email protected]> wrote:
> 
> Recently I was told that ASSERT() calls to check whether a variable is NULL 
> breaks the Clang Static Analyzer in terms of generating wrong warnings. The 
> reason is that, when a variable/parameter is checked for NULL, this analyzer 
> assumes that it can be. As it doesn't support EDK2 ASSERTs, but only 
> compiler-provided asserts, to it, the ASSERT() call is a simple if-check (-> 
> triggers NULL warnings) which does return to normal code flow (-> any further 
> usages may be dereferencing NULL). This behavior is documented here: 
> http://clang-analyzer.llvm.org/faq.html#null_pointer
> 
> To make clear that EDK2 ASSERT() calls are indeed asserts, in my opinion, 
> CpuDeadLoop() should be flagged as 'noreturn' (it indeed should never return) 
> and Breakpoint() as 'analyzer_noreturn' (it may return, but the analyzer 
> doesn't have to care as the debugger is invoked). If I didn't understand the 
> documentation incorrectly, this should fix the issue described in the first 
> paragraph.
> 

Marvin,

Sometimes people use CpuDeadLoop() to debug with a JTAG debugger so they will 
step over the code. So you can't use noreturn as that tells the optimizer it 
can remove the code following the no return function. So for example your 
entire program could get optimized away if you place a CpuBreakpoint() at the 
start of your function. 
Simple clang example:
~/work/Compiler>cat noreturn.c

int NoReturn(void) __attribute__ ((noreturn));

int
main()
{
  NoReturn();
  return 0;
}
~/work/Compiler>clang -Os -S  noreturn.c
~/work/Compiler>cat noreturn.S
        .section        __TEXT,__text,regular,pure_instructions
        .macosx_version_min 10, 11
        .globl  _main
_main:                                  ## @main
        pushq   %rbp
        movq    %rsp, %rbp
        callq   _NoReturn


.subsections_via_symbols


Depending on how much Heisenberg uncertainty you can stand....

You can -D MDEPKG_NDEBUG for your analyzer run. 
https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Library/DebugLib.h#L288
 

In the DSC map the DebugLib library class to 
https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
 all the functions are empty and you would avoid your issues. 

PcdDebugPropertyMask, set in DSC, can control what happens after an ASSERT(), 
but I'm guessing that is to far into the optimizer to be useful for you? If you 
compiled with clang LTO the CpuBreakpoint() and CpuDeadLoop() would get dead 
stripped. 
https://github.com/tianocore/edk2/blob/master/MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c#L146

Thanks,

Andrew Fish

> If you have experience with the Clang Static Analyzer or even this specific 
> issue, I would be happy if you would share your opinion of the concern.
> 
> Regards,
> Marvin.
> _______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.01.org/mailman/listinfo/edk2-devel

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to