Closed aashish29n closed 5 years ago
Hey @aashish29n , I need some context. What do you mean "compilation database has some gcc files and some clang files"? I don't understand this. Can you explain what do you mean by that?
Actually i am running scan-build on a directory which has lot of files. Some files use gcc as their compiler and some uses clang as their compiler.The files which uses gcc are build with gcc compilers.
The analyze-build
has a flag --use-analyzer
where you can specify which Clang to use to do the analysis. But it will run the analyzer against all files.
So, in your project there might be "gcc files" and "clang files", but for the analyze-build
they are the same.
What suppose to be the problem? Do you want to analyze only the "clang files"? (You might want to create a new compilation database, which has entries containg those only.) Or you want to run against all files, but it fails to do it? (This case I need to see some logs, that will explain why it was not running the analyzer.)
i want to run the analyzer against all the files but it only analyzing clang files not gcc files. I have read this that states that Scan-build analyzes your project by using a compiler to compile the project and clang to analyze your project. But in my case it is using clang for both compilation and analysis. By the way can analyze-build compile the files or not?? this is a sample log: can-build: DEBUG: Run analyzer against '['cc', '-c', '-nostdinc', '-Wno-pointer-sign', '-Wno-error=address', '-O', '-pipe', '-fno-builtin-printf', '-DELF', '-Dunix', '-Dunix', '-Dunix', '-DFreeBSD=6', '-Dmips64', '-DJUNOS_LEGACY', '-I../../../../../src/pan-release', '-I../../../../../src/pan-release/shared', '-I../../../../../src/pfe-shared/ipc', '-I../../../../../src/pfe/common/toolkits', '-DMINFRA_RESET_FREED_OBJS', '-DMINFRA_NO_CHUNK_ALLOC', '-DUSE_INFRA_PROV', '-O3', '-DDSI_NO_TRACE_ON_DUPLICATE', '-DMINFRA_NO_DELAYED_DOUBLE_FREE', '-DMINFRA_NO_PROV_MAGIC', '-I../../../../../src/junos/lib/libmspapp-infra/common', '-I../../../../../src/junos/lib/libmspapp-infra/dsi', '-I../../../../../src/junos/lib/libmspapp-infra/ipc', '-I../../../../../src/junos/lib/libmspapp-infra/lock', '-I../../../../../src/junos/lib/libmspapp-infra/mem/chunk', '-I../../../../../src/junos/lib/libmspapp-infra/mem/common', '-I../../../../../src/junos/lib/libmspapp-infra/mem/mag', '-I../../../../../src/junos/lib/libmspapp-infra/mem/objcache', '-I../../../../../src/junos/lib/libmspapp-infra/mem/pktbuf', '-I../../../../../src/junos/lib/libmspapp-infra/mem/prov', '-I../../../../../src/junos/lib/libmspapp-infra/mem/vsize', '-I../../../../../src/junos/lib/libmspapp-infra/threadpool', '-I../../../../../src/junos/lib/libmspapp-infra/timer', '-I../../../../../src/junos/lib/libmspapp-infra/trace', '-I../../../../../src/junos/lib/libmspapp-infra/utils', '-DSTANDALONE', '-I../../../../../src/junos/usr.sbin/mspdbg-cli', '-I../../../../../src/junos/lib/libmspapp-infra/vty', '-I../../../../../src/junos/lib/libmspapp-infra', '-std=gnu99', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/xlr64/usr/include', '-DTARGET_JUNOS', '-I../../../../../src/bsd/include', '-I../../../../../src/junos/bsd/include', '-I../../../../../src/junos-shared/idl/include', '-I../../../../../obj/xlr64/bsd/include', '-I../../../../../obj/xlr64/junos/bsd/include', '-I../../../../../obj/xlr64/junos/bsd/include/machine_arch/junos', '-I../../../../../src/junos/bsd/sys', '-I../../../../../src/bsd/sys', '-G', '0', '-EB', '-march=xlr', '-mabi=64', '-ggdb', '-gdwarf-2', '-g2', '-feliminate-unused-debug-types', '-msoft-float', '-mno-flush-func', '-mcall-freebsd', '-fPIC', '-mabicalls', '-G', '0', '-EB', '-march=xlr', '-mabi=64', '-ggdb', '-gdwarf-2', '-g2', '-feliminate-unused-debug-types', '-msoft-float', '-mno-flush-func', '-mcall-freebsd', '-fPIC', '-mabicalls', '-ggdb', '-gdwarf-2', '-g2', '-feliminate-unused-debug-types', '-I../../../../../src/junos/lib/libmspdbg-cli-mem/h', '-I../../../../../src/junos/lib/libcmd-parser', '-I../../../../../obj/xlr64/junos/lib/libcmd-parser', '-I../../../../../src/junos/lib/libjunos-timers/h', '-I../../../../../src/junos/lib/libjunos-sys-util/h', '-I../../../../../src/junos/lib/libevent/h', '-I../../../../../src/junos/lib/libmp-sdk/h', '-I../../../../../src/junos/lib/libsmplocks/h', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/external/mit/libxml2/dist/include', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/lib/libjunos-log-trace', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/xlr64/usr/lib', '-I../../../../../src/junos/lib/libjipc/h', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/common/usr/src/libjunos-fileio', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/lib/libjunos-xmlutil', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/lib/libjunos-string', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/lib/libjunos-path', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/lib/libjunos-bits', '-I../../../../../src/junos/lib/libconn/h', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/lib/libjunos-patricia', '-I../../../../../src/junos/lib/libjunos-systimes/h', '-I../../../../../src/pfe/common/toolkits/parser', '-I../../../../../src/junos/lib/libmspapp-infra/h', '-DJUNOS_INTERNAL_BUILD', '-DJUNOS_MAJOR=19', '-DJUNOS_MINOR=3', '-DJUNOS_DEV_BUILD', '-DJUNOS_BUILD', '-W', '-Wall', '-Wcast-qual', '-Wchar-subscripts', '-Wcomment', '-Werror', '-Wformat', '-Wimplicit', '-Winline', '-Wmissing-declarations', '-Wmissing-prototypes', '-Wnested-externs', '-Wparentheses', '-Wpointer-arith', '-Wreturn-type', '-Wshadow', '-Wstrict-prototypes', '-Wswitch', '-Wtrigraphs', '-Wuninitialized', '-Wunused', '-Wwrite-strings', '-I/b/aashisha/dcb_ui_final/obj/stage/xlr64/usr/include', '-I/b/aashisha/dcb_ui_final/obj/stage/xlr64/include', '-I../../../../../src/pfe-shared/include', '-I../../../../../src/pfe-shared/toolkits', '-I../../../../../src/junos/bsd/sys', '-I../../../../../src/bsd/sys', '-I../../../../../src/junos/include', '-I../../../../../src/junos-shared/include', '-I../../../../../src/junos-shared/platform/bsd', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/xlr64/usr/include', '-I../../../../../src/pfe-shared/include', '-I../../../../../src/pfe-shared/toolkits', '-I../../../../../src/junos/bsd/sys', '-I../../../../../src/bsd/sys', '-I../../../../../src/junos/include', '-I../../../../../src/junos-shared/include', '-I../../../../../src/junos-shared/platform/bsd', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/xlr64/usr/include', '-D__libmspapp_infra', '-I/b/aashisha/dcb_ui_final/obj/stage/xlr64/usr/include', '-I/b/aashisha/dcb_ui_final/obj/stage/xlr64/include', '-I../../../../../src/pfe-shared/include', '-I../../../../../src/pfe-shared/toolkits', '-I../../../../../src/junos/bsd/sys', '-I../../../../../src/bsd/sys', '-I../../../../../src/junos/include', '-I../../../../../src/junos-shared/include', '-I../../../../../src/junos-shared/platform/bsd', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/xlr64/usr/include', '-I../../../../../src/pfe-shared/include', '-I../../../../../src/pfe-shared/toolkits', '-I../../../../../src/junos/bsd/sys', '-I../../../../../src/bsd/sys', '-I../../../../../src/junos/include', '-I../../../../../src/junos-shared/include', '-I../../../../../src/junos-shared/platform/bsd', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/xlr64/usr/include', '-o', 'mspapp_pktbuf.o.o', '../../../../../src/junos/lib/libmspapp-infra/mem/pktbuf/mspapp_pktbuf.c']' scan-build: DEBUG: analysis, on default arch scan-build: DEBUG: analysis, language: c scan-build: DEBUG: exec command ['/volume/hab/Linux/Ubuntu-12.04/x86_64/llvm/5.0/current/bin/clang', '-###', '--analyze', '-Xclang', '-analyzer-output=html', '-x', 'c', '-nostdinc', '-Wno-pointer-sign', '-Wno-error=address', '-O', '-pipe', '-fno-builtin-printf', '-DELF', '-Dunix', '-Dunix', '-Dunix', '-DFreeBSD=6', '-Dmips64', '-DJUNOS_LEGACY', '-I../../../../../src/pan-release', '-I../../../../../src/pan-release/shared', '-I../../../../../src/pfe-shared/ipc', '-I../../../../../src/pfe/common/toolkits', '-DMINFRA_RESET_FREED_OBJS', '-DMINFRA_NO_CHUNK_ALLOC', '-DUSE_INFRA_PROV', '-O3', '-DDSI_NO_TRACE_ON_DUPLICATE', '-DMINFRA_NO_DELAYED_DOUBLE_FREE', '-DMINFRA_NO_PROV_MAGIC', '-I../../../../../src/junos/lib/libmspapp-infra/common', '-I../../../../../src/junos/lib/libmspapp-infra/dsi', '-I../../../../../src/junos/lib/libmspapp-infra/ipc', '-I../../../../../src/junos/lib/libmspapp-infra/lock', '-I../../../../../src/junos/lib/libmspapp-infra/mem/chunk', '-I../../../../../src/junos/lib/libmspapp-infra/mem/common', '-I../../../../../src/junos/lib/libmspapp-infra/mem/mag', '-I../../../../../src/junos/lib/libmspapp-infra/mem/objcache', '-I../../../../../src/junos/lib/libmspapp-infra/mem/pktbuf', '-I../../../../../src/junos/lib/libmspapp-infra/mem/prov', '-I../../../../../src/junos/lib/libmspapp-infra/mem/vsize', '-I../../../../../src/junos/lib/libmspapp-infra/threadpool', '-I../../../../../src/junos/lib/libmspapp-infra/timer', '-I../../../../../src/junos/lib/libmspapp-infra/trace', '-I../../../../../src/junos/lib/libmspapp-infra/utils', '-DSTANDALONE', '-I../../../../../src/junos/usr.sbin/mspdbg-cli', '-I../../../../../src/junos/lib/libmspapp-infra/vty', '-I../../../../../src/junos/lib/libmspapp-infra', '-std=gnu99', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/xlr64/usr/include', '-DTARGET_JUNOS', '-I../../../../../src/bsd/include', '-I../../../../../src/junos/bsd/include', '-I../../../../../src/junos-shared/idl/include', '-I../../../../../obj/xlr64/bsd/include', '-I../../../../../obj/xlr64/junos/bsd/include', '-I../../../../../obj/xlr64/junos/bsd/include/machine_arch/junos', '-I../../../../../src/junos/bsd/sys', '-I../../../../../src/bsd/sys', '-G', '0', '-EB', '-march=xlr', '-mabi=64', '-ggdb', '-gdwarf-2', '-g2', '-feliminate-unused-debug-types', '-msoft-float', '-mno-flush-func', '-mcall-freebsd', '-fPIC', '-mabicalls', '-G', '0', '-EB', '-march=xlr', '-mabi=64', '-ggdb', '-gdwarf-2', '-g2', '-feliminate-unused-debug-types', '-msoft-float', '-mno-flush-func', '-mcall-freebsd', '-fPIC', '-mabicalls', '-ggdb', '-gdwarf-2', '-g2', '-feliminate-unused-debug-types', '-I../../../../../src/junos/lib/libmspdbg-cli-mem/h', '-I../../../../../src/junos/lib/libcmd-parser', '-I../../../../../obj/xlr64/junos/lib/libcmd-parser', '-I../../../../../src/junos/lib/libjunos-timers/h', '-I../../../../../src/junos/lib/libjunos-sys-util/h', '-I../../../../../src/junos/lib/libevent/h', '-I../../../../../src/junos/lib/libmp-sdk/h', '-I../../../../../src/junos/lib/libsmplocks/h', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/external/mit/libxml2/dist/include', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/lib/libjunos-log-trace', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/xlr64/usr/lib', '-I../../../../../src/junos/lib/libjipc/h', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/common/usr/src/libjunos-fileio', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/lib/libjunos-xmlutil', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/lib/libjunos-string', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/lib/libjunos-path', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/lib/libjunos-bits', '-I../../../../../src/junos/lib/libconn/h', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/src/ui/lib/libjunos-patricia', '-I../../../../../src/junos/lib/libjunos-systimes/h', '-I../../../../../src/pfe/common/toolkits/parser', '-I../../../../../src/junos/lib/libmspapp-infra/h', '-DJUNOS_INTERNAL_BUILD', '-DJUNOS_MAJOR=19', '-DJUNOS_MINOR=3', '-DJUNOS_DEV_BUILD', '-DJUNOS_BUILD', '-W', '-I/b/aashisha/dcb_ui_final/obj/stage/xlr64/usr/include', '-I/b/aashisha/dcb_ui_final/obj/stage/xlr64/include', '-I../../../../../src/pfe-shared/include', '-I../../../../../src/pfe-shared/toolkits', '-I../../../../../src/junos/bsd/sys', '-I../../../../../src/bsd/sys', '-I../../../../../src/junos/include', '-I../../../../../src/junos-shared/include', '-I../../../../../src/junos-shared/platform/bsd', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/xlr64/usr/include', '-I../../../../../src/pfe-shared/include', '-I../../../../../src/pfe-shared/toolkits', '-I../../../../../src/junos/bsd/sys', '-I../../../../../src/bsd/sys', '-I../../../../../src/junos/include', '-I../../../../../src/junos-shared/include', '-I../../../../../src/junos-shared/platform/bsd', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/xlr64/usr/include', '-D__libmspapp_infra', '-I/b/aashisha/dcb_ui_final/obj/stage/xlr64/usr/include', '-I/b/aashisha/dcb_ui_final/obj/stage/xlr64/include', '-I../../../../../src/pfe-shared/include', '-I../../../../../src/pfe-shared/toolkits', '-I../../../../../src/junos/bsd/sys', '-I../../../../../src/bsd/sys', '-I../../../../../src/junos/include', '-I../../../../../src/junos-shared/include', '-I../../../../../src/junos-shared/platform/bsd', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/xlr64/usr/include', '-I../../../../../src/pfe-shared/include', '-I../../../../../src/pfe-shared/toolkits', '-I../../../../../src/junos/bsd/sys', '-I../../../../../src/bsd/sys', '-I../../../../../src/junos/include', '-I../../../../../src/junos-shared/include', '-I../../../../../src/junos-shared/platform/bsd', '-I/b/aashisha/ui_sb2/pub/ui/dev_common_branch/20190508.aashisha.r1025893/stage/gcc-4.2.1/xlr64/usr/include', u'/b/aashisha/dcb_ui_final/src/junos/lib/libmspapp-infra/mem/pktbuf/mspapp_pktbuf.c', '-o', '/b/aashisha/report/scan-build-2019-05-14-16-58-42-197291-xrJ7mI'] in /b/aashisha/dcb_ui_final/obj/xlr64/junos/lib/libmspapp-infra scan-build: ERROR: Problem occured during analyzis. Traceback (most recent call last): File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/analyze.py", line 318, in run return arch_check(opts) File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/analyze.py", line 283, in wrapper return function(*args, kwargs) File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/analyze.py", line 476, in arch_check return continuation(opts) File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/analyze.py", line 283, in wrapper return function(*args, *kwargs) File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/analyze.py", line 448, in language_check return continuation(opts) File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/analyze.py", line 283, in wrapper return function(args, kwargs) File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/analyze.py", line 418, in filter_debug_flags return continuation(opts) File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/analyze.py", line 283, in wrapper return function(*args, *kwargs) File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/analyze.py", line 406, in run_analyzer continuation(opts) File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/analyze.py", line 283, in wrapper return function(args, **kwargs) File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/analyze.py", line 361, in report_failure ] + opts['flags'] + [opts['file'], '-o', name], cwd) File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/clang.py", line 42, in get_arguments output = run_command(cmd, cwd=cwd) File "/b/aashisha/llvm-5.0/clang/tools/scan-build-py/libscanbuild/init.py", line 77, in run_command raise ex
i want to run the analyzer against all the files but it only analyzing clang files not gcc files.
I was re-reading the code, and it does run against all files in the compilation database. It's not aware if something "gcc file" or "clang file". It runs against all files. So, I think it does what you want. Unless you have seen it in the log that it was not executing the analyzer command for all files. (You can grep
the build output for a "gcc file".)
By the way can analyze-build compile the files or not??
The analyze-build
runs the Clang static analyzer against all files in the compilation database. It parse the source file and executes the analyzer passes. I would not call it as compilation. (It does not generate object file, it generate a report if it found an error.)
I have read this that states that Scan-build analyzes your project by using a compiler to compile the project and clang to analyze your project. But in my case it is using clang for both compilation and analysis.
scan-build
is a thing which does what intercept-build
and analyze-build
does. (I would not go into details here. You can read the documentation or the code if you are more interested.) You should use the analyze-build
command if you already have a compilation database, so it won't run any compiler it will run only Clang static analyzer. (The Clang static analyzer is in the clang
executable. So, it will execute the clang
program, but it will run the static analyzer and not gonna do compilation.)
this is a sample log: [...]
From this log you've sent I saw that it read an entry from the compilation database, and it tries to run the Clang static analyzer, and it fails. Which means: a) it was running Clang static analyzer against a file which you would call "gcc file". b) It did not compile it. c) It failed to analyze it.
Why it failed to analyze it? I don't know from this log... It should generate failure reports in the output directory, that shall contains the standard error message, the preprocessor output and some basic information about the compiler. You can inspect those files to find out what's causing the failure.
But to me it seems logical, if the project was distinguish the "gcc files", because it compiler only with gcc. So it might be the problem that they are not compiling with Clang. Did you try to compile them with Clang? Maybe try that, without scan-build
or analyze-build
. Change the build file to use Clang for those files too. What do you think?
if you see the sample log that i shared above, in that if you see the command above that line scan-build: DEBUG: analysis, on default arch. that command is a gcc command because if you see it contains some GNU flags which clang does not understand. if you see the log where it states scan-build: DEBUG: exec command their it execuates this command where the cc value got replaced with clang path and it append some analysis flag and took the rest of the flags from the above command only(which also contains those GNU flags<for eg -mcall-freebsd,-mno-flush-funcd> which clang does not supports. So now when it executes this command then it give errors because here it is trying to run clang on a gcc file. And also i have tried to execute this command with clang it is giving me errors like: clang-5.0: error: unknown argument: '-mno-flush-func' clang-5.0: error: unknown argument: '-mcall-freebsd' clang-5.0: error: unknown argument: '-mno-flush-func' clang-5.0: error: unknown argument: '-mcall-freebsd'
So that is why it is failing to analyze.
Ok, I'm glad that you've found the root cause for the failure... Do you think this problem Is related to this tool? (If not, I would close this ticket.) What would help you to find fix to your problem alone? Do you need more documentation? Or the logs were not misleading?
Hi i think you misunderstood my problem!!! I think it is related to this tool only because this tool only need to use clang for the analysis part only right. Here it is read the command from the database and replacing the compiler name that was mentioned in the database with clang and tried the execute that command but ideally it should not do that. Because for analyze-build it does not matter whether it analyze clang files or gcc files.
hi if you see its code.. In line 402 of analyze.py it calls this get_arguments function in this it pass clang as an argument along with lots of flags right. Now if you see the get_arguments function definition you see it call the run command function with that command is like this (clang and option that we passed during get_arguments call and flags that it took from the compilation database). That run command function executes this command. But that command has some flags which are specific to gcc compiler and it tries to executes those with clang compiler which results in unknown-arguments. But the script should not run like that right. if you think this is not this tool issue then pls let me know how to analyze a gcc file which has GNU flags which clang does not understand. for scan-build it does not matter whether we are analyzing a gcc file or a clang files
i can say that problem is this tools problem only because i am reading the code of this tool from past 3 months.
Hey @aashish29n , thanks to clarify your expectation.
You are suggesting to filter those flags out (which Clang would not understand) before it calls the static analyzer... I'm not convinced that would be the best thing to do. I'm gonna tell you why I'm hesitating, and give you a tip for workaround.
Clang is trying to accept all gcc flags. (At least that's what I've learn to read their mailing list a few years back. That might have been changed, but don't think so.) Which means, most of the flag (used by gcc) will be understand by Clang. The situation is improving for every relase. So, your current version 5.0 might not understand these flags, but there is a chance that the recent version does... And flags are not the only difference between these compilers. While some code will compile with gcc, that will not compile with Clang. (Famous example is the linux kernel itself.)
Which means, if this tool starts to filter out some compiler flags, it has to be aware which Clang version it uses for analysis. (And filter or not filter some flags if the compiler version is X.) This is not trivial work. And even if it filters those flags out, it will not guarantee that all file will be analyzed.
I would suggest to change the build to run all compilation with Clang. Capture those compilations (into a compilation database) and run the analyzer against it... There would be no "gcc file" or "clang file". You can spot early which files can be compiled with Clang. And run the analyzer against those files only.
What's your opinion?
Thanks for your suggestion but i am not asking to filter out those flags. i just want know when the script calls get_arguments function in the analyze.py, In that the command that it pass to the get_arguments is a analysis command or not(looks like a analysis command).
For my problem What i thought i can do is to specify --use-cc argument in the script before run_command in so that it will take the proper compiler to run those files(the value of --use-cc i can take from the compilation database) and clang to analyze those files(Don't know whether it is possible or not? OR will it run the compiler from compilation database and clang for analysis?)
Needed your opinion on that thought?
Yes, the libscan/analyze.py
module is responsible to run the static analyzer. The report_failure
method calls it when the analyzer crashed, and the run_analyzer
method calls to run the analyzer.
The --use-cc
flag is used for intercepting the compiler calls, not when it runs the analyzer. (As far as I know, the analyze-build
command does not even accepts it.)
Don't understand your question. The Clang static analyzer can be executed as clang --analyze ... source.c -o report.html
. It looks like a compiler call, but it runs different logic. And you can't pass a different compiler to it to run the analyzer. It will always run the Clang C/C++ parser and run the analyzer against the AST. So, it understand only those flags which is understood by the Clang... But again, I've might misunderstood what you are trying to do.
No. You didn't misunderstood my question. So is their any way in which scan-build can analyze those files which are build with gcc(which has gcc specific flags)? Because Half of my files are clang files and half are gcc files. So in my case it is analyzing and generating reports for only half of my files(clang files).
If a file can be compiled with Clang, it can be analyzed with the Clang static analyzer. (And the job of this tool is to make that happen, without change your build system.) If can't be compiled with Clang, it can't be analyzed with the Clang static analyzer.
As earlier suggested, if you inspect the "gcc files" and try to compile then with Clang then you got what you wanted... This could be easy or hard. Don't know much about your project, so can't say how much work is that... But if it's written in C or C++, both compiler understand thos languages. If it's some embeded project, Clang also has some coverage that... You can inspect your build system why those special flags are there. Maybe it's important for code generation only. Your goal could be only compile these files. (It does not have to link the object files successfuly, or run the tests.) That's what I would do.
Hi.. thanks for that suggestion, Just one last question is it that scan-build can only analyze those files which compile with clang only? If so then what does this means scan-build analyzes your project by using a compiler to compile the project and clang to analyze your project. The script uses simple heuristics to determine which compiler should be used (it defaults to clang on Darwin and gcc on other platforms). This i read from the documentation. If you are working on scan-build you can fix this problem(i think it can be a really big fix for the tool.)
Hey @aashish29n , I'm closing this ticket now. Feel free to send a pull-request if you know how to improve or fix this tool. (You've said, you are familiarize yourself to the code in the past 3 months.)
As I mentioned earlier, filtering out the target specific flags could be an option, but I don't think that would cover all the cases where it might fail. But also, I'm not that familiar your project... And I have little experience with cross compilation. Maybe try another tool which does have better support for it.
Hey laszlo, Thanks for all your help . you are a saviour but i just have 1 more query. Is scan-build running the analyzer against a AST or a .C file? if it is running against a AST then why the analyzer needs all the flags from the compilation database. OR if it is running the analyzer against a .C file with all the compiler flags then what is the point of generating the compilation database because it recompiles the source file with clang again. i have read somewhere which states that compiler flags are needed only in the compilation phase. Can you pls help me one last time pls...!!!!
The analyzer consist multiple checkers. Some checkers works on something called: "exploded execution trace", which is created from the AST. There are also checkers, which are working on simple AST.
So, as you see the AST is not only used for to compile your program. It is used inside the compiler when it runs the compilation phase. But many other logic, which are not generating code, is also using the AST.
The AST is built from the source file by the parser... The parser needs compiler flags. (Not all flags, but the relevant ones, like the pre-processor ones:) But the logic which deals with the AST might also need some compiler flags too. (The static analyzerr checkers are also look at certain compiler flags. Which are not only the preprocessor flags, but ones which might be used for the compilation pass too.)
The compilation database is an easy to read form to store how each module was compiled. This is enough for many tools to re-build the AST from the source files and run whatever logic on it. (Commands like clang-format
or clang-tidy
does that too.) In the Clang repo, there are a set of libraries which gives you C/C++ API to implement these logic which works on AST. And they also provide a common way to build the AST from the compilation database. (So, people who write tools as such, they don't have to re-implement it.)
If you are interested in this topic, you should definitelly read more Clang internal docs or ask people on the mailing list.
If you just want to run against a project, then this tool does a good job on it. (At least it works better for me than the scan-build
which the Clang project distributes with.) You can be happy that half of your project was analyzed! ;) And I've already suggested some tricks how to attempt to cover the missing half... Unfortunatelly sometimes there is no easy way to do things.
Hi Laszlo,
i am running the analyze-build on my compilation database.My compilation database has some gcc files and some clang files. So it is analysing only clang files not gcc files. In that the original functionality will be to use the proper compiler for building and clang for analysis but it is build with clang only. i have checked in verbose mode also that it is not analysing gcc files.So is their any way in which i can specify the appropriate compiler for build like setting use-cc variable in the script and specify compiler that it has to use for build by parsing compilation database.