The ASTImporter was failing to import the SourceLocation field of Attrs. This adds a public API to import Attrs.
Details
Diff Detail
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 | Could we just remove 'const' qualifier from A to avoid const_cast? (Same below) | |
6541 | Is it possible to get into a situation where a nullptr attribute is imported? | |
7201–7202 | 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 | ||
5 | Could you please clang-format the file? |
include/clang/AST/ASTImporter.h | ||
---|---|---|
137 | I tried to stay consistent with the other descriptions. Will be removed anyway (see below). | |
lib/AST/ASTImporter.cpp | ||
2650 | I made the interface const instead. | |
6541 | I looked at the Decl variant and thought it should act similarly, but as far as I can tell, null attributes should not exist. |
nullptr