diff options
author | smanna12 <soumi.manna@intel.com> | 2024-06-29 11:32:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-29 13:32:39 -0500 |
commit | f7fec8c80a986e82ef174080a3e07703c7b2c3c6 (patch) | |
tree | f3edf47a733e4471fddeb48ceba915d2cac08cb3 /clang/lib/Sema | |
parent | 1791b11b7d94d33a37897163702f5bfeb9a26f12 (diff) | |
download | llvm-f7fec8c80a986e82ef174080a3e07703c7b2c3c6.zip llvm-f7fec8c80a986e82ef174080a3e07703c7b2c3c6.tar.gz llvm-f7fec8c80a986e82ef174080a3e07703c7b2c3c6.tar.bz2 |
[Clang] Prevent null pointer dereference in template deduction guide creation (#97097)
This patch addresses static analyzer concerns where `TSI` could be
dereferenced after being assigned a null value from `SubstType` in
`ConvertConstructorToDeductionGuideTransform()`.
The fixes now check null value of `TSI` after the call to `SubstType`
and return `nullptr` to prevent potential null pointer dereferences when
calling getTypeLoc() or getType() and ensure safe execution.
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index e36ee2d..9f4acbe 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -2513,6 +2513,9 @@ struct ConvertConstructorToDeductionGuideTransform { TSI = SemaRef.SubstType(TSI, OuterInstantiationArgs, Loc, DeductionGuideName); + if (!TSI) + return nullptr; + FunctionProtoTypeLoc FPTL = TSI->getTypeLoc().castAs<FunctionProtoTypeLoc>(); @@ -2523,6 +2526,9 @@ struct ConvertConstructorToDeductionGuideTransform { if (NestedPattern) TSI = SemaRef.SubstType(TSI, OuterInstantiationArgs, Loc, DeclarationName()); + if (!TSI) + return nullptr; + ParmVarDecl *NewParam = ParmVarDecl::Create(SemaRef.Context, DC, Loc, Loc, nullptr, TSI->getType(), TSI, SC_None, nullptr); |