The ASTImporter was failing to import the SourceLocation field of Attrs. This adds a public API to import Attrs.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
This is unfinished. Posting to make you aware of the issue. There are other occurances of imported attrs without importing the srcloc in:
- VisitIndirectFieldDecl
- VisitAttributedStmt
So I was thinking this would suggest to add a public API ASTImporter::Import(Attr *). Does it make sense to add this? Is there anything else I need to do to change public API?
Merging of Attr would also be missing and I wouldn't know how to approach this.
Testing also added soon!
Hi all. I'm already here, invited by the Herald - just had no time to take a look (will change the script to add me as a reviewer). But thank you anyway! :)
In the initial implementation (https://raw.githubusercontent.com/haoNoQ/clang/summary-ipa-draft/lib/AST/ASTImporter.cpp), we already had this feature, and it was even called similarly - ImportAttributes(). But the centralized import inside Imported (or even `Import()?), as it is done in this patch, looks to be a better option to me.
I'm not sure that we have to "merge" attributes. Moreover, declarations with different attributes can be considered structurally different (possibly, in an another patch). But I can possibly be missing something so feel free to correct me.
Maybe this is a user error of CrossTU, but it seemed to import a FuncDecl with attributes, causing the imported FuncDecl to have all those attributes twice. That's why I thought merging would maybe make sense. However I did not encounter any issue with the duplicate attributes. Only the wrong source locations produced odd crashes.
Thanks for the input, then I will prepare the full patch.
Hi Rafael! Please find my comments inline.
lib/AST/ASTImporter.cpp | ||
---|---|---|
2650 ↗ | (On Diff #145486) | Could we just remove 'const' qualifier from A to avoid const_cast? (Same below) |
6547 ↗ | (On Diff #145486) | Is it possible to get into a situation where a nullptr attribute is imported? |
7211 ↗ | (On Diff #145486) | As I can see, Import(Attr *) can return nullptr. And I'm not sure that addAttr(nullptr) has well-defined behaviour. |
test/Import/attr/Inputs/S.cpp | ||
4 ↗ | (On Diff #145486) | Could you please clang-format the file? |
include/clang/AST/ASTImporter.h | ||
---|---|---|
137 ↗ | (On Diff #145486) | I tried to stay consistent with the other descriptions. Will be removed anyway (see below). |
lib/AST/ASTImporter.cpp | ||
2650 ↗ | (On Diff #145486) | I made the interface const instead. |
6547 ↗ | (On Diff #145486) | I looked at the Decl variant and thought it should act similarly, but as far as I can tell, null attributes should not exist. |