[cfe-users] libclang: Syntactic or Semantic analysis?

Philipp, Damian Damian.Philipp at vector.com
Tue Mar 17 00:01:52 PDT 2015


Hello Clang experts,

I am currently working on upgrading a tool for static code analysis based on libclang. It uses a RecursiveASTVisitor to traverse the syntax tree and extract some information relevant to us. To support a bunch of new features, I had to upgrade Clang from Version 3.1 as used before to 3.4.2 (I am stuck on Visual Studio 2010, so no up-to-date Clang, unfortunately). To verify that the new Clang behaves as expected, I have inherited a number of testcases from another project, based the clang test suite. Among other things, these testcases check whether extra parentheses are detected (example: 'if ((x == 2)) {') or whether a static analysis shows that an array access out of bounds is found in the code (example: 'int array[2]; array[5] = 7;'). However, my tool does not output the respective warnings. If I run clang.exe on the respective source files, I get all the expected warnings.

After brooding on this problem for a while, I realized that detecting array access out of bounds is actually a semantic analysis, not a syntactic one. However, when using a RecursiveASTVisitor, I am only doing a syntactic analysis. Thus, I can actually expect *not* to see any of these warnings. Are these assumptions correct, or does Clang always perform a semantic analysis and it is in fact my code that eats the warning messages?

Thank you in advance for any input!

Best regards

Damian Philipp
-----------------------------------------------------
Software Development Engineer
PES

Vector Informatik GmbH
Ingersheimer Str. 24
70499 Stuttgart
Deutschland / Germany
Tel.: +49 711 80670-3656
Fax: +49 711 80670-399
mailto: Damian.Philipp at vector.com<mailto:Damian.Philipp at vector.com>
Internet: www.vector.com<http://www.vector.com/>

Sitz der Gesellschaft / Head Office: Stuttgart
Handelsregister / Commercial Register:
Amtsgericht Stuttgart, HRB 17317
Geschaeftsfuehrer / Managing Directors:
Dr. Thomas Beck, Thomas Riegraf
-----------------------------------------------------

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20150317/a71f83fd/attachment.html>


More information about the cfe-users mailing list