Patch represents the clang part of changes in D143347
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
3900 | I am not familiar with this use case, is there a path where the attributes are read from a FieldDecl before return from VisitFieldDecl? Probably ImportImpl is overridden? Importing the attributes here should work but not totally sure if it does not cause problems. Problematic case is if the attribute has pointer to a Decl or Type that is imported here in a state when the field is already created but not initialized. Another problem is that attributes are added a second time in Import(Decl *). Can it work if the ImportAttrs is made a protected function and called from (overridden) ImportImpl (still there can be a second import in Import(Decl *)? | |
clang/unittests/AST/ASTImporterTest.cpp | ||
8161 | ||
8164 | ||
8165 | Does this test fail without the changes applied? And does it not fail after (is the "Empty" value copied at import)? |
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
3900 | The problem is that field attributes are required when we are adding a copy of a field to a structure in VisitFieldDecl. Attributes themselves are read in CXXRecordDecl::addedMember (see the call to isZeroSize). Adding them after ImportImpl is called is too late: record is already marked as non-empty. |
clang/unittests/AST/ASTImporterTest.cpp | ||
---|---|---|
8165 | Yes the tests will fail due to above mentioned problem with field attributes |
clang/lib/AST/ASTImporter.cpp | ||
---|---|---|
3900 | I understand now. But a comment could be added here to explain why the attribute import is needed here. | |
8991 | Should use braces in this case (https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements). |
clang/include/clang/AST/DeclCXX.h | ||
---|---|---|
1171 | This change looks not related. |
clang/include/clang/AST/DeclCXX.h | ||
---|---|---|
1171 | The markEmpty is still needed and is used in corresponding unit tests. It's gonna be used in DWARFASTParserClang to mark records with empty fields as having zero size. Then by copying attributes in ASTImporter we prevent this empty mark to be overwritten |
There are some unresolved comments in the test (cast is not needed at Import and EXPECT_TRUE can be used) but otherwise LGTM.
(But I have a feeling that problems may happen with attributes like GuardedByAttr if these are imported before the field is added to the record. Probably it is better to only import the NoUniqueAddressAttr in VisitFieldDecl.)
This change looks not related.