Don't revisit the subexpressions of PseudoObjectExpr when building a
authorAkira Hatanaka <ahatanaka@apple.com>
Fri, 2 Dec 2022 19:41:09 +0000 (11:41 -0800)
committerAkira Hatanaka <ahatanaka@apple.com>
Fri, 2 Dec 2022 19:41:09 +0000 (11:41 -0800)
ParentMap

The assertion that is removed in this patch was failing when ObjC dot
notation expressions appear in both sides of an assignment (see the test
case in arc-repeated-weak.mm). Visit the PseudoObjectExpr once when the
syntactic expression is visited and return without visiting the
subexpressions when it's visited again when the semantic expressions are
visited.

Differential Revision: https://reviews.llvm.org/D139171

clang/lib/AST/ParentMap.cpp
clang/test/SemaObjC/arc-repeated-weak.mm

index da21e57..3d6a1cc 100644 (file)
@@ -33,9 +33,11 @@ static void BuildParentMap(MapTy& M, Stmt* S,
 
   switch (S->getStmtClass()) {
   case Stmt::PseudoObjectExprClass: {
-    assert(OVMode == OV_Transparent && "Should not appear alongside OVEs");
     PseudoObjectExpr *POE = cast<PseudoObjectExpr>(S);
 
+    if (OVMode == OV_Opaque && M[POE->getSyntacticForm()])
+      break;
+
     // If we are rebuilding the map, clear out any existing state.
     if (M[POE->getSyntacticForm()])
       for (Stmt *SubStmt : S->children())
index e9b4d1a..d23af8c 100644 (file)
@@ -290,6 +290,18 @@ void doWhileLoop(Test *a) {
   } while(0);
 }
 
+struct S {
+  int a;
+  id b;
+};
+
+@interface C
+@property S p;
+@end
+
+void test_list_init(C *c) {
+  c.p = {0, c.p.b};
+}
 
 @interface Test (Methods)
 @end