[cfe-dev] [analyzer] Emit errors from StaticAnalyzer

George Karpenkov via cfe-dev cfe-dev at lists.llvm.org
Fri May 11 13:37:14 PDT 2018


Hi Alexey,

Could you give some examples of diagnostics you have implemented?

In general, clang static analyzer emits warnings as it is allowed to have false positives by design.
I think your workflow can be achieved without any changes required though: if you know that checker X
will not have false positive, you can just configure your build system to fail the build if the static analyzer
finds any bugs with only your checker turned on.

Regards,
George

> On May 11, 2018, at 3:22 AM, Sachkov, Alexey via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hi,
>  
> I would like to ask what do you think about having possibility to emit errors from clang StaticAnalyzer?
>  
> Recently I encountered a problem with implementing complex diagnostics in clang (which requires call graph analysis, for example): it is hard to implement such diagnostics in Sema because there is no place with fully-built AST.
> So, I used static analyzer and implemented a few additional checkers, but the problem with static analyzer is that all diagnostics are emitted as warnings.
> Here is an example of the patch I would like to commit: https://github.com/AlexeySachkov/clang/commit/898c9c566d4c1c37c2d56787fd08ff8b1697aca9 <https://github.com/AlexeySachkov/clang/commit/898c9c566d4c1c37c2d56787fd08ff8b1697aca9>
>  
> What do you think?
> If there are no objections from adding possibility to emit errors from static analyzer, I will put a patch for review. Any comments on implementation?
>  
>  
> My main task is to implement some diagnostic messages, probably someone can advise me a better solution than static analyzer? Here an example (I’m interested in OpenCL C):
>  
> int val __attribute__((my_attr1));
> void func() {
>     val = 10; // expected-error{{variables declared with my_attr1 attribute cannot be used from kernels declared with my_attr2 attribute}}
> }
> __attribute__((my_attr2))
> __kernel void my_kernel() {
>     func();
> }
>  
> I knew that call graph analysis is used in Sema during compilation of CUDA sources and if static analyzer is completely wrong place for such stuff, I can try to use CUDA approach and update the Sema.
> Also I wouldn’t like to use clang plugins or to create a clang-based tool.
>  
> Best regards,
> Alexey Sachkov
> 
> --------------------------------------------------------------------
> Joint Stock Company Intel A/O
> Registered legal address: Krylatsky Hills Business Park, 
> 17 Krylatskaya Str., Bldg 4, Moscow 121614, 
> Russian Federation
> 
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180511/59ba2f2b/attachment.html>


More information about the cfe-dev mailing list