}
static bool isGLValueFromPointerDeref(const Expr *E) {
- E = E->IgnoreParenCasts();
+ E = E->IgnoreParens();
- if (isa<ArraySubscriptExpr>(E))
- return true;
-
- if (const auto *UO = dyn_cast<UnaryOperator>(E))
- if (UO->getOpcode() == UO_Deref)
- return true;
+ if (const auto *CE = dyn_cast<CastExpr>(E)) {
+ if (!CE->getSubExpr()->isGLValue())
+ return false;
+ return isGLValueFromPointerDeref(CE->getSubExpr());
+ }
if (const auto *BO = dyn_cast<BinaryOperator>(E))
if (BO->getOpcode() == BO_Comma)
return isGLValueFromPointerDeref(OVE->getSourceExpr()) ||
isGLValueFromPointerDeref(BCO->getFalseExpr());
+ // C++11 [expr.sub]p1:
+ // The expression E1[E2] is identical (by definition) to *((E1)+(E2))
+ if (isa<ArraySubscriptExpr>(E))
+ return true;
+
+ if (const auto *UO = dyn_cast<UnaryOperator>(E))
+ if (UO->getOpcode() == UO_Deref)
+ return true;
+
return false;
}
// CHECK-LABEL: define void @_Z2f9P1A
// CHECK: icmp eq {{.*}}, null
// CHECK-NEXT: br i1
+
+void f10(A *x) { typeid((const A &)(A)*x); }
+// CHECK-LABEL: define void @_Z3f10P1A
+// CHECK-NOT: icmp eq {{.*}}, null