Clang currently picks the second tentative definition when
VarDecl::getActingDefinition is called. This can lead to attributes
being dropped if they are attached to tentative definitions that
appear after the second one. This is because
VarDecl::getActingDefinition loops through VarDecl::redecls assuming
that the last tentative definition is the last element in the
iterator. However, it is the second element that would be the last
tentative definition. This changeset modifies getActingDefinition to
iterate through the declaration chain in reverse, so that it can
immediately return when it encounters a tentative definition.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks, this makes sense.
clang/lib/AST/Decl.cpp | ||
---|---|---|
2215 | Is there a good reason to switch from checking for a Definition in the loop to checking it ahead of time? This change means we'll do two passes over the redeclarations, and call isThisDeclarationADefinition twice for each, where the old approach only performed one pass. |
Removed extra pass over decl chain for acting definition.
clang/lib/AST/Decl.cpp | ||
---|---|---|
2215 | My thought was that separating the logic would make the loop easier to read, but I see that this causes 2 passes vs. 1. |
@mizvekov Thanks for the help! I recently got commit access, so I think I can commit this myself.
This breaks tests on macOS: http://45.33.8.238/macm1/16663/step_7.txt
Please to a look. Just adding a -triple flag is probably sufficient.
Is there a good reason to switch from checking for a Definition in the loop to checking it ahead of time? This change means we'll do two passes over the redeclarations, and call isThisDeclarationADefinition twice for each, where the old approach only performed one pass.