[all-commits] [llvm/llvm-project] 0b553e: [Clang] Fix missed initializer instantiation bug f...

dty2 via All-commits all-commits at lists.llvm.org
Sun May 18 03:42:28 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0b553e055ad01ca6a2c88f7da92157df29e42fd0
      https://github.com/llvm/llvm-project/commit/0b553e055ad01ca6a2c88f7da92157df29e42fd0
  Author: dty2 <118413413+dty2 at users.noreply.github.com>
  Date:   2025-05-18 (Sun, 18 May 2025)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
    M clang/test/CodeGenCXX/cxx1z-inline-variables.cpp
    M clang/test/SemaTemplate/cxx17-inline-variables.cpp

  Log Message:
  -----------
  [Clang] Fix missed initializer instantiation bug for variable templates (#138122)

Fixes https://github.com/llvm/llvm-project/issues/135032

Due to nested templates, when instantiating the outer layer (the
template class), the inner layer (the template variable) uses delayed
instantiation.
This causes the declaration (VarDecl) of the template variable to retain
the type from the original template declaration (i.e., auto), and it
loses the initializer.
Later, when instantiating the template variable, its
VarTemplateSpecializationDecl type depends on the VarDecl type.
Thus, the VarTemplateSpecializationDecl also has no initializer, and its
type remains auto.
Ultimately, when building the reference expression in
Sema::BuildDeclarationNameExpr, the expression's type is auto and stays
as auto until code generation, triggering llvm_unreachable in
CodeGenTypes::ConvertType.

Since I noticed that the deduction of auto type is caused by the
initializer
I plan to do special processing for template variables of type auto,
that is, to prevent their delayed instantiation
so that their initializers will not be lost when the outer template
class is instantiated



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list