File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -130,6 +130,16 @@ bool IsInMainFile(const clang::Decl *decl) {
130130 return src_mgr.isInMainFile (src_mgr.getExpansionLoc (loc));
131131}
132132
133+ bool IsUnionArrayMember (const clang::Expr *base) {
134+ if (auto *me =
135+ clang::dyn_cast<clang::MemberExpr>(base->IgnoreParenImpCasts ())) {
136+ if (auto *fd = clang::dyn_cast<clang::FieldDecl>(me->getMemberDecl ())) {
137+ return fd->getParent ()->isUnion () && fd->getType ()->isArrayType ();
138+ }
139+ }
140+ return false ;
141+ }
142+
133143bool IsUserDefinedDecl (const clang::Decl *decl) {
134144 const auto &ctx = decl->getASTContext ();
135145 const auto &src_mgr = ctx.getSourceManager ();
Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ bool IsComparisonWithNullOp(const clang::BinaryOperator *expr);
4040
4141bool IsInMainFile (const clang::Decl *decl);
4242
43+ bool IsUnionArrayMember (const clang::Expr *base);
44+
4345bool IsUserDefinedDecl (const clang::Decl *decl);
4446
4547bool RefersToUserDefinedDecl (const clang::Expr *expr);
Original file line number Diff line number Diff line change @@ -378,7 +378,8 @@ std::string ConverterRefCount::ConvertPtrType(clang::QualType type) {
378378bool ConverterRefCount::VisitArraySubscriptExpr (
379379 clang::ArraySubscriptExpr *expr) {
380380 auto *base = expr->getBase ();
381- if (base->IgnoreCasts ()->getType ()->isPointerType ()) {
381+ if (base->IgnoreCasts ()->getType ()->isPointerType () ||
382+ (isLValue () && IsUnionArrayMember (base))) {
382383 ConvertPointerSubscript (expr);
383384 } else {
384385 if (!base->IgnoreCasts ()->getType ()->isArrayType ()) {
You can’t perform that action at this time.
0 commit comments