llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.86k stars 11.48k forks source link

scan-build reports unable to detect bugs when used with IAR C Compiler #36616

Open llvmbot opened 6 years ago

llvmbot commented 6 years ago
Bugzilla Link 37268
Version 6.0
OS other
Reporter LLVM Bugzilla Contributor

Extended Description

I'm trying to get scan-build working with IAR C/C++ Compiler but scan-build always reports No bugs found.

I have performed the below steps.

  1. On Windows 10 64 bit, Downloaded and installed http://releases.llvm.org/6.0.0/LLVM-6.0.0-win64.exe

  2. Installed strawberry-perl-5.26.2.1-64bit.msi

  3. Ran the below command

scan-build -v -v -v -o .\test --keep-empty --use-analyzer c:\LLVM\bin\clang.exe --use-cc "c:\Program Files (x86)\IAR Systems\Embedded Workbench 8.0\avr\bin\iccavr.exe" -enable-checker alpha.core.PointerArithm "c:\Program Files (x86)\IAR Systems\Embedded Workbench 8.0\common\bin\IarBuild.exe" "IAR Embedded Workbench\avr\examples\IAR\STK500\ledchaser.ewp" -build Debug -log all

  1. I've also tried without the -enable-checker alpha.core.PointerArithm and the result is still No bugs found.

  2. A directory by the name 2018-04-27-181923-2936-1 or similar name is getting created every time but has no contents.

Kindly suggest how to debug further.

Please find the detailed log below:

Log

C:\Users\benny\Documents>scan-build -v -v -v -o .\test --keep-empty --use-analyzer c:\LLVM\bin\clang.exe --use-cc "c:\Program Files (x86)\IAR Systems\Embedded Workbench 8.0\avr\bin\iccavr.exe" -enable-checker alpha.core.PointerArithm "c:\Program Files (x86)\IAR Systems\Embedded Workbench 8.0\common\bin\IarBuild.exe" "IAR Embedded Workbench\avr\examples\IAR\STK500\ledchaser.ewp" -build Debug -log all

C:\Users\benny\Documents>perl -S scan-build -V -v -v -v -o .\test --keep-empty --use-analyzer c:\LLVM\bin\clang.exe --use-cc "c:\Program Files (x86)\IAR Systems\Embedded Workbench 8.0\avr\bin\iccavr.exe" -enable-checker alpha.core.PointerArithm "c:\Program Files (x86)\IAR Systems\Embedded Workbench 8.0\common\bin\IarBuild.exe" "IAR Embedded Workbench\avr\examples\IAR\STK500\ledchaser.ewp" -build Debug -log all scan-build: Using 'c:\LLVM\bin\clang.exe' for static analysis scan-build: Emitting reports for this run to 'C:/Users/benny/Documents/test/2018-04-27-182051-7560-1'.

 IAR Command Line Build Utility V8.0.7.4869
 Copyright 2002-2017 IAR Systems AB.

Building configuration: ledchaser - Debug Updating build tree... C:\Users\benny\Documents\IAR Embedded Workbench\avr\examples\IAR\STK500\Debug\Obj\ledchaser.r90 C:\Users\benny\Documents\IAR Embedded Workbench\avr\examples\IAR\STK500\Debug\Exe\ledchaser.d90

2 file(s) deleted. Updating build tree...

ledchaser.c iccavr.exe C:\Users\benny\Documents\IAR Embedded Workbench\avr\examples\IAR\STK500\ledchaser.c --cpu=m48 -ms -o C:\Users\benny\Documents\IAR Embedded Workbench\avr\examples\IAR\STK500\Debug\Obj --initializers_in_flash --no_cse --no_inline --no_code_motion --no_cross_call --no_clustering --no_tbaa --debug -e --eeprom_size 256 --dlib --dlib_config c:/Program Files (x86)\IAR Systems\Embedded Workbench 8.0\avr\LIB\DLIB\dlAVR-1s-ec_mul-n.h -Ol

