Skip to content

Commit 23b9848

Browse files
committed
Make code more recursive, add tests
1 parent 3dc5d78 commit 23b9848

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -469,20 +469,18 @@ struct TransferFunctions : public StmtVisitor<TransferFunctions> {
469469
}
470470

471471
void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *CE) {
472-
if (CE->getOperator() == OO_Call && CE->getNumArgs() > 0) {
473-
Expr *Obj = CE->getArg(0)->IgnoreParenCasts();
474-
if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(Obj))
475-
Obj = MTE->getSubExpr();
476-
if (auto *DRE = dyn_cast<DeclRefExpr>(Obj)) {
477-
auto *D = dyn_cast<VarDecl>(DRE->getDecl());
478-
if (D && D->hasInit())
479-
Obj = D->getInit();
480-
}
481-
Visit(Obj);
482-
}
472+
if (CE->getOperator() == OO_Call && CE->getNumArgs() > 0)
473+
Visit(CE->getArg(0)->IgnoreParenCasts());
483474
VisitCallExpr(CE);
484475
}
485476

477+
void VisitDeclRefExpr(DeclRefExpr *DRef) {
478+
if (auto *D = dyn_cast<VarDecl>(DRef->getDecl())) {
479+
if (D->hasInit())
480+
Visit(D->getInit());
481+
}
482+
}
483+
486484
void VisitLambdaExpr(LambdaExpr *LE) {
487485
for (const LambdaCapture &Capture : LE->captures())
488486
if (Capture.capturesVariable())

clang/test/SemaCXX/noreturn-vars.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,27 @@ extern void abc_02(func_type *);
272272
LF(func_ptr);
273273
func_ptr();
274274
}
275+
276+
[[noreturn]] void call_lambda_by_ptr(int x) {
277+
func_type func_ptr = noret;
278+
auto LF = [&func_ptr](){};
279+
auto LFPtr = &LF;
280+
(*LFPtr)();
281+
func_ptr();
282+
} // expected-warning {{function declared 'noreturn' should not return}}
283+
284+
[[noreturn]] void call_lambda_by_ptr_no_capture(int x) {
285+
func_type func_ptr = noret;
286+
auto LF = [](){};
287+
auto LFPtr = &LF;
288+
(*LFPtr)();
289+
func_ptr();
290+
}
291+
292+
[[noreturn]] void call_lambda_by_ptr_capture_value(int x) {
293+
func_type func_ptr = noret;
294+
auto LF = [func_ptr](){};
295+
auto LFPtr = &LF;
296+
(*LFPtr)();
297+
func_ptr();
298+
}

0 commit comments

Comments
 (0)