A new TypeLocImporter is created to import the TypeLoc values from
TypeSourceInfo. The previous "trivial TypeSourceInfo" is replaced.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
8109 | I think this should have a less-generic name for example TypeLocImporter_IMPORT. |
Finally, this FIXME is addressed. Thanks! Are you going to add any tests in the following patches?
It looks almost good to me, but I have a question inline.
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
8109 | IMPORT_TYPE_LOC_ELEMENT_OR_RETURN_ERROR. | |
8238 | Does this import interacts well with type loc import partially done at L3258 (VisitFunctionDecl)? Should we merge them? |
Are you going to add any tests in the following patches?
I don't have any tests for now, but in a later patch we can create them.
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
8238 | I think we should check here whether the given ParmVarDecl had been imported previously and if yes then set that with setParam, otherwise it could be set to a nullptr. @balazske what do you think? |
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
8238 | Probably we could get the FunctionTypeLoc from TInfo (this is the first TypeLoc there?) and set the parameters (that are set to nullptr at line 8055), at this loop in VisitFunctionDecl: // Set the parameters. for (auto *Param : Parameters) { Param->setOwningFunction(ToFunction); ToFunction->addDeclInternal(Param); } ToFunction->setParams(Parameters); |
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
8238 | Guys, I moved the TypeLoc import part of VisitFunctionDecl to here. But, this is possible only if first we import the parameters and only then we import the TypeLoc (TypeSourceInfo) in VisitFunctionDecl, so I made that reorganization too. |
- Move the setting of parameters of FunctionProtoTypeLoc to TypeLocImporter
- Add tests for TypeLoc import in case of functions
The patch looks good. Thanks! I would prefer to see more tests for other TypeLoc cases, but I think they could be added in the following patches.
@shafik Shafik, do you have any suggestions for this patch?
@teemperor , @shafik
Guys, could you please take a look on this patch? I don't think that type locations could have any effects on LLDB, but one may never know, so, it is better to have your review too.
Thanks!
A few comments and I would like @teemperor to give this a look as well but it looks good to me.
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
3281 | I am curious, why move this chunk of code up? | |
clang/unittests/AST/ASTImporterTest.cpp | ||
5850 | Maybe I am missing it but these tests don't seem like they cover all the visit methods of TypeLocImporter. |
My only problem is the reimplementation of the default visit methods with (from what I can tell) the same behavior as the default. If you delete all of these then that would also fix Shafik's point that all the custom dispatch code is technically untested in the unit test (I think not testing the dispatch code from the TypeLocVisitor is fine).
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
8133 | I know the ASTImporter is doing these reimplementation of the default visitor behavior quite often, but I feel in this case it would be much more readable to omit all these default implementations and just let the TypeLocVisitor do the dispatch to parent class logic. Especially since from what I understand it's unlikely that we need custom logic for all these TypeLoc subclasses in the future? It would also make this code less fragile in case the inheritance hierarchy every gets another intermediate class that might require special handling. |
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
3281 | See comments at line 8238? | |
clang/unittests/AST/ASTImporterTest.cpp | ||
5850 | It could be useful to add some kind of generic imported AST similarity tests. These can test for things that should match in the imported and original AST, for example source locations. |
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
8133 | It is really better to remove these redundant visit branches. |
Thanks guys for the review and the comments! :) I am going to address all of them, but only during next week, I am on vacation for the rest of this week.
- Remove default visit functions
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
3281 | I moved the TypeLoc import part of VisitFunctionDecl to VisitFunctionTypeLoc. But, that was possible only if first we import the parameters and only then we import the TypeLoc (TypeSourceInfo) in VisitFunctionDecl, so I made that reorganization here. | |
8133 | OK, indeed we don't need them. So, I removed these default implementations. | |
clang/unittests/AST/ASTImporterTest.cpp | ||
5850 | I added tests only for the non-trivial cases like FunctionTypeLoc, in that case we moved some code out from VisitFunctionDecl to the typeloc importer. All the other branches are very trivial and type loc import happens only in the type loc importer. So, I think it would be the best if we could test them in a generic way as @balazske suggests: we could extend the existing unittests to check for typelocations too. But that is not that trivial to do (may require another typeloc visitation in the test, I don't know yet). I'd rather do that in a separate patch, if that's okay. |
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
8132 | This assert is new related to the old code. Are really all TypeLoc's are implemented (probably analyze with CTU a large project)? |
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
8132 | Yeah, I am not going to commit this, until our full CI job is green on the change. That job analyzes Tmux, Redis, Curl, Xercex, Bitcoin and Protobuf and considered as a quite good coverage for the Analyzer. |
I realized that the mentioned functions are redundant, because we have a while loop which iterates over all related typelocs (getNextTypeLoc).
Also, it is better to remove the llvm_unreachable because there are many TypeLocs that we just don't handle, e.g. TypeOfExprTypeLoc.
I am curious, why move this chunk of code up?