IAR C/C++ Compiler V7.10.1.1197 for Atmel AVR Copyright 1996-2017 IAR Systems AB. Evaluation license - IAR Embedded Workbench for Atmel AVR, Evaluation Version 7.10 C:\Users\benny\Documents\IAR Embedded Workbench\avr\examples\IAR\STK500\ledchaser.c(52) : Warning[Pe550]: variable "p" was set but never used

52 bytes of CODE memory 0 bytes of DATA memory (+ 2 bytes shared)

Errors: none Warnings: 1

Linking xlink.exe C:\Users\benny\Documents\IAR Embedded Workbench\avr\examples\IAR\STK500\Debug\Obj\ledchaser.r90 -o C:\Users\benny\Documents\IAR Embedded Workbench\avr\examples\IAR\STK500\Debug\Exe\ledchaser.d90 -Ic:/Program Files (x86)\IAR Systems\Embedded Workbench 8.0\avr\LIB\ -f c:/Program Files (x86)\IAR Systems\Embedded Workbench 8.0\avr\src\template\cfgm48.xcl -D_..X_HEAPSIZE=0 -D..X_TINY_HEAPSIZE=0 -D..X_NEAR_HEAPSIZE=20 -D..X_FAR_HEAPSIZE=0 -D..X_HUGE_HEAPSIZE=0 -D..X_CSTACKSIZE=20 -D..X_RSTACKSIZE=20 -D..X_FLASH_CODEEND=..X_FLASHEND -f c:/Program Files (x86)\IAR Systems\Embedded Workbench 8.0\avr\src\template\cfg1soim.xcl -D..X_FLASHBASE=..X_INTVECSIZE -H1895 -h(CODE)0-(..X_INTVECSIZE-1) -D..X_CSTACKBASE=..X_SRAMBASE -D..X_CSTACKEND=..X_SRAMEND -D..X_RSTACKBASE=..X_SRAMBASE -D..X_RSTACKEND=..X_SRAM_END -rt -s __program_start c:/Program Files (x86)\IAR Systems\Embedded Workbench 8.0\avr\LIB\DLIB\dlAVR-1s-ec_mul-n.r90 -e_PrintfSmall=_Printf -e_ScanfFull=_Scanf

 IAR Universal Linker V6.5.0.91
 Copyright 1987-2016 IAR Systems AB.

108 bytes of CODE memory (+ 50 range fill ) 64 bytes of DATA memory (+ 2 absolute )

Errors: none Warnings: none

Total number of errors: 0 Total number of warnings: 1

scan-build: No bugs found.

======================================================= Source File

void test1(); void test2(); int main( void ) {

test1();
test2();
while(1)        /* Eternal loop */
{
}

} void test1() { int x; int *p; p = &x + 1; // warn }

void test2() { void (*foo)(void); foo = 0; foo(); // warn: function pointer is null }

llvmbot commented 6 years ago

I have tried to run the clang as below on individual source files of the project without specifying any compiler and it is able to generate the below output.

So it seems that my invocation of the scan-build command may be wrong.

Kindly suggest how to debug further so that I can run the analyzer on the entire project.

============================ Output Log

PS C:\Users\benny> C:\LLVM\bin\clang --analyze -Xanalyzer "-analyzer-checker=alpha.core.PointerArithm" "C:\Users\benny\D ocuments\IAR Embedded Workbench\avr\examples\IAR\STK500\ledchaser.c" C:\Users\benny\Documents\IAR Embedded Workbench\avr\examples\IAR\STK500\ledchaser.c:36:3: warning: Value stored to 'p' is never read p = &x + 1; // warn ^ ~~ C:\Users\benny\Documents\IAR Embedded Workbench\avr\examples\IAR\STK500\ledchaser.c:36:10: warning: Pointer arithmetic on non-array variables relies on memory layout, which is dangerous p = &x + 1; // warn ~~ ^ C:\Users\benny\Documents\IAR Embedded Workbench\avr\examples\IAR\STK500\ledchaser.c:42:3: warning: Called function pointer is null (null dereference) foo(); // warn: function pointer is null ^~~~~ 3 warnings generated.

llvmbot commented 6 years ago

assigned to @devincoughlin