Skip to content

Commit a63c9b2

Browse files
committed
Do not pass null attributes to BuildAttributedStmt during instantiation
When transforming an attribute during template instantiation, if the transformation fails, it may result in a null attribute being returned. This null attribute should not be passed in as one of the attributes used to create an attributed statement. If all of the attributes fail to transform, we do not create an attributed statement at all. There are no attributes that return null currently, so there is no easy way to test this currently. However, this fixes a crash caused by 8344675.
1 parent fa404ae commit a63c9b2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

clang/lib/Sema/TreeTransform.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7325,7 +7325,8 @@ TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S,
73257325
for (const auto *I : S->getAttrs()) {
73267326
const Attr *R = getDerived().TransformAttr(I);
73277327
AttrsChanged |= (I != R);
7328-
Attrs.push_back(R);
7328+
if (R)
7329+
Attrs.push_back(R);
73297330
}
73307331

73317332
StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
@@ -7335,6 +7336,11 @@ TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S,
73357336
if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
73367337
return S;
73377338

7339+
// If transforming the attributes failed for all of the attributes in the
7340+
// statement, don't make an AttributedStmt without attributes.
7341+
if (Attrs.empty())
7342+
return SubStmt;
7343+
73387344
return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
73397345
SubStmt.get());
73407346
}

0 commit comments

Comments
 (0)