[clang] a63c9b2 - Do not pass null attributes to BuildAttributedStmt during instantiation

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 21 06:31:06 PDT 2021


Author: Aaron Ballman
Date: 2021-04-21T09:30:56-04:00
New Revision: a63c9b25620c8a4da9fcf1e1e8535d3110819ec0

URL: https://github.com/llvm/llvm-project/commit/a63c9b25620c8a4da9fcf1e1e8535d3110819ec0
DIFF: https://github.com/llvm/llvm-project/commit/a63c9b25620c8a4da9fcf1e1e8535d3110819ec0.diff

LOG: 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
8344675908424ee532d4ae30e5043c5a5834e02c.

Added: 
    

Modified: 
    clang/lib/Sema/TreeTransform.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index ee661f0fc1ab..5a2013bd53a7 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7325,7 +7325,8 @@ TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S,
   for (const auto *I : S->getAttrs()) {
     const Attr *R = getDerived().TransformAttr(I);
     AttrsChanged |= (I != R);
-    Attrs.push_back(R);
+    if (R)
+      Attrs.push_back(R);
   }
 
   StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
@@ -7335,6 +7336,11 @@ TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S,
   if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
     return S;
 
+  // If transforming the attributes failed for all of the attributes in the
+  // statement, don't make an AttributedStmt without attributes.
+  if (Attrs.empty())
+    return SubStmt;
+
   return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
                                             SubStmt.get());
 }


        


More information about the cfe-commits mailing list