@@ -1443,19 +1443,28 @@ void CallExpr::updateDependenciesFromArg(Expr *Arg) {
1443
1443
Decl *Expr::getReferencedDeclOfCallee () {
1444
1444
Expr *CEE = IgnoreParenImpCasts ();
1445
1445
1446
- while (SubstNonTypeTemplateParmExpr *NTTP
1447
- = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) {
1448
- CEE = NTTP->getReplacement ()->IgnoreParenCasts ();
1446
+ while (SubstNonTypeTemplateParmExpr *NTTP =
1447
+ dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) {
1448
+ CEE = NTTP->getReplacement ()->IgnoreParenImpCasts ();
1449
1449
}
1450
1450
1451
1451
// If we're calling a dereference, look at the pointer instead.
1452
- if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) {
1453
- if (BO->isPtrMemOp ())
1454
- CEE = BO->getRHS ()->IgnoreParenCasts ();
1455
- } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) {
1456
- if (UO->getOpcode () == UO_Deref)
1457
- CEE = UO->getSubExpr ()->IgnoreParenCasts ();
1452
+ while (true ) {
1453
+ if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) {
1454
+ if (BO->isPtrMemOp ()) {
1455
+ CEE = BO->getRHS ()->IgnoreParenImpCasts ();
1456
+ continue ;
1457
+ }
1458
+ } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) {
1459
+ if (UO->getOpcode () == UO_Deref || UO->getOpcode () == UO_AddrOf ||
1460
+ UO->getOpcode () == UO_Plus) {
1461
+ CEE = UO->getSubExpr ()->IgnoreParenImpCasts ();
1462
+ continue ;
1463
+ }
1464
+ }
1465
+ break ;
1458
1466
}
1467
+
1459
1468
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE))
1460
1469
return DRE->getDecl ();
1461
1470
if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE))
@@ -1466,28 +1475,11 @@ Decl *Expr::getReferencedDeclOfCallee() {
1466
1475
return nullptr ;
1467
1476
}
1468
1477
1469
- // / getBuiltinCallee - If this is a call to a builtin, return the builtin ID. If
1470
- // / not, return 0.
1478
+ // / If this is a call to a builtin, return the builtin ID. If not, return 0.
1471
1479
unsigned CallExpr::getBuiltinCallee () const {
1472
- // All simple function calls (e.g. func()) are implicitly cast to pointer to
1473
- // function. As a result, we try and obtain the DeclRefExpr from the
1474
- // ImplicitCastExpr.
1475
- const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee ());
1476
- if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
1477
- return 0 ;
1478
-
1479
- const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr ());
1480
- if (!DRE)
1481
- return 0 ;
1482
-
1483
- const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl ());
1484
- if (!FDecl)
1485
- return 0 ;
1486
-
1487
- if (!FDecl->getIdentifier ())
1488
- return 0 ;
1489
-
1490
- return FDecl->getBuiltinID ();
1480
+ auto *FDecl =
1481
+ dyn_cast_or_null<FunctionDecl>(getCallee ()->getReferencedDeclOfCallee ());
1482
+ return FDecl ? FDecl->getBuiltinID () : 0 ;
1491
1483
}
1492
1484
1493
1485
bool CallExpr::isUnevaluatedBuiltinCall (const ASTContext &Ctx) const {
0 commit comments