[clang] Reland: [clang] Track function template instantiation from definition (PR #125266)
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 3 14:59:36 PST 2025
================
@@ -2298,6 +2298,13 @@ class FunctionDecl : public DeclaratorDecl,
FunctionDeclBits.IsLateTemplateParsed = ILT;
}
+ bool isInstantiatedFromMemberTemplate() const {
+ return FunctionDeclBits.IsInstantiatedFromMemberTemplate;
+ }
+ void setInstantiatedFromMemberTemplate(bool Val = true) {
+ FunctionDeclBits.IsInstantiatedFromMemberTemplate = Val;
+ }
+
----------------
mizvekov wrote:
Yes, one possibility would be to move the `InstantiatedFromMemberTemplate` field from the common area into the redeclarable.
This would also increase source representation accuracy, as we would be able to point to the exact template redeclaration for each instantiated redeclaration, but it would waste one pointer per Redeclarable. The Function is the only part which really requires the extra information for correctness reasons.
We could on a follow up consider that change, but it would have to stand on its own against the costs, without relying on the bug fix to make it worthwhile.
> However, why is FunctionDecl::getInstantiatedFromDecl / FunctionDecl::getMemberSpecializationInfo not what we want?
These are for different things. `getInstantiatedFromDecl` is used to tell which function this "was instantiated from, if this is a function declaration declared locally inside of a function template".
`getMemberSpecializationInfo` is info for member functions, but friends are not members.
> If we can't use that, why are we storing a bit in FunctionDecl and not in FunctionTemplateSpecializationInfo for example?
Because FunctionDecl has free bits, so this change has basically no space cost :)
https://github.com/llvm/llvm-project/pull/125266
More information about the cfe-commits
mailing list