Skip to content

Commit 99d7ea0

Browse files
committed
[CFG] Ignore parens in CXXDefaultArgExpr when build CFG
Signed-off-by: yronglin <[email protected]>
1 parent 092af69 commit 99d7ea0

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

clang/lib/Analysis/CFG.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2447,7 +2447,7 @@ CFGBlock *CFGBuilder::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Arg,
24472447
autoCreateBlock();
24482448
appendStmt(Block, Arg);
24492449
}
2450-
return VisitStmt(Arg->getExpr(), asc);
2450+
return VisitStmt(Arg->getExpr()->IgnoreParens(), asc);
24512451
}
24522452

24532453
// We can't add the default argument if it's not rewritten because the
@@ -2464,6 +2464,10 @@ CFGBlock *CFGBuilder::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Init,
24642464
autoCreateBlock();
24652465
appendStmt(Block, Init);
24662466
}
2467+
2468+
// Unlike CXXDefaultArgExpr::getExpr stripped off the top level FullExpr and
2469+
// ConstantExpr, CXXDefaultInitExpr::getExpr does not do this, so we don't
2470+
// need to ignore ParenExprs, because the top level will not be a ParenExpr.
24672471
return VisitStmt(Init->getExpr(), asc);
24682472
}
24692473

clang/test/SemaCXX/warn-unreachable.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,39 @@ int f(int a) {
453453
A{}; // expected-warning {{will never be executed}}
454454
}
455455
} // namespace test_rebuilt_default_init
456+
457+
// This issue reported by the comments in https://github.com/llvm/llvm-project/pull/117437.
458+
// All block-level expressions should have already been IgnoreParens()ed.
459+
namespace gh117437_ignore_parens_in_default_arg {
460+
class Location {
461+
public:
462+
static Location Current(int = __builtin_LINE());
463+
};
464+
class DOMMatrix;
465+
class BasicMember {
466+
public:
467+
BasicMember(DOMMatrix *);
468+
};
469+
template <typename> using Member = BasicMember;
470+
class ExceptionState {
471+
public:
472+
ExceptionState &ReturnThis();
473+
ExceptionState(Location);
474+
};
475+
class NonThrowableExceptionState : public ExceptionState {
476+
public:
477+
NonThrowableExceptionState(Location location = Location::Current())
478+
: ExceptionState(location) {}
479+
};
480+
class DOMMatrix {
481+
public:
482+
static DOMMatrix *
483+
Create(int *, ExceptionState & = (NonThrowableExceptionState().ReturnThis()));
484+
};
485+
class CSSMatrixComponent {
486+
int CSSMatrixComponent_matrix;
487+
CSSMatrixComponent()
488+
: matrix_(DOMMatrix::Create(&CSSMatrixComponent_matrix)) {}
489+
Member<DOMMatrix> matrix_;
490+
};
491+
} // namespace gh117437_ignore_parens_in_default_arg

0 commit comments

Comments
 (0)