This is an archive of the discontinued LLVM Phabricator instance.

[astimporter] Support importing CXXDependentScopeMemberExpr and FunctionTemplateDecl
Needs RevisionPublic

Authored by khazem on Nov 21 2016, 1:22 AM.

Details

Reviewers
spyffe
a.sidorin
Summary

This patch adds support for importing two different kinds of AST nodes. The patch also adds an AST Matcher for cxxDependentScopeMemberExpr to support the addition of three new unit tests.

This fixes an issue where Clang would error out with "Unsupported AST node..." when attempting to import programs containing these nodes.

Diff Detail

Event Timeline

khazem updated this revision to Diff 78691.Nov 21 2016, 1:22 AM
khazem retitled this revision from to [astimporter] Support importing CXXDependentScopeMemberExpr and FunctionTemplateDecl.
khazem updated this object.
khazem added reviewers: spyffe, a.sidorin.
khazem added subscribers: phosek, seanklein.
a.sidorin requested changes to this revision.Nov 23 2016, 1:30 AM
a.sidorin edited edge metadata.
a.sidorin added a subscriber: aaron.ballman.

Hello Kareem,
Thank you for working on it! You can find my comments below.

include/clang/ASTMatchers/ASTMatchers.h
5459

I'd prefer to have a discussion with ASTMatcher developers (@aaron.ballman, @klimek) first. Maybe it is better to place this matcher into ASTImporterTest.cpp - as I understand, it will be used very rarely.

lib/AST/ASTImporter.cpp
3495

If DC is nullptr, we should return on the previous line - ImportDeclParts returns true in this case. We may turn it into an assertion, however.

3509

Seems like we don't attempt to lookup an existing declaration first. This may lead to appearance of multiple definitions of same decl. I'd also prefer to see a functional test for this in test/ASTMerge.

You can also refer to https://github.com/haoNoQ/clang/blob/summary-ipa-draft/lib/AST/ASTImporter.cpp#L3594 because some important parts (setting of lexical decl context, adding a decl to the imported map) are missed here.

This revision now requires changes to proceed.Nov 23 2016, 1:30 AM
khazem updated this revision to Diff 79371.Nov 27 2016, 9:44 PM
khazem edited edge metadata.

Thanks for the comments, Aleksei!

I've merged some aspects of the code you pointed me to, although I had to change some of it because some of the function calls have changed since 2015. In particular, I'm checking for already-imported functions, and adding the decl to the imported map.

I'm not sure how to proceed with tests. I was looking at test/ASTMerge/class-template-partial-spec.cpp, would it be something like this?

But I'm not sure what error I should throw if we have already imported the function, there is no appropriate error in include/clang/Basic/DiagnosticASTKinds.td. Should I define a new error, e.g. "function %0 defined in multiple translation units"?

Hello Kareem.

There are some tests in "class-template" dir that may serve as example. You don't need a warning for a function that was found: you should just return found declaration. There is already a warning for a declaration that is defined in multiple TUs. You can run these tests to see them.

spyffe requested changes to this revision.Nov 28 2016, 1:40 PM
spyffe edited edge metadata.

There are several missing imports here, as well as a few minor nits.
If the unit test cases aren't catching these, I'm a little concerned. We should be catching this.
Also we should definitely test that bodies of function templates (in particular, bodies that use the template arguments) get imported properly.

lib/AST/ASTImporter.cpp
2327

Would

for (Attr *A : From->atrs()) {

work in this case?

3564

You didn't import TemplatedFD before installing it in ToFunc. This code is broken, and we should make sure the unit tests know to catch these cases.

6482

You're installing Base and BaseType without importing them, as well as all the Locs.

This revision now requires changes to proceed.Nov 28 2016, 1:40 PM
dkrupp added a subscriber: dkrupp.Jul 17 2017, 4:32 AM