Skip to content

Commit c269182

Browse files
authored
[lldb][TypeSystemClang] Initialize ClassTemplateSpecializationDecl'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.
1 parent 98e118c commit c269182

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clang/include/clang/AST/DeclTemplate.h

+2
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,8 @@ class ClassTemplateSpecializationDecl : public CXXRecordDecl,
19601960

19611961
bool hasStrictPackMatch() const { return StrictPackMatch; }
19621962

1963+
void setStrictPackMatch(bool Val) { StrictPackMatch = Val; }
1964+
19631965
/// Get the point of instantiation (if any), or null if none.
19641966
SourceLocation getPointOfInstantiation() const {
19651967
return PointOfInstantiation;

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,12 @@ TypeSystemClang::CreateClassTemplateSpecializationDecl(
16661666
ast.getTypeDeclType(class_template_specialization_decl, nullptr);
16671667
class_template_specialization_decl->setDeclName(
16681668
class_template_decl->getDeclName());
1669+
1670+
// FIXME: set to fixed value for now so it's not uninitialized.
1671+
// One way to determine StrictPackMatch would be
1672+
// Sema::CheckTemplateTemplateArgument.
1673+
class_template_specialization_decl->setStrictPackMatch(false);
1674+
16691675
SetOwningModule(class_template_specialization_decl, owning_module);
16701676
decl_ctx->addDecl(class_template_specialization_decl);
16711677

0 commit comments

Comments
 (0)