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

Sachkov, Alexey via cfe-dev cfe-dev at lists.llvm.org
Fri May 11 03:22:06 PDT 2018


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

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180511/79e590ba/attachment.html>


More information about the cfe-dev mailing list