Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

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

Open Quuxplusone opened 6 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR37268
Status NEW
Importance P normal
Reported by Benny K J (benny.kj@gadgeon.com)
Reported on 2018-04-27 06:09:37 -0700
Last modified on 2018-04-27 20:22:31 -0700
Version 6.0
Hardware PC other
CC benny.kj@gadgeon.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
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

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

5. 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_HEAP_SIZE=0 -
D_..X_TINY_HEAP_SIZE=0 -D_..X_NEAR_HEAP_SIZE=20 -D_..X_FAR_HEAP_SIZE=0 -
D_..X_HUGE_HEAP_SIZE=0 -D_..X_CSTACK_SIZE=20 -D_..X_RSTACK_SIZE=20 -
D_..X_FLASH_CODE_END=_..X_FLASH_END -f c:/Program Files (x86)\IAR
Systems\Embedded Workbench 8.0\avr\src\template\cfg1soim.xcl -
D_..X_FLASH_BASE=_..X_INTVEC_SIZE -H1895 -h(CODE)0-(_..X_INTVEC_SIZE-1) -
D_..X_CSTACK_BASE=_..X_SRAM_BASE -D_..X_CSTACK_END=_..X_SRAM_END -
D_..X_RSTACK_BASE=_..X_SRAM_BASE -D_..X_RSTACK_END=_..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
}
Quuxplusone 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.