Skip to content

Commit 1c63984

Browse files
committed
Fix the bug which causes the SmallVector to be not so small.
PackDeductionScope::PackDeductionScope calls PackDeductionScope::addPack, which might not assign a value to PackDeductionScope::FixedNumExpansions given that getExpandedPackSize returns a nullopt. Access to an empty std::optional via the operator* is UB, and there is a case where IsExpanded is true while FixedNumberExpansions is empty. We access the empty optional, and this value is eventually used to in a call to SmallVector::reserve, which ends up trying to reserve 137 gigs of space and crashes clangd/clang++
1 parent fad3752 commit 1c63984

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ class PackDeductionScope {
831831
if (IsPartiallyExpanded)
832832
PackElements += NumPartialPackArgs;
833833
else if (IsExpanded)
834-
PackElements += *FixedNumExpansions;
834+
PackElements += FixedNumExpansions.value_or(1);
835835

836836
for (auto &Pack : Packs) {
837837
if (Info.PendingDeducedPacks.size() > Pack.Index)

0 commit comments

Comments
 (0)