[cfe-dev] RFC: Frontend insight remarks

Jan Korous via cfe-dev cfe-dev at lists.llvm.org
Tue Jul 23 21:21:20 PDT 2019


Hi all,

I would like to ask for feedback on an idea of compilation logging.

You can find PoC implementation here:
https://reviews.llvm.org/D65187 <https://reviews.llvm.org/D65187>

# Motivation

Despite programming models being fairly complex (esp. C++) clang provides only limited insight into what happens during semantic analysis. I am aware of just a couple of diagnostics (e. g. -fshow-overloads).  Although other tools might help in specific cases I consider it sub-optimal:
For some cases there's no tool.
Compiler is ultimately the source of truth and it seems like a waste of effort to replicate its logic in an external tool.

For example to understand the following simple piece of code developers need to recall rules for special class members implicit definitions and rules for implicit conversions.

struct foo { };
struct bar : foo { };

int main() {
    bar b;
    const foo f = b;
}

The point is - although none of these rules are overly complicated and for a seasoned C++ developer they are just natural, it still seems easier to not have to model these in one's head.

# PoC implementation

For the above example the PoC implementation generates these remarks:

example.cpp:1:8: remark: implicit default constructor was generated for class 'foo' [-Rspecial-member-generated]
example.cpp:1:8: remark: implicit destructor was generated for class 'foo' [-Rspecial-member-generated]
example.cpp:1:8: remark: implicit copy constructor was generated for class 'foo' [-Rspecial-member-generated]
example.cpp:1:8: remark: implicit move constructor was generated for class 'foo' [-Rspecial-member-generated]
example.cpp:2:8: remark: implicit default constructor was generated for class 'bar' [-Rspecial-member-generated]
example.cpp:2:8: remark: implicit copy constructor was generated for class 'bar' [-Rspecial-member-generated]
example.cpp:2:8: remark: implicit move constructor was generated for class 'bar' [-Rspecial-member-generated]
example.cpp:6:19: remark: using implicit conversion from 'bar' to 'const bar' [-Rimplicit-conversion]
example.cpp:6:19: remark: using implicit conversion from 'const bar' to 'const foo' [-Rimplicit-conversion]

So far I selected just a handful of use-cases where additional information might be useful. Since this potentially generates loads of diagnostic output I also added an option for source range filtering.

Please see the provided tests to learn how to use the functionality.

For the PoC I decided to output this information directly from Sema but maybe it is possible to create a better user experience with more interactive/on-demand workflow (maybe as part of clangd or some other tool?). Two things should be considered for such approaches: 
1. For certain interesting use-cases, the state of Sema during compilation-time is necessary and AST on it's own is not sufficient - for example for function name resolution.
2. If such feature is kept in compilation codepath in clang it is less likely for the feature and the actual working of clang to diverge.

Thanks.

Jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190723/eb4b63e8/attachment.html>


More information about the cfe-dev mailing list