Skip to content

Commit

Permalink
Automerge: [lldb][TypeSystemClang] Initialize ClassTemplateSpecializa…
Browse files Browse the repository at this point in the history
…tionDecl's StrictPackMatch field (#126215)

This addresses the MSAN failure reported
in
llvm/llvm-project#125791 (comment):
```
==5633==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 in clang::ASTNodeImporter::CallOverloadedCreateFun<clang::ClassTemplateSpecializationDecl>::operator()
    #1 in bool clang::ASTNodeImporter::GetImportedOrCreateSpecialDecl<...>
...
```

The ASTImporter reads `D->hasStrictPackMatch()` and forwards it to the
constructor of the destination `ClassTemplateSpecializationDecl`. But if
`D` is a decl that LLDB created from debug-info, it would've been
created using `ClassTemplateSpecializationDecl::CreateDeserialized`,
which doesn't initialize the `StrictPackMatch` field.

This patch just initializes the field to a fixed value of `false`, to
preserve previous behaviour and avoid the use-of-uninitialized-value.

An alternative would be to always initialize it in the
`ClassTemplateSpecializationDecl` constructor, but there were
reservations about providing a default value for it because it might
lead to hard-to-diagnose problems down the line.
  • Loading branch information
Michael137 authored and github-actions[bot] committed Feb 7, 2025
2 parents ef9cb5e + c269182 commit c95311a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/AST/DeclTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,8 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,

bool hasStrictPackMatch() const { return StrictPackMatch; }

void setStrictPackMatch(bool Val) { StrictPackMatch = Val; }

/// Get the point of instantiation (if any), or null if none.
SourceLocation getPointOfInstantiation() const {
return PointOfInstantiation;
Expand Down
6 changes: 6 additions & 0 deletions lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,12 @@ TypeSystemClang::CreateClassTemplateSpecializationDecl(
ast.getTypeDeclType(class_template_specialization_decl, nullptr);
class_template_specialization_decl->setDeclName(
class_template_decl->getDeclName());

// FIXME: set to fixed value for now so it's not uninitialized.
// One way to determine StrictPackMatch would be
// Sema::CheckTemplateTemplateArgument.
class_template_specialization_decl->setStrictPackMatch(false);

SetOwningModule(class_template_specialization_decl, owning_module);
decl_ctx->addDecl(class_template_specialization_decl);

Expand Down

0 comments on commit c95311a

Please sign in to comment.