This is an archive of the discontinued LLVM Phabricator instance.

[clang][DeclPrinter] Fix AST print of delegating constructors
ClosedPublic

Authored by strimo378 on Jun 30 2023, 12:00 AM.

Details

Summary

DeclPrinter::PrintConstructorInitializers did not consider delegating initializers. As result, the output contained an "NULL TYPE" for delegating constructors.

I chose a generic test case name (ast-print-method-decl.cpp). The plan is to add there other method related test cases for fixes I have in my local branch.

Please use "Timo Stripf" and timo.stripf@emmtrix.com for commit.

Diff Detail

Event Timeline

strimo378 created this revision.Jun 30 2023, 12:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 12:00 AM
strimo378 requested review of this revision.Jun 30 2023, 12:00 AM

Thank you for the fix! This generally LGTM, but I did find some extra test cases to add.

clang/test/AST/ast-print-method-decl.cpp
2

I think the file should be named ast-print-delegating-constructor.cpp, WDYT?

16

I'd also like to see test cases along the lines of:

struct B {
  template <typename Ty>
  B(Ty);
  B(int X) : B((float)X) {}
};

struct C {
  C(auto);
  C(int) : C("") {}
};
strimo378 added inline comments.Jul 11 2023, 8:41 AM
clang/test/AST/ast-print-method-decl.cpp
16

I fully agree to you that these test cases should also work but that goes beyond the scope of a "simple" delegating ctor output fix.

In the current implementation all implicitly specialized templates are output and therefore the generated code is not correct C++ anymore, see https://godbolt.org/z/34xaoYW5n . I think it is not a good idea to check for incorrect C++ code in a test case...

I am currently focusing to get non-templated C++ code output correctly. For methods e.g. there are many problems with the correct position of attributes. I will address that in one of my next merge request and I want to put all method related tests into ast-print-method-decl.cpp . Therefore, I would like to keep the name.

aaron.ballman added inline comments.Jul 11 2023, 11:27 AM
clang/test/AST/ast-print-method-decl.cpp
16

I fully agree to you that these test cases should also work but that goes beyond the scope of a "simple" delegating ctor output fix.

Ah, so this is exposing an already existing issue. In that case, let's add the tests and leave a FIXME comment to improve the behavior in the future (bonus points for filing an issue) so that it's clear we've noticed there's a problem rather than looking like an oversight in test coverage. This also ensures that those forms of delegation don't cause assertions or crashes despite being wrong.

I am currently focusing to get non-templated C++ code output correctly. For methods e.g. there are many problems with the correct position of attributes. I will address that in one of my next merge request and I want to put all method related tests into ast-print-method-decl.cpp . Therefore, I would like to keep the name.

Ah, if there's more functionality to be added to the test in the near future, the current name is fine by me.

strimo378 updated this revision to Diff 540627.Jul 14 2023, 8:14 PM

Updated test case

strimo378 marked 3 inline comments as done.Jul 20 2023, 2:32 AM

Ping

aaron.ballman accepted this revision.Jul 25 2023, 10:57 AM

LGTM! Do you need me to commit this on your behalf? (If you plan to do more patches, I'm also happy to let you ask for commit privileges [https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access] and land this yourself if you'd like.)

This revision is now accepted and ready to land.Jul 25 2023, 10:57 AM

I plan around half a dozen patches only for ast-print functionality. I would love to land it myself and will asked for commit privileges.

This revision was landed with ongoing or failed builds.Jul 26 2023, 2:30 AM
This revision was automatically updated to reflect the committed changes.