Coverage Report

Created: 2021-01-23 06:44

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/AST/Expr.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- Expr.cpp - Expression AST Node Implementation --------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements the Expr class and subclasses.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/AST/Expr.h"
14
#include "clang/AST/APValue.h"
15
#include "clang/AST/ASTContext.h"
16
#include "clang/AST/Attr.h"
17
#include "clang/AST/ComputeDependence.h"
18
#include "clang/AST/DeclCXX.h"
19
#include "clang/AST/DeclObjC.h"
20
#include "clang/AST/DeclTemplate.h"
21
#include "clang/AST/DependenceFlags.h"
22
#include "clang/AST/EvaluatedExprVisitor.h"
23
#include "clang/AST/ExprCXX.h"
24
#include "clang/AST/IgnoreExpr.h"
25
#include "clang/AST/Mangle.h"
26
#include "clang/AST/RecordLayout.h"
27
#include "clang/AST/StmtVisitor.h"
28
#include "clang/Basic/Builtins.h"
29
#include "clang/Basic/CharInfo.h"
30
#include "clang/Basic/SourceManager.h"
31
#include "clang/Basic/TargetInfo.h"
32
#include "clang/Lex/Lexer.h"
33
#include "clang/Lex/LiteralSupport.h"
34
#include "llvm/Support/ErrorHandling.h"
35
#include "llvm/Support/raw_ostream.h"
36
#include <algorithm>
37
#include <cstring>
38
using namespace clang;
39
40
32.3k
const Expr *Expr::getBestDynamicClassTypeExpr() const {
41
32.3k
  const Expr *E = this;
42
32.7k
  while (true) {
43
32.7k
    E = E->IgnoreParenBaseCasts();
44
45
    // Follow the RHS of a comma operator.
46
32.7k
    if (auto *BO = dyn_cast<BinaryOperator>(E)) {
47
60
      if (BO->getOpcode() == BO_Comma) {
48
18
        E = BO->getRHS();
49
18
        continue;
50
18
      }
51
32.6k
    }
52
53
    // Step into initializer for materialized temporaries.
54
32.6k
    if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) {
55
290
      E = MTE->getSubExpr();
56
290
      continue;
57
290
    }
58
59
32.3k
    break;
60
32.3k
  }
61
62
32.3k
  return E;
63
32.3k
}
64
65
18.1k
const CXXRecordDecl *Expr::getBestDynamicClassType() const {
66
18.1k
  const Expr *E = getBestDynamicClassTypeExpr();
67
18.1k
  QualType DerivedType = E->getType();
68
18.1k
  if (const PointerType *PTy = DerivedType->getAs<PointerType>())
69
12.5k
    DerivedType = PTy->getPointeeType();
70
71
18.1k
  if (DerivedType->isDependentType())
72
4.09k
    return nullptr;
73
74
14.0k
  const RecordType *Ty = DerivedType->castAs<RecordType>();
75
14.0k
  Decl *D = Ty->getDecl();
76
14.0k
  return cast<CXXRecordDecl>(D);
77
14.0k
}
78
79
const Expr *Expr::skipRValueSubobjectAdjustments(
80
    SmallVectorImpl<const Expr *> &CommaLHSs,
81
9.31M
    SmallVectorImpl<SubobjectAdjustment> &Adjustments) const {
82
9.31M
  const Expr *E = this;
83
9.65M
  while (true) {
84
9.65M
    E = E->IgnoreParens();
85
86
9.65M
    if (const CastExpr *CE = dyn_cast<CastExpr>(E)) {
87
3.76M
      if ((CE->getCastKind() == CK_DerivedToBase ||
88
3.76M
           CE->getCastKind() == CK_UncheckedDerivedToBase) &&
89
3.72k
          E->getType()->isRecordType()) {
90
3.12k
        E = CE->getSubExpr();
91
3.12k
        auto *Derived =
92
3.12k
            cast<CXXRecordDecl>(E->getType()->castAs<RecordType>()->getDecl());
93
3.12k
        Adjustments.push_back(SubobjectAdjustment(CE, Derived));
94
3.12k
        continue;
95
3.12k
      }
96
97
3.76M
      if (CE->getCastKind() == CK_NoOp) {
98
279k
        E = CE->getSubExpr();
99
279k
        continue;
100
279k
      }
101
5.88M
    } else if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
102
109k
      if (!ME->isArrow()) {
103
51.1k
        assert(ME->getBase()->getType()->isRecordType());
104
51.1k
        if (FieldDecl *Field = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
105
50.8k
          if (!Field->isBitField() && 
!Field->getType()->isReferenceType()50.5k
) {
106
49.5k
            E = ME->getBase();
107
49.5k
            Adjustments.push_back(SubobjectAdjustment(Field));
108
49.5k
            continue;
109
49.5k
          }
110
5.77M
        }
111
51.1k
      }
112
5.77M
    } else if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
113
619k
      if (BO->getOpcode() == BO_PtrMemD) {
114
110
        assert(BO->getRHS()->isRValue());
115
110
        E = BO->getLHS();
116
110
        const MemberPointerType *MPT =
117
110
          BO->getRHS()->getType()->getAs<MemberPointerType>();
118
110
        Adjustments.push_back(SubobjectAdjustment(MPT, BO->getRHS()));
119
110
        continue;
120
619k
      } else if (BO->getOpcode() == BO_Comma) {
121
4.24k
        CommaLHSs.push_back(BO->getLHS());
122
4.24k
        E = BO->getRHS();
123
4.24k
        continue;
124
4.24k
      }
125
9.31M
    }
126
127
    // Nothing changed.
128
9.31M
    break;
129
9.31M
  }
130
9.31M
  return E;
131
9.31M
}
132
133
356k
bool Expr::isKnownToHaveBooleanValue(bool Semantic) const {
134
356k
  const Expr *E = IgnoreParens();
135
136
  // If this value has _Bool type, it is obvious 0/1.
137
356k
  if (E->getType()->isBooleanType()) 
return true454
;
138
  // If this is a non-scalar-integer type, we don't care enough to try.
139
355k
  if (!E->getType()->isIntegralOrEnumerationType()) 
return false26.1k
;
140
141
329k
  if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) {
142
4.58k
    switch (UO->getOpcode()) {
143
2
    case UO_Plus:
144
2
      return UO->getSubExpr()->isKnownToHaveBooleanValue(Semantic);
145
118
    case UO_LNot:
146
118
      return true;
147
4.46k
    default:
148
4.46k
      return false;
149
325k
    }
150
325k
  }
151
152
  // Only look through implicit casts.  If the user writes
153
  // '(int) (a && b)' treat it as an arbitrary int.
154
  // FIXME: Should we look through any cast expression in !Semantic mode?
155
325k
  if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
156
59.0k
    return CE->getSubExpr()->isKnownToHaveBooleanValue(Semantic);
157
158
266k
  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
159
9.45k
    switch (BO->getOpcode()) {
160
3.54k
    default: return false;
161
50
    case BO_LT:   // Relational operators.
162
58
    case BO_GT:
163
58
    case BO_LE:
164
59
    case BO_GE:
165
76
    case BO_EQ:   // Equality operators.
166
77
    case BO_NE:
167
627
    case BO_LAnd: // AND operator.
168
659
    case BO_LOr:  // Logical OR operator.
169
659
      return true;
170
171
4.81k
    case BO_And:  // Bitwise AND operator.
172
4.82k
    case BO_Xor:  // Bitwise XOR operator.
173
4.88k
    case BO_Or:   // Bitwise OR operator.
174
      // Handle things like (x==2)|(y==12).
175
4.88k
      return BO->getLHS()->isKnownToHaveBooleanValue(Semantic) &&
176
0
             BO->getRHS()->isKnownToHaveBooleanValue(Semantic);
177
178
21
    case BO_Comma:
179
377
    case BO_Assign:
180
377
      return BO->getRHS()->isKnownToHaveBooleanValue(Semantic);
181
256k
    }
182
256k
  }
183
184
256k
  if (const ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E))
185
0
    return CO->getTrueExpr()->isKnownToHaveBooleanValue(Semantic) &&
186
0
           CO->getFalseExpr()->isKnownToHaveBooleanValue(Semantic);
187
188
256k
  if (isa<ObjCBoolLiteralExpr>(E))
189
1
    return true;
190
191
256k
  if (const auto *OVE = dyn_cast<OpaqueValueExpr>(E))
192
0
    return OVE->getSourceExpr()->isKnownToHaveBooleanValue(Semantic);
193
194
256k
  if (const FieldDecl *FD = E->getSourceBitField())
195
802
    if (!Semantic && 
FD->getType()->isUnsignedIntegerType()26
&&
196
22
        !FD->getBitWidth()->isValueDependent() &&
197
22
        FD->getBitWidthValue(FD->getASTContext()) == 1)
198
11
      return true;
199
200
256k
  return false;
201
256k
}
202
203
// Amusing macro metaprogramming hack: check whether a class provides
204
// a more specific implementation of getExprLoc().
205
//
206
// See also Stmt.cpp:{getBeginLoc(),getEndLoc()}.
207
namespace {
208
  /// This implementation is used when a class provides a custom
209
  /// implementation of getExprLoc.
210
  template <class E, class T>
211
  SourceLocation getExprLocImpl(const Expr *expr,
212
18.0M
                                SourceLocation (T::*v)() const) {
213
18.0M
    return static_cast<const E*>(expr)->getExprLoc();
214
18.0M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ArraySubscriptExpr, clang::ArraySubscriptExpr>(clang::Expr const*, clang::SourceLocation (clang::ArraySubscriptExpr::*)() const)
Line
Count
Source
212
514k
                                SourceLocation (T::*v)() const) {
213
514k
    return static_cast<const E*>(expr)->getExprLoc();
214
514k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::BinaryOperator, clang::BinaryOperator>(clang::Expr const*, clang::SourceLocation (clang::BinaryOperator::*)() const)
Line
Count
Source
212
9.87M
                                SourceLocation (T::*v)() const) {
213
9.87M
    return static_cast<const E*>(expr)->getExprLoc();
214
9.87M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CompoundAssignOperator, clang::BinaryOperator>(clang::Expr const*, clang::SourceLocation (clang::BinaryOperator::*)() const)
Line
Count
Source
212
296k
                                SourceLocation (T::*v)() const) {
213
296k
    return static_cast<const E*>(expr)->getExprLoc();
214
296k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDefaultArgExpr, clang::CXXDefaultArgExpr>(clang::Expr const*, clang::SourceLocation (clang::CXXDefaultArgExpr::*)() const)
Line
Count
Source
212
34.6k
                                SourceLocation (T::*v)() const) {
213
34.6k
    return static_cast<const E*>(expr)->getExprLoc();
214
34.6k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXRewrittenBinaryOperator, clang::CXXRewrittenBinaryOperator>(clang::Expr const*, clang::SourceLocation (clang::CXXRewrittenBinaryOperator::*)() const)
Line
Count
Source
212
466
                                SourceLocation (T::*v)() const) {
213
466
    return static_cast<const E*>(expr)->getExprLoc();
214
466
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXMemberCallExpr, clang::CXXMemberCallExpr>(clang::Expr const*, clang::SourceLocation (clang::CXXMemberCallExpr::*)() const)
Line
Count
Source
212
947k
                                SourceLocation (T::*v)() const) {
213
947k
    return static_cast<const E*>(expr)->getExprLoc();
214
947k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXOperatorCallExpr, clang::CXXOperatorCallExpr>(clang::Expr const*, clang::SourceLocation (clang::CXXOperatorCallExpr::*)() const)
Line
Count
Source
212
648k
                                SourceLocation (T::*v)() const) {
213
648k
    return static_cast<const E*>(expr)->getExprLoc();
214
648k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MSPropertySubscriptExpr, clang::MSPropertySubscriptExpr>(clang::Expr const*, clang::SourceLocation (clang::MSPropertySubscriptExpr::*)() const)
Line
Count
Source
212
396
                                SourceLocation (T::*v)() const) {
213
396
    return static_cast<const E*>(expr)->getExprLoc();
214
396
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MatrixSubscriptExpr, clang::MatrixSubscriptExpr>(clang::Expr const*, clang::SourceLocation (clang::MatrixSubscriptExpr::*)() const)
Line
Count
Source
212
102
                                SourceLocation (T::*v)() const) {
213
102
    return static_cast<const E*>(expr)->getExprLoc();
214
102
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MemberExpr, clang::MemberExpr>(clang::Expr const*, clang::SourceLocation (clang::MemberExpr::*)() const)
Line
Count
Source
212
2.20M
                                SourceLocation (T::*v)() const) {
213
2.20M
    return static_cast<const E*>(expr)->getExprLoc();
214
2.20M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OMPArraySectionExpr, clang::OMPArraySectionExpr>(clang::Expr const*, clang::SourceLocation (clang::OMPArraySectionExpr::*)() const)
Line
Count
Source
212
45.0k
                                SourceLocation (T::*v)() const) {
213
45.0k
    return static_cast<const E*>(expr)->getExprLoc();
214
45.0k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCIndirectCopyRestoreExpr, clang::ObjCIndirectCopyRestoreExpr>(clang::Expr const*, clang::SourceLocation (clang::ObjCIndirectCopyRestoreExpr::*)() const)
Line
Count
Source
212
102
                                SourceLocation (T::*v)() const) {
213
102
    return static_cast<const E*>(expr)->getExprLoc();
214
102
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCIsaExpr, clang::ObjCIsaExpr>(clang::Expr const*, clang::SourceLocation (clang::ObjCIsaExpr::*)() const)
Line
Count
Source
212
185
                                SourceLocation (T::*v)() const) {
213
185
    return static_cast<const E*>(expr)->getExprLoc();
214
185
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OpaqueValueExpr, clang::OpaqueValueExpr>(clang::Expr const*, clang::SourceLocation (clang::OpaqueValueExpr::*)() const)
Line
Count
Source
212
41.2k
                                SourceLocation (T::*v)() const) {
213
41.2k
    return static_cast<const E*>(expr)->getExprLoc();
214
41.2k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UnresolvedMemberExpr, clang::UnresolvedMemberExpr>(clang::Expr const*, clang::SourceLocation (clang::UnresolvedMemberExpr::*)() const)
Line
Count
Source
212
306
                                SourceLocation (T::*v)() const) {
213
306
    return static_cast<const E*>(expr)->getExprLoc();
214
306
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::PseudoObjectExpr, clang::PseudoObjectExpr>(clang::Expr const*, clang::SourceLocation (clang::PseudoObjectExpr::*)() const)
Line
Count
Source
212
16.3k
                                SourceLocation (T::*v)() const) {
213
16.3k
    return static_cast<const E*>(expr)->getExprLoc();
214
16.3k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UnaryOperator, clang::UnaryOperator>(clang::Expr const*, clang::SourceLocation (clang::UnaryOperator::*)() const)
Line
Count
Source
212
3.41M
                                SourceLocation (T::*v)() const) {
213
3.41M
    return static_cast<const E*>(expr)->getExprLoc();
214
3.41M
  }
215
216
  /// This implementation is used when a class doesn't provide
217
  /// a custom implementation of getExprLoc.  Overload resolution
218
  /// should pick it over the implementation above because it's
219
  /// more specialized according to function template partial ordering.
220
  template <class E>
221
  SourceLocation getExprLocImpl(const Expr *expr,
222
72.2M
                                SourceLocation (Expr::*v)() const) {
223
72.2M
    return static_cast<const E *>(expr)->getBeginLoc();
224
72.2M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::BinaryConditionalOperator>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
282
                                SourceLocation (Expr::*v)() const) {
223
282
    return static_cast<const E *>(expr)->getBeginLoc();
224
282
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ConditionalOperator>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
264k
                                SourceLocation (Expr::*v)() const) {
223
264k
    return static_cast<const E *>(expr)->getBeginLoc();
224
264k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::AddrLabelExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
524
                                SourceLocation (Expr::*v)() const) {
223
524
    return static_cast<const E *>(expr)->getBeginLoc();
224
524
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ArrayInitIndexExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
73
                                SourceLocation (Expr::*v)() const) {
223
73
    return static_cast<const E *>(expr)->getBeginLoc();
224
73
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ArrayInitLoopExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
86
                                SourceLocation (Expr::*v)() const) {
223
86
    return static_cast<const E *>(expr)->getBeginLoc();
224
86
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ArrayTypeTraitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
465
                                SourceLocation (Expr::*v)() const) {
223
465
    return static_cast<const E *>(expr)->getBeginLoc();
224
465
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::AsTypeExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
81
                                SourceLocation (Expr::*v)() const) {
223
81
    return static_cast<const E *>(expr)->getBeginLoc();
224
81
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::AtomicExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
13.2k
                                SourceLocation (Expr::*v)() const) {
223
13.2k
    return static_cast<const E *>(expr)->getBeginLoc();
224
13.2k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::BlockExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
6.08k
                                SourceLocation (Expr::*v)() const) {
223
6.08k
    return static_cast<const E *>(expr)->getBeginLoc();
224
6.08k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXBindTemporaryExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
51.1k
                                SourceLocation (Expr::*v)() const) {
223
51.1k
    return static_cast<const E *>(expr)->getBeginLoc();
224
51.1k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXBoolLiteralExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
1.51M
                                SourceLocation (Expr::*v)() const) {
223
1.51M
    return static_cast<const E *>(expr)->getBeginLoc();
224
1.51M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXConstructExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
631k
                                SourceLocation (Expr::*v)() const) {
223
631k
    return static_cast<const E *>(expr)->getBeginLoc();
224
631k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXTemporaryObjectExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
246k
                                SourceLocation (Expr::*v)() const) {
223
246k
    return static_cast<const E *>(expr)->getBeginLoc();
224
246k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDefaultInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
1.29k
                                SourceLocation (Expr::*v)() const) {
223
1.29k
    return static_cast<const E *>(expr)->getBeginLoc();
224
1.29k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDeleteExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
12.4k
                                SourceLocation (Expr::*v)() const) {
223
12.4k
    return static_cast<const E *>(expr)->getBeginLoc();
224
12.4k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDependentScopeMemberExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
64.1k
                                SourceLocation (Expr::*v)() const) {
223
64.1k
    return static_cast<const E *>(expr)->getBeginLoc();
224
64.1k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXFoldExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
112
                                SourceLocation (Expr::*v)() const) {
223
112
    return static_cast<const E *>(expr)->getBeginLoc();
224
112
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXInheritedCtorInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
250
                                SourceLocation (Expr::*v)() const) {
223
250
    return static_cast<const E *>(expr)->getBeginLoc();
224
250
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXNewExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
56.4k
                                SourceLocation (Expr::*v)() const) {
223
56.4k
    return static_cast<const E *>(expr)->getBeginLoc();
224
56.4k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXNoexceptExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
1.81k
                                SourceLocation (Expr::*v)() const) {
223
1.81k
    return static_cast<const E *>(expr)->getBeginLoc();
224
1.81k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXNullPtrLiteralExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
86.9k
                                SourceLocation (Expr::*v)() const) {
223
86.9k
    return static_cast<const E *>(expr)->getBeginLoc();
224
86.9k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXPseudoDestructorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
546
                                SourceLocation (Expr::*v)() const) {
223
546
    return static_cast<const E *>(expr)->getBeginLoc();
224
546
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXScalarValueInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
17.7k
                                SourceLocation (Expr::*v)() const) {
223
17.7k
    return static_cast<const E *>(expr)->getBeginLoc();
224
17.7k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXStdInitializerListExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
2.26k
                                SourceLocation (Expr::*v)() const) {
223
2.26k
    return static_cast<const E *>(expr)->getBeginLoc();
224
2.26k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXThisExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
1.32M
                                SourceLocation (Expr::*v)() const) {
223
1.32M
    return static_cast<const E *>(expr)->getBeginLoc();
224
1.32M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXThrowExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
41.2k
                                SourceLocation (Expr::*v)() const) {
223
41.2k
    return static_cast<const E *>(expr)->getBeginLoc();
224
41.2k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXTypeidExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
3.95k
                                SourceLocation (Expr::*v)() const) {
223
3.95k
    return static_cast<const E *>(expr)->getBeginLoc();
224
3.95k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXUnresolvedConstructExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
6.43k
                                SourceLocation (Expr::*v)() const) {
223
6.43k
    return static_cast<const E *>(expr)->getBeginLoc();
224
6.43k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXUuidofExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
250
                                SourceLocation (Expr::*v)() const) {
223
250
    return static_cast<const E *>(expr)->getBeginLoc();
224
250
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CallExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
11.9M
                                SourceLocation (Expr::*v)() const) {
223
11.9M
    return static_cast<const E *>(expr)->getBeginLoc();
224
11.9M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CUDAKernelCallExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
604
                                SourceLocation (Expr::*v)() const) {
223
604
    return static_cast<const E *>(expr)->getBeginLoc();
224
604
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UserDefinedLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
3.44k
                                SourceLocation (Expr::*v)() const) {
223
3.44k
    return static_cast<const E *>(expr)->getBeginLoc();
224
3.44k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::BuiltinBitCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
1.10k
                                SourceLocation (Expr::*v)() const) {
223
1.10k
    return static_cast<const E *>(expr)->getBeginLoc();
224
1.10k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CStyleCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
4.72M
                                SourceLocation (Expr::*v)() const) {
223
4.72M
    return static_cast<const E *>(expr)->getBeginLoc();
224
4.72M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXFunctionalCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
69.4k
                                SourceLocation (Expr::*v)() const) {
223
69.4k
    return static_cast<const E *>(expr)->getBeginLoc();
224
69.4k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXAddrspaceCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
5
                                SourceLocation (Expr::*v)() const) {
223
5
    return static_cast<const E *>(expr)->getBeginLoc();
224
5
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXConstCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
542
                                SourceLocation (Expr::*v)() const) {
223
542
    return static_cast<const E *>(expr)->getBeginLoc();
224
542
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXDynamicCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
563
                                SourceLocation (Expr::*v)() const) {
223
563
    return static_cast<const E *>(expr)->getBeginLoc();
224
563
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXReinterpretCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
2.65k
                                SourceLocation (Expr::*v)() const) {
223
2.65k
    return static_cast<const E *>(expr)->getBeginLoc();
224
2.65k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CXXStaticCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
72.3k
                                SourceLocation (Expr::*v)() const) {
223
72.3k
    return static_cast<const E *>(expr)->getBeginLoc();
224
72.3k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCBridgedCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
366
                                SourceLocation (Expr::*v)() const) {
223
366
    return static_cast<const E *>(expr)->getBeginLoc();
224
366
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ImplicitCastExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
6.49M
                                SourceLocation (Expr::*v)() const) {
223
6.49M
    return static_cast<const E *>(expr)->getBeginLoc();
224
6.49M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CharacterLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
883k
                                SourceLocation (Expr::*v)() const) {
223
883k
    return static_cast<const E *>(expr)->getBeginLoc();
224
883k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ChooseExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
30
                                SourceLocation (Expr::*v)() const) {
223
30
    return static_cast<const E *>(expr)->getBeginLoc();
224
30
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CompoundLiteralExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
95.5k
                                SourceLocation (Expr::*v)() const) {
223
95.5k
    return static_cast<const E *>(expr)->getBeginLoc();
224
95.5k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ConceptSpecializationExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
553
                                SourceLocation (Expr::*v)() const) {
223
553
    return static_cast<const E *>(expr)->getBeginLoc();
224
553
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ConvertVectorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
21.1k
                                SourceLocation (Expr::*v)() const) {
223
21.1k
    return static_cast<const E *>(expr)->getBeginLoc();
224
21.1k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CoawaitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
1.45k
                                SourceLocation (Expr::*v)() const) {
223
1.45k
    return static_cast<const E *>(expr)->getBeginLoc();
224
1.45k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::CoyieldExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
144
                                SourceLocation (Expr::*v)() const) {
223
144
    return static_cast<const E *>(expr)->getBeginLoc();
224
144
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DeclRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
26.4M
                                SourceLocation (Expr::*v)() const) {
223
26.4M
    return static_cast<const E *>(expr)->getBeginLoc();
224
26.4M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DependentCoawaitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
52
                                SourceLocation (Expr::*v)() const) {
223
52
    return static_cast<const E *>(expr)->getBeginLoc();
224
52
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DependentScopeDeclRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
1.29k
                                SourceLocation (Expr::*v)() const) {
223
1.29k
    return static_cast<const E *>(expr)->getBeginLoc();
224
1.29k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DesignatedInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
10
                                SourceLocation (Expr::*v)() const) {
223
10
    return static_cast<const E *>(expr)->getBeginLoc();
224
10
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::DesignatedInitUpdateExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
75
                                SourceLocation (Expr::*v)() const) {
223
75
    return static_cast<const E *>(expr)->getBeginLoc();
224
75
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ExpressionTraitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
24
                                SourceLocation (Expr::*v)() const) {
223
24
    return static_cast<const E *>(expr)->getBeginLoc();
224
24
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ExtVectorElementExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
1.53k
                                SourceLocation (Expr::*v)() const) {
223
1.53k
    return static_cast<const E *>(expr)->getBeginLoc();
224
1.53k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::FixedPointLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
1.56k
                                SourceLocation (Expr::*v)() const) {
223
1.56k
    return static_cast<const E *>(expr)->getBeginLoc();
224
1.56k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::FloatingLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
81.2k
                                SourceLocation (Expr::*v)() const) {
223
81.2k
    return static_cast<const E *>(expr)->getBeginLoc();
224
81.2k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ConstantExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
111k
                                SourceLocation (Expr::*v)() const) {
223
111k
    return static_cast<const E *>(expr)->getBeginLoc();
224
111k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ExprWithCleanups>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
23.5k
                                SourceLocation (Expr::*v)() const) {
223
23.5k
    return static_cast<const E *>(expr)->getBeginLoc();
224
23.5k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::FunctionParmPackExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
190
                                SourceLocation (Expr::*v)() const) {
223
190
    return static_cast<const E *>(expr)->getBeginLoc();
224
190
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::GNUNullExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
5.20k
                                SourceLocation (Expr::*v)() const) {
223
5.20k
    return static_cast<const E *>(expr)->getBeginLoc();
224
5.20k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::GenericSelectionExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
436
                                SourceLocation (Expr::*v)() const) {
223
436
    return static_cast<const E *>(expr)->getBeginLoc();
224
436
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ImaginaryLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
611
                                SourceLocation (Expr::*v)() const) {
223
611
    return static_cast<const E *>(expr)->getBeginLoc();
224
611
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ImplicitValueInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
18.2k
                                SourceLocation (Expr::*v)() const) {
223
18.2k
    return static_cast<const E *>(expr)->getBeginLoc();
224
18.2k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::InitListExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
134k
                                SourceLocation (Expr::*v)() const) {
223
134k
    return static_cast<const E *>(expr)->getBeginLoc();
224
134k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::IntegerLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
12.1M
                                SourceLocation (Expr::*v)() const) {
223
12.1M
    return static_cast<const E *>(expr)->getBeginLoc();
224
12.1M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::LambdaExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
35.3k
                                SourceLocation (Expr::*v)() const) {
223
35.3k
    return static_cast<const E *>(expr)->getBeginLoc();
224
35.3k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MSPropertyRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
631
                                SourceLocation (Expr::*v)() const) {
223
631
    return static_cast<const E *>(expr)->getBeginLoc();
224
631
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::MaterializeTemporaryExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
43.8k
                                SourceLocation (Expr::*v)() const) {
223
43.8k
    return static_cast<const E *>(expr)->getBeginLoc();
224
43.8k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::NoInitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
102
                                SourceLocation (Expr::*v)() const) {
223
102
    return static_cast<const E *>(expr)->getBeginLoc();
224
102
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OMPArrayShapingExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
417
                                SourceLocation (Expr::*v)() const) {
223
417
    return static_cast<const E *>(expr)->getBeginLoc();
224
417
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OMPIteratorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
8
                                SourceLocation (Expr::*v)() const) {
223
8
    return static_cast<const E *>(expr)->getBeginLoc();
224
8
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCArrayLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
836
                                SourceLocation (Expr::*v)() const) {
223
836
    return static_cast<const E *>(expr)->getBeginLoc();
224
836
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCAvailabilityCheckExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
218
                                SourceLocation (Expr::*v)() const) {
223
218
    return static_cast<const E *>(expr)->getBeginLoc();
224
218
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCBoolLiteralExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
3.13k
                                SourceLocation (Expr::*v)() const) {
223
3.13k
    return static_cast<const E *>(expr)->getBeginLoc();
224
3.13k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCBoxedExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
3.64k
                                SourceLocation (Expr::*v)() const) {
223
3.64k
    return static_cast<const E *>(expr)->getBeginLoc();
224
3.64k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCDictionaryLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
643
                                SourceLocation (Expr::*v)() const) {
223
643
    return static_cast<const E *>(expr)->getBeginLoc();
224
643
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCEncodeExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
245
                                SourceLocation (Expr::*v)() const) {
223
245
    return static_cast<const E *>(expr)->getBeginLoc();
224
245
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCIvarRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
10.0k
                                SourceLocation (Expr::*v)() const) {
223
10.0k
    return static_cast<const E *>(expr)->getBeginLoc();
224
10.0k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCMessageExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
98.8k
                                SourceLocation (Expr::*v)() const) {
223
98.8k
    return static_cast<const E *>(expr)->getBeginLoc();
224
98.8k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCPropertyRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
6.76k
                                SourceLocation (Expr::*v)() const) {
223
6.76k
    return static_cast<const E *>(expr)->getBeginLoc();
224
6.76k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCProtocolExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
98
                                SourceLocation (Expr::*v)() const) {
223
98
    return static_cast<const E *>(expr)->getBeginLoc();
224
98
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCSelectorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
900
                                SourceLocation (Expr::*v)() const) {
223
900
    return static_cast<const E *>(expr)->getBeginLoc();
224
900
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCStringLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
25.2k
                                SourceLocation (Expr::*v)() const) {
223
25.2k
    return static_cast<const E *>(expr)->getBeginLoc();
224
25.2k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ObjCSubscriptRefExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
737
                                SourceLocation (Expr::*v)() const) {
223
737
    return static_cast<const E *>(expr)->getBeginLoc();
224
737
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::OffsetOfExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
933
                                SourceLocation (Expr::*v)() const) {
223
933
    return static_cast<const E *>(expr)->getBeginLoc();
224
933
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UnresolvedLookupExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
1.00M
                                SourceLocation (Expr::*v)() const) {
223
1.00M
    return static_cast<const E *>(expr)->getBeginLoc();
224
1.00M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::PackExpansionExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
17
                                SourceLocation (Expr::*v)() const) {
223
17
    return static_cast<const E *>(expr)->getBeginLoc();
224
17
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ParenExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
635k
                                SourceLocation (Expr::*v)() const) {
223
635k
    return static_cast<const E *>(expr)->getBeginLoc();
224
635k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ParenListExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
5.14k
                                SourceLocation (Expr::*v)() const) {
223
5.14k
    return static_cast<const E *>(expr)->getBeginLoc();
224
5.14k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::PredefinedExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
2.19k
                                SourceLocation (Expr::*v)() const) {
223
2.19k
    return static_cast<const E *>(expr)->getBeginLoc();
224
2.19k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::RecoveryExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
11.9k
                                SourceLocation (Expr::*v)() const) {
223
11.9k
    return static_cast<const E *>(expr)->getBeginLoc();
224
11.9k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::RequiresExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
253
                                SourceLocation (Expr::*v)() const) {
223
253
    return static_cast<const E *>(expr)->getBeginLoc();
224
253
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::ShuffleVectorExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
351k
                                SourceLocation (Expr::*v)() const) {
223
351k
    return static_cast<const E *>(expr)->getBeginLoc();
224
351k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::SizeOfPackExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
143k
                                SourceLocation (Expr::*v)() const) {
223
143k
    return static_cast<const E *>(expr)->getBeginLoc();
224
143k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::SourceLocExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
326
                                SourceLocation (Expr::*v)() const) {
223
326
    return static_cast<const E *>(expr)->getBeginLoc();
224
326
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::StmtExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
11.4k
                                SourceLocation (Expr::*v)() const) {
223
11.4k
    return static_cast<const E *>(expr)->getBeginLoc();
224
11.4k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::StringLiteral>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
384k
                                SourceLocation (Expr::*v)() const) {
223
384k
    return static_cast<const E *>(expr)->getBeginLoc();
224
384k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::SubstNonTypeTemplateParmExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
1.07M
                                SourceLocation (Expr::*v)() const) {
223
1.07M
    return static_cast<const E *>(expr)->getBeginLoc();
224
1.07M
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::SubstNonTypeTemplateParmPackExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
6
                                SourceLocation (Expr::*v)() const) {
223
6
    return static_cast<const E *>(expr)->getBeginLoc();
224
6
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::TypeTraitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
507k
                                SourceLocation (Expr::*v)() const) {
223
507k
    return static_cast<const E *>(expr)->getBeginLoc();
224
507k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::TypoExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
78
                                SourceLocation (Expr::*v)() const) {
223
78
    return static_cast<const E *>(expr)->getBeginLoc();
224
78
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::UnaryExprOrTypeTraitExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
189k
                                SourceLocation (Expr::*v)() const) {
223
189k
    return static_cast<const E *>(expr)->getBeginLoc();
224
189k
  }
Expr.cpp:clang::SourceLocation (anonymous namespace)::getExprLocImpl<clang::VAArgExpr>(clang::Expr const*, clang::SourceLocation (clang::Expr::*)() const)
Line
Count
Source
222
3.31k
                                SourceLocation (Expr::*v)() const) {
223
3.31k
    return static_cast<const E *>(expr)->getBeginLoc();
224
3.31k
  }
225
}
226
227
90.2M
SourceLocation Expr::getExprLoc() const {
228
90.2M
  switch (getStmtClass()) {
229
0
  case Stmt::NoStmtClass: llvm_unreachable("statement without class");
230
0
#define ABSTRACT_STMT(type)
231
0
#define STMT(type, base) \
232
0
  case Stmt::type##Class: break;
233
0
#define EXPR(type, base) \
234
90.2M
  case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc);
235
0
#include "clang/AST/StmtNodes.inc"
236
90.2M
  }
237
90.2M
  
llvm_unreachable0
("unknown expression kind");
238
90.2M
}
239
240
//===----------------------------------------------------------------------===//
241
// Primary Expressions.
242
//===----------------------------------------------------------------------===//
243
244
7.01M
static void AssertResultStorageKind(ConstantExpr::ResultStorageKind Kind) {
245
7.01M
  assert((Kind == ConstantExpr::RSK_APValue ||
246
7.01M
          Kind == ConstantExpr::RSK_Int64 || Kind == ConstantExpr::RSK_None) &&
247
7.01M
         "Invalid StorageKind Value");
248
7.01M
  (void)Kind;
249
7.01M
}
250
251
ConstantExpr::ResultStorageKind
252
4.90M
ConstantExpr::getStorageKind(const APValue &Value) {
253
4.90M
  switch (Value.getKind()) {
254
14.5k
  case APValue::None:
255
14.5k
  case APValue::Indeterminate:
256
14.5k
    return ConstantExpr::RSK_None;
257
4.88M
  case APValue::Int:
258
4.88M
    if (!Value.getInt().needsCleanup())
259
4.88M
      return ConstantExpr::RSK_Int64;
260
45
    LLVM_FALLTHROUGH;
261
1.95k
  default:
262
1.95k
    return ConstantExpr::RSK_APValue;
263
4.90M
  }
264
4.90M
}
265
266
ConstantExpr::ResultStorageKind
267
212
ConstantExpr::getStorageKind(const Type *T, const ASTContext &Context) {
268
212
  if (T->isIntegralOrEnumerationType() && 
Context.getTypeInfo(T).Width <= 6463
)
269
60
    return ConstantExpr::RSK_Int64;
270
152
  return ConstantExpr::RSK_APValue;
271
152
}
272
273
ConstantExpr::ConstantExpr(Expr *SubExpr, ResultStorageKind StorageKind,
274
                           bool IsImmediateInvocation)
275
6.84M
    : FullExpr(ConstantExprClass, SubExpr) {
276
6.84M
  ConstantExprBits.ResultKind = StorageKind;
277
6.84M
  ConstantExprBits.APValueKind = APValue::None;
278
6.84M
  ConstantExprBits.IsUnsigned = false;
279
6.84M
  ConstantExprBits.BitWidth = 0;
280
6.84M
  ConstantExprBits.HasCleanup = false;
281
6.84M
  ConstantExprBits.IsImmediateInvocation = IsImmediateInvocation;
282
283
6.84M
  if (StorageKind == ConstantExpr::RSK_APValue)
284
1.08k
    ::new (getTrailingObjects<APValue>()) APValue();
285
6.84M
}
286
287
ConstantExpr *ConstantExpr::Create(const ASTContext &Context, Expr *E,
288
                                   ResultStorageKind StorageKind,
289
6.84M
                                   bool IsImmediateInvocation) {
290
6.84M
  assert(!isa<ConstantExpr>(E));
291
6.84M
  AssertResultStorageKind(StorageKind);
292
293
6.84M
  unsigned Size = totalSizeToAlloc<APValue, uint64_t>(
294
6.84M
      StorageKind == ConstantExpr::RSK_APValue,
295
6.84M
      StorageKind == ConstantExpr::RSK_Int64);
296
6.84M
  void *Mem = Context.Allocate(Size, alignof(ConstantExpr));
297
6.84M
  return new (Mem) ConstantExpr(E, StorageKind, IsImmediateInvocation);
298
6.84M
}
299
300
ConstantExpr *ConstantExpr::Create(const ASTContext &Context, Expr *E,
301
2.45M
                                   const APValue &Result) {
302
2.45M
  ResultStorageKind StorageKind = getStorageKind(Result);
303
2.45M
  ConstantExpr *Self = Create(Context, E, StorageKind);
304
2.45M
  Self->SetResult(Result, Context);
305
2.45M
  return Self;
306
2.45M
}
307
308
ConstantExpr::ConstantExpr(EmptyShell Empty, ResultStorageKind StorageKind)
309
175k
    : FullExpr(ConstantExprClass, Empty) {
310
175k
  ConstantExprBits.ResultKind = StorageKind;
311
312
175k
  if (StorageKind == ConstantExpr::RSK_APValue)
313
6
    ::new (getTrailingObjects<APValue>()) APValue();
314
175k
}
315
316
ConstantExpr *ConstantExpr::CreateEmpty(const ASTContext &Context,
317
175k
                                        ResultStorageKind StorageKind) {
318
175k
  AssertResultStorageKind(StorageKind);
319
320
175k
  unsigned Size = totalSizeToAlloc<APValue, uint64_t>(
321
175k
      StorageKind == ConstantExpr::RSK_APValue,
322
175k
      StorageKind == ConstantExpr::RSK_Int64);
323
175k
  void *Mem = Context.Allocate(Size, alignof(ConstantExpr));
324
175k
  return new (Mem) ConstantExpr(EmptyShell(), StorageKind);
325
175k
}
326
327
2.45M
void ConstantExpr::MoveIntoResult(APValue &Value, const ASTContext &Context) {
328
2.45M
  assert((unsigned)getStorageKind(Value) <= ConstantExprBits.ResultKind &&
329
2.45M
         "Invalid storage for this value kind");
330
2.45M
  ConstantExprBits.APValueKind = Value.getKind();
331
2.45M
  switch (ConstantExprBits.ResultKind) {
332
7.29k
  case RSK_None:
333
7.29k
    return;
334
2.44M
  case RSK_Int64:
335
2.44M
    Int64Result() = *Value.getInt().getRawData();
336
2.44M
    ConstantExprBits.BitWidth = Value.getInt().getBitWidth();
337
2.44M
    ConstantExprBits.IsUnsigned = Value.getInt().isUnsigned();
338
2.44M
    return;
339
1.02k
  case RSK_APValue:
340
1.02k
    if (!ConstantExprBits.HasCleanup && Value.needsCleanup()) {
341
324
      ConstantExprBits.HasCleanup = true;
342
324
      Context.addDestruction(&APValueResult());
343
324
    }
344
1.02k
    APValueResult() = std::move(Value);
345
1.02k
    return;
346
0
  }
347
0
  llvm_unreachable("Invalid ResultKind Bits");
348
0
}
349
350
0
llvm::APSInt ConstantExpr::getResultAsAPSInt() const {
351
0
  switch (ConstantExprBits.ResultKind) {
352
0
  case ConstantExpr::RSK_APValue:
353
0
    return APValueResult().getInt();
354
0
  case ConstantExpr::RSK_Int64:
355
0
    return llvm::APSInt(llvm::APInt(ConstantExprBits.BitWidth, Int64Result()),
356
0
                        ConstantExprBits.IsUnsigned);
357
0
  default:
358
0
    llvm_unreachable("invalid Accessor");
359
0
  }
360
0
}
361
362
96.5k
APValue ConstantExpr::getAPValueResult() const {
363
364
96.5k
  switch (ConstantExprBits.ResultKind) {
365
81
  case ConstantExpr::RSK_APValue:
366
81
    return APValueResult();
367
96.4k
  case ConstantExpr::RSK_Int64:
368
96.4k
    return APValue(
369
96.4k
        llvm::APSInt(llvm::APInt(ConstantExprBits.BitWidth, Int64Result()),
370
96.4k
                     ConstantExprBits.IsUnsigned));
371
68
  case ConstantExpr::RSK_None:
372
68
    if (ConstantExprBits.APValueKind == APValue::Indeterminate)
373
0
      return APValue::IndeterminateValue();
374
68
    return APValue();
375
0
  }
376
0
  llvm_unreachable("invalid ResultKind");
377
0
}
378
379
DeclRefExpr::DeclRefExpr(const ASTContext &Ctx, ValueDecl *D,
380
                         bool RefersToEnclosingVariableOrCapture, QualType T,
381
                         ExprValueKind VK, SourceLocation L,
382
                         const DeclarationNameLoc &LocInfo,
383
                         NonOdrUseReason NOUR)
384
821k
    : Expr(DeclRefExprClass, T, VK, OK_Ordinary), D(D), DNLoc(LocInfo) {
385
821k
  DeclRefExprBits.HasQualifier = false;
386
821k
  DeclRefExprBits.HasTemplateKWAndArgsInfo = false;
387
821k
  DeclRefExprBits.HasFoundDecl = false;
388
821k
  DeclRefExprBits.HadMultipleCandidates = false;
389
821k
  DeclRefExprBits.RefersToEnclosingVariableOrCapture =
390
821k
      RefersToEnclosingVariableOrCapture;
391
821k
  DeclRefExprBits.NonOdrUseReason = NOUR;
392
821k
  DeclRefExprBits.Loc = L;
393
821k
  setDependence(computeDependence(this, Ctx));
394
821k
}
395
396
DeclRefExpr::DeclRefExpr(const ASTContext &Ctx,
397
                         NestedNameSpecifierLoc QualifierLoc,
398
                         SourceLocation TemplateKWLoc, ValueDecl *D,
399
                         bool RefersToEnclosingVariableOrCapture,
400
                         const DeclarationNameInfo &NameInfo, NamedDecl *FoundD,
401
                         const TemplateArgumentListInfo *TemplateArgs,
402
                         QualType T, ExprValueKind VK, NonOdrUseReason NOUR)
403
    : Expr(DeclRefExprClass, T, VK, OK_Ordinary), D(D),
404
20.1M
      DNLoc(NameInfo.getInfo()) {
405
20.1M
  DeclRefExprBits.Loc = NameInfo.getLoc();
406
18.4M
  DeclRefExprBits.HasQualifier = QualifierLoc ? 
11.73M
: 0;
407
20.1M
  if (QualifierLoc)
408
1.73M
    new (getTrailingObjects<NestedNameSpecifierLoc>())
409
1.73M
        NestedNameSpecifierLoc(QualifierLoc);
410
19.9M
  DeclRefExprBits.HasFoundDecl = FoundD ? 
1229k
: 0;
411
20.1M
  if (FoundD)
412
229k
    *getTrailingObjects<NamedDecl *>() = FoundD;
413
20.1M
  DeclRefExprBits.HasTemplateKWAndArgsInfo
414
20.1M
    = (TemplateArgs || 
TemplateKWLoc.isValid()20.0M
) ?
1141k
:
020.0M
;
415
20.1M
  DeclRefExprBits.RefersToEnclosingVariableOrCapture =
416
20.1M
      RefersToEnclosingVariableOrCapture;
417
20.1M
  DeclRefExprBits.NonOdrUseReason = NOUR;
418
20.1M
  if (TemplateArgs) {
419
141k
    auto Deps = TemplateArgumentDependence::None;
420
141k
    getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
421
141k
        TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
422
141k
        Deps);
423
141k
    assert(!(Deps & TemplateArgumentDependence::Dependent) &&
424
141k
           "built a DeclRefExpr with dependent template args");
425
20.0M
  } else if (TemplateKWLoc.isValid()) {
426
19
    getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
427
19
        TemplateKWLoc);
428
19
  }
429
20.1M
  DeclRefExprBits.HadMultipleCandidates = 0;
430
20.1M
  setDependence(computeDependence(this, Ctx));
431
20.1M
}
432
433
DeclRefExpr *DeclRefExpr::Create(const ASTContext &Context,
434
                                 NestedNameSpecifierLoc QualifierLoc,
435
                                 SourceLocation TemplateKWLoc, ValueDecl *D,
436
                                 bool RefersToEnclosingVariableOrCapture,
437
                                 SourceLocation NameLoc, QualType T,
438
                                 ExprValueKind VK, NamedDecl *FoundD,
439
                                 const TemplateArgumentListInfo *TemplateArgs,
440
2.58M
                                 NonOdrUseReason NOUR) {
441
2.58M
  return Create(Context, QualifierLoc, TemplateKWLoc, D,
442
2.58M
                RefersToEnclosingVariableOrCapture,
443
2.58M
                DeclarationNameInfo(D->getDeclName(), NameLoc),
444
2.58M
                T, VK, FoundD, TemplateArgs, NOUR);
445
2.58M
}
446
447
DeclRefExpr *DeclRefExpr::Create(const ASTContext &Context,
448
                                 NestedNameSpecifierLoc QualifierLoc,
449
                                 SourceLocation TemplateKWLoc, ValueDecl *D,
450
                                 bool RefersToEnclosingVariableOrCapture,
451
                                 const DeclarationNameInfo &NameInfo,
452
                                 QualType T, ExprValueKind VK,
453
                                 NamedDecl *FoundD,
454
                                 const TemplateArgumentListInfo *TemplateArgs,
455
20.1M
                                 NonOdrUseReason NOUR) {
456
  // Filter out cases where the found Decl is the same as the value refenenced.
457
20.1M
  if (D == FoundD)
458
16.9M
    FoundD = nullptr;
459
460
20.1M
  bool HasTemplateKWAndArgsInfo = TemplateArgs || 
TemplateKWLoc.isValid()20.0M
;
461
20.1M
  std::size_t Size =
462
20.1M
      totalSizeToAlloc<NestedNameSpecifierLoc, NamedDecl *,
463
20.1M
                       ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
464
19.9M
          QualifierLoc ? 
11.73M
:
018.4M
, FoundD ?
1229k
: 0,
465
20.0M
          HasTemplateKWAndArgsInfo ? 
1141k
: 0,
466
20.0M
          TemplateArgs ? 
TemplateArgs->size()141k
: 0);
467
468
20.1M
  void *Mem = Context.Allocate(Size, alignof(DeclRefExpr));
469
20.1M
  return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D,
470
20.1M
                               RefersToEnclosingVariableOrCapture, NameInfo,
471
20.1M
                               FoundD, TemplateArgs, T, VK, NOUR);
472
20.1M
}
473
474
DeclRefExpr *DeclRefExpr::CreateEmpty(const ASTContext &Context,
475
                                      bool HasQualifier,
476
                                      bool HasFoundDecl,
477
                                      bool HasTemplateKWAndArgsInfo,
478
1.45M
                                      unsigned NumTemplateArgs) {
479
1.45M
  assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
480
1.45M
  std::size_t Size =
481
1.45M
      totalSizeToAlloc<NestedNameSpecifierLoc, NamedDecl *,
482
1.45M
                       ASTTemplateKWAndArgsInfo, TemplateArgumentLoc>(
483
1.43M
          HasQualifier ? 
188.1k
:
01.36M
, HasFoundDecl ?
116.1k
: 0, HasTemplateKWAndArgsInfo,
484
1.45M
          NumTemplateArgs);
485
1.45M
  void *Mem = Context.Allocate(Size, alignof(DeclRefExpr));
486
1.45M
  return new (Mem) DeclRefExpr(EmptyShell());
487
1.45M
}
488
489
869k
void DeclRefExpr::setDecl(ValueDecl *NewD) {
490
869k
  D = NewD;
491
869k
  setDependence(computeDependence(this, NewD->getASTContext()));
492
869k
}
493
494
107M
SourceLocation DeclRefExpr::getBeginLoc() const {
495
107M
  if (hasQualifier())
496
7.17M
    return getQualifierLoc().getBeginLoc();
497
100M
  return getNameInfo().getBeginLoc();
498
100M
}
499
8.80M
SourceLocation DeclRefExpr::getEndLoc() const {
500
8.80M
  if (hasExplicitTemplateArgs())
501
137k
    return getRAngleLoc();
502
8.66M
  return getNameInfo().getEndLoc();
503
8.66M
}
504
505
PredefinedExpr::PredefinedExpr(SourceLocation L, QualType FNTy, IdentKind IK,
506
                               StringLiteral *SL)
507
830
    : Expr(PredefinedExprClass, FNTy, VK_LValue, OK_Ordinary) {
508
830
  PredefinedExprBits.Kind = IK;
509
830
  assert((getIdentKind() == IK) &&
510
830
         "IdentKind do not fit in PredefinedExprBitfields!");
511
830
  bool HasFunctionName = SL != nullptr;
512
830
  PredefinedExprBits.HasFunctionName = HasFunctionName;
513
830
  PredefinedExprBits.Loc = L;
514
830
  if (HasFunctionName)
515
762
    setFunctionName(SL);
516
830
  setDependence(computeDependence(this));
517
830
}
518
519
PredefinedExpr::PredefinedExpr(EmptyShell Empty, bool HasFunctionName)
520
17
    : Expr(PredefinedExprClass, Empty) {
521
17
  PredefinedExprBits.HasFunctionName = HasFunctionName;
522
17
}
523
524
PredefinedExpr *PredefinedExpr::Create(const ASTContext &Ctx, SourceLocation L,
525
                                       QualType FNTy, IdentKind IK,
526
830
                                       StringLiteral *SL) {
527
830
  bool HasFunctionName = SL != nullptr;
528
830
  void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName),
529
830
                           alignof(PredefinedExpr));
530
830
  return new (Mem) PredefinedExpr(L, FNTy, IK, SL);
531
830
}
532
533
PredefinedExpr *PredefinedExpr::CreateEmpty(const ASTContext &Ctx,
534
17
                                            bool HasFunctionName) {
535
17
  void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName),
536
17
                           alignof(PredefinedExpr));
537
17
  return new (Mem) PredefinedExpr(EmptyShell(), HasFunctionName);
538
17
}
539
540
555
StringRef PredefinedExpr::getIdentKindName(PredefinedExpr::IdentKind IK) {
541
555
  switch (IK) {
542
200
  case Func:
543
200
    return "__func__";
544
168
  case Function:
545
168
    return "__FUNCTION__";
546
0
  case FuncDName:
547
0
    return "__FUNCDNAME__";
548
1
  case LFunction:
549
1
    return "L__FUNCTION__";
550
177
  case PrettyFunction:
551
177
    return "__PRETTY_FUNCTION__";
552
9
  case FuncSig:
553
9
    return "__FUNCSIG__";
554
0
  case LFuncSig:
555
0
    return "L__FUNCSIG__";
556
0
  case PrettyFunctionNoVirtual:
557
0
    break;
558
0
  }
559
0
  llvm_unreachable("Unknown ident kind for PredefinedExpr");
560
0
}
561
562
// FIXME: Maybe this should use DeclPrinter with a special "print predefined
563
// expr" policy instead.
564
2.67k
std::string PredefinedExpr::ComputeName(IdentKind IK, const Decl *CurrentDecl) {
565
2.67k
  ASTContext &Context = CurrentDecl->getASTContext();
566
567
2.67k
  if (IK == PredefinedExpr::FuncDName) {
568
9
    if (const NamedDecl *ND = dyn_cast<NamedDecl>(CurrentDecl)) {
569
9
      std::unique_ptr<MangleContext> MC;
570
9
      MC.reset(Context.createMangleContext());
571
572
9
      if (MC->shouldMangleDeclName(ND)) {
573
8
        SmallString<256> Buffer;
574
8
        llvm::raw_svector_ostream Out(Buffer);
575
8
        GlobalDecl GD;
576
8
        if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(ND))
577
2
          GD = GlobalDecl(CD, Ctor_Base);
578
6
        else if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(ND))
579
2
          GD = GlobalDecl(DD, Dtor_Base);
580
4
        else if (ND->hasAttr<CUDAGlobalAttr>())
581
0
          GD = GlobalDecl(cast<FunctionDecl>(ND));
582
4
        else
583
4
          GD = GlobalDecl(ND);
584
8
        MC->mangleName(GD, Out);
585
586
8
        if (!Buffer.empty() && Buffer.front() == '\01')
587
0
          return std::string(Buffer.substr(1));
588
8
        return std::string(Buffer.str());
589
8
      } else
590
1
        return std::string(ND->getIdentifier()->getName());
591
0
    }
592
0
    return "";
593
0
  }
594
2.66k
  if (isa<BlockDecl>(CurrentDecl)) {
595
    // For blocks we only emit something if it is enclosed in a function
596
    // For top-level block we'd like to include the name of variable, but we
597
    // don't have it at this point.
598
43
    auto DC = CurrentDecl->getDeclContext();
599
43
    if (DC->isFileContext())
600
5
      return "";
601
602
38
    SmallString<256> Buffer;
603
38
    llvm::raw_svector_ostream Out(Buffer);
604
38
    if (auto *DCBlock = dyn_cast<BlockDecl>(DC))
605
      // For nested blocks, propagate up to the parent.
606
5
      Out << ComputeName(IK, DCBlock);
607
33
    else if (auto *DCDecl = dyn_cast<Decl>(DC))
608
33
      Out << ComputeName(IK, DCDecl) << "_block_invoke";
609
38
    return std::string(Out.str());
610
38
  }
611
2.62k
  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) {
612
2.45k
    if (IK != PrettyFunction && 
IK != PrettyFunctionNoVirtual2.26k
&&
613
542
        IK != FuncSig && 
IK != LFuncSig529
)
614
523
      return FD->getNameAsString();
615
616
1.93k
    SmallString<256> Name;
617
1.93k
    llvm::raw_svector_ostream Out(Name);
618
619
1.93k
    if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
620
1.84k
      if (MD->isVirtual() && 
IK != PrettyFunctionNoVirtual1.72k
)
621
2
        Out << "virtual ";
622
1.84k
      if (MD->isStatic())
623
2
        Out << "static ";
624
1.84k
    }
625
626
1.93k
    PrintingPolicy Policy(Context.getLangOpts());
627
1.93k
    std::string Proto;
628
1.93k
    llvm::raw_string_ostream POut(Proto);
629
630
1.93k
    const FunctionDecl *Decl = FD;
631
1.93k
    if (const FunctionDecl* Pattern = FD->getTemplateInstantiationPattern())
632
34
      Decl = Pattern;
633
1.93k
    const FunctionType *AFT = Decl->getType()->getAs<FunctionType>();
634
1.93k
    const FunctionProtoType *FT = nullptr;
635
1.93k
    if (FD->hasWrittenPrototype())
636
1.90k
      FT = dyn_cast<FunctionProtoType>(AFT);
637
638
1.93k
    if (IK == FuncSig || 
IK == LFuncSig1.91k
) {
639
19
      switch (AFT->getCallConv()) {
640
13
      case CC_C: POut << "__cdecl "; break;
641
0
      case CC_X86StdCall: POut << "__stdcall "; break;
642
0
      case CC_X86FastCall: POut << "__fastcall "; break;
643
6
      case CC_X86ThisCall: POut << "__thiscall "; break;
644
0
      case CC_X86VectorCall: POut << "__vectorcall "; break;
645
0
      case CC_X86RegCall: POut << "__regcall "; break;
646
      // Only bother printing the conventions that MSVC knows about.
647
0
      default: break;
648
1.93k
      }
649
1.93k
    }
650
651
1.93k
    FD->printQualifiedName(POut, Policy);
652
653
1.93k
    POut << "(";
654
1.93k
    if (FT) {
655
2.05k
      for (unsigned i = 0, e = Decl->getNumParams(); i != e; 
++i146
) {
656
146
        if (i) 
POut << ", "10
;
657
146
        POut << Decl->getParamDecl(i)->getType().stream(Policy);
658
146
      }
659
660
1.90k
      if (FT->isVariadic()) {
661
4
        if (FD->getNumParams()) 
POut << ", "3
;
662
4
        POut << "...";
663
1.90k
      } else if ((IK == FuncSig || 
IK == LFuncSig1.89k
||
664
1.88k
                  !Context.getLangOpts().CPlusPlus) &&
665
18
                 !Decl->getNumParams()) {
666
11
        POut << "void";
667
11
      }
668
1.90k
    }
669
1.93k
    POut << ")";
670
671
1.93k
    if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
672
1.84k
      assert(FT && "We must have a written prototype in this case.");
673
1.84k
      if (FT->isConst())
674
17
        POut << " const";
675
1.84k
      if (FT->isVolatile())
676
2
        POut << " volatile";
677
1.84k
      RefQualifierKind Ref = MD->getRefQualifier();
678
1.84k
      if (Ref == RQ_LValue)
679
1
        POut << " &";
680
1.84k
      else if (Ref == RQ_RValue)
681
1
        POut << " &&";
682
1.84k
    }
683
684
1.93k
    typedef SmallVector<const ClassTemplateSpecializationDecl *, 8> SpecsTy;
685
1.93k
    SpecsTy Specs;
686
1.93k
    const DeclContext *Ctx = FD->getDeclContext();
687
5.31k
    while (Ctx && isa<NamedDecl>(Ctx)) {
688
3.37k
      const ClassTemplateSpecializationDecl *Spec
689
3.37k
                               = dyn_cast<ClassTemplateSpecializationDecl>(Ctx);
690
3.37k
      if (Spec && 
!Spec->isExplicitSpecialization()12
)
691
11
        Specs.push_back(Spec);
692
3.37k
      Ctx = Ctx->getParent();
693
3.37k
    }
694
695
1.93k
    std::string TemplateParams;
696
1.93k
    llvm::raw_string_ostream TOut(TemplateParams);
697
1.93k
    for (SpecsTy::reverse_iterator I = Specs.rbegin(), E = Specs.rend();
698
1.94k
         I != E; 
++I11
) {
699
11
      const TemplateParameterList *Params
700
11
                  = (*I)->getSpecializedTemplate()->getTemplateParameters();
701
11
      const TemplateArgumentList &Args = (*I)->getTemplateArgs();
702
11
      assert(Params->size() == Args.size());
703
23
      for (unsigned i = 0, numParams = Params->size(); i != numParams; 
++i12
) {
704
12
        StringRef Param = Params->getParam(i)->getName();
705
12
        if (Param.empty()) 
continue0
;
706
12
        TOut << Param << " = ";
707
12
        Args.get(i).print(Policy, TOut);
708
12
        TOut << ", ";
709
12
      }
710
11
    }
711
712
1.93k
    FunctionTemplateSpecializationInfo *FSI
713
1.93k
                                          = FD->getTemplateSpecializationInfo();
714
1.93k
    if (FSI && 
!FSI->isExplicitSpecialization()24
) {
715
23
      const TemplateParameterList* Params
716
23
                                  = FSI->getTemplate()->getTemplateParameters();
717
23
      const TemplateArgumentList* Args = FSI->TemplateArguments;
718
23
      assert(Params->size() == Args->size());
719
56
      for (unsigned i = 0, e = Params->size(); i != e; 
++i33
) {
720
33
        StringRef Param = Params->getParam(i)->getName();
721
33
        if (Param.empty()) 
continue1
;
722
32
        TOut << Param << " = ";
723
32
        Args->get(i).print(Policy, TOut);
724
32
        TOut << ", ";
725
32
      }
726
23
    }
727
728
1.93k
    TOut.flush();
729
1.93k
    if (!TemplateParams.empty()) {
730
      // remove the trailing comma and space
731
32
      TemplateParams.resize(TemplateParams.size() - 2);
732
32
      POut << " [" << TemplateParams << "]";
733
32
    }
734
735
1.93k
    POut.flush();
736
737
    // Print "auto" for all deduced return types. This includes C++1y return
738
    // type deduction and lambdas. For trailing return types resolve the
739
    // decltype expression. Otherwise print the real type when this is
740
    // not a constructor or destructor.
741
1.93k
    if (isa<CXXMethodDecl>(FD) &&
742
1.84k
         cast<CXXMethodDecl>(FD)->getParent()->isLambda())
743
6
      Proto = "auto " + Proto;
744
1.92k
    else if (FT && 
FT->getReturnType()->getAs<DecltypeType>()1.90k
)
745
1
      FT->getReturnType()
746
1
          ->getAs<DecltypeType>()
747
1
          ->getUnderlyingType()
748
1
          .getAsStringInternal(Proto, Policy);
749
1.92k
    else if (!isa<CXXConstructorDecl>(FD) && 
!isa<CXXDestructorDecl>(FD)1.91k
)
750
1.77k
      AFT->getReturnType().getAsStringInternal(Proto, Policy);
751
752
1.93k
    Out << Proto;
753
754
1.93k
    return std::string(Name);
755
1.93k
  }
756
171
  if (const CapturedDecl *CD = dyn_cast<CapturedDecl>(CurrentDecl)) {
757
22
    for (const DeclContext *DC = CD->getParent(); DC; 
DC = DC->getParent()3
)
758
      // Skip to its enclosing function or method, but not its enclosing
759
      // CapturedDecl.
760
22
      if (DC->isFunctionOrMethod() && (DC->getDeclKind() != Decl::Captured)) {
761
19
        const Decl *D = Decl::castFromDeclContext(DC);
762
19
        return ComputeName(IK, D);
763
19
      }
764
0
    llvm_unreachable("CapturedDecl not inside a function or method");
765
152
  }
766
152
  if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) {
767
108
    SmallString<256> Name;
768
108
    llvm::raw_svector_ostream Out(Name);
769
92
    Out << (MD->isInstanceMethod() ? '-' : 
'+'16
);
770
108
    Out << '[';
771
772
    // For incorrect code, there might not be an ObjCInterfaceDecl.  Do
773
    // a null check to avoid a crash.
774
108
    if (const ObjCInterfaceDecl *ID = MD->getClassInterface())
775
107
      Out << *ID;
776
777
108
    if (const ObjCCategoryImplDecl *CID =
778
7
        dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext()))
779
7
      Out << '(' << *CID << ')';
780
781
108
    Out <<  ' ';
782
108
    MD->getSelector().print(Out);
783
108
    Out <<  ']';
784
785
108
    return std::string(Name);
786
108
  }
787
44
  if (isa<TranslationUnitDecl>(CurrentDecl) && 
IK == PrettyFunction20
) {
788
    // __PRETTY_FUNCTION__ -> "top level", the others produce an empty string.
789
2
    return "top level";
790
2
  }
791
42
  return "";
792
42
}
793
794
void APNumericStorage::setIntValue(const ASTContext &C,
795
10.7M
                                   const llvm::APInt &Val) {
796
10.7M
  if (hasAllocation())
797
0
    C.Deallocate(pVal);
798
799
10.7M
  BitWidth = Val.getBitWidth();
800
10.7M
  unsigned NumWords = Val.getNumWords();
801
10.7M
  const uint64_t* Words = Val.getRawData();
802
10.7M
  if (NumWords > 1) {
803
3.39k
    pVal = new (C) uint64_t[NumWords];
804
3.39k
    std::copy(Words, Words + NumWords, pVal);
805
10.7M
  } else if (NumWords == 1)
806
10.7M
    VAL = Words[0];
807
0
  else
808
0
    VAL = 0;
809
10.7M
}
810
811
IntegerLiteral::IntegerLiteral(const ASTContext &C, const llvm::APInt &V,
812
                               QualType type, SourceLocation l)
813
10.3M
    : Expr(IntegerLiteralClass, type, VK_RValue, OK_Ordinary), Loc(l) {
814
10.3M
  assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
815
10.3M
  assert(V.getBitWidth() == C.getIntWidth(type) &&
816
10.3M
         "Integer type is not the correct size for constant.");
817
10.3M
  setValue(C, V);
818
10.3M
  setDependence(ExprDependence::None);
819
10.3M
}
820
821
IntegerLiteral *
822
IntegerLiteral::Create(const ASTContext &C, const llvm::APInt &V,
823
10.3M
                       QualType type, SourceLocation l) {
824
10.3M
  return new (C) IntegerLiteral(C, V, type, l);
825
10.3M
}
826
827
IntegerLiteral *
828
311k
IntegerLiteral::Create(const ASTContext &C, EmptyShell Empty) {
829
311k
  return new (C) IntegerLiteral(Empty);
830
311k
}
831
832
FixedPointLiteral::FixedPointLiteral(const ASTContext &C, const llvm::APInt &V,
833
                                     QualType type, SourceLocation l,
834
                                     unsigned Scale)
835
    : Expr(FixedPointLiteralClass, type, VK_RValue, OK_Ordinary), Loc(l),
836
816
      Scale(Scale) {
837
816
  assert(type->isFixedPointType() && "Illegal type in FixedPointLiteral");
838
816
  assert(V.getBitWidth() == C.getTypeInfo(type).Width &&
839
816
         "Fixed point type is not the correct size for constant.");
840
816
  setValue(C, V);
841
816
  setDependence(ExprDependence::None);
842
816
}
843
844
FixedPointLiteral *FixedPointLiteral::CreateFromRawInt(const ASTContext &C,
845
                                                       const llvm::APInt &V,
846
                                                       QualType type,
847
                                                       SourceLocation l,
848
808
                                                       unsigned Scale) {
849
808
  return new (C) FixedPointLiteral(C, V, type, l, Scale);
850
808
}
851
852
FixedPointLiteral *FixedPointLiteral::Create(const ASTContext &C,
853
56
                                             EmptyShell Empty) {
854
56
  return new (C) FixedPointLiteral(Empty);
855
56
}
856
857
128
std::string FixedPointLiteral::getValueAsString(unsigned Radix) const {
858
  // Currently the longest decimal number that can be printed is the max for an
859
  // unsigned long _Accum: 4294967295.99999999976716935634613037109375
860
  // which is 43 characters.
861
128
  SmallString<64> S;
862
128
  FixedPointValueToString(
863
128
      S, llvm::APSInt::getUnsigned(getValue().getZExtValue()), Scale);
864
128
  return std::string(S.str());
865
128
}
866
867
FloatingLiteral::FloatingLiteral(const ASTContext &C, const llvm::APFloat &V,
868
                                 bool isexact, QualType Type, SourceLocation L)
869
37.2k
    : Expr(FloatingLiteralClass, Type, VK_RValue, OK_Ordinary), Loc(L) {
870
37.2k
  setSemantics(V.getSemantics());
871
37.2k
  FloatingLiteralBits.IsExact = isexact;
872
37.2k
  setValue(C, V);
873
37.2k
  setDependence(ExprDependence::None);
874
37.2k
}
875
876
FloatingLiteral::FloatingLiteral(const ASTContext &C, EmptyShell Empty)
877
1.55k
  : Expr(FloatingLiteralClass, Empty) {
878
1.55k
  setRawSemantics(llvm::APFloatBase::S_IEEEhalf);
879
1.55k
  FloatingLiteralBits.IsExact = false;
880
1.55k
}
881
882
FloatingLiteral *
883
FloatingLiteral::Create(const ASTContext &C, const llvm::APFloat &V,
884
37.2k
                        bool isexact, QualType Type, SourceLocation L) {
885
37.2k
  return new (C) FloatingLiteral(C, V, isexact, Type, L);
886
37.2k
}
887
888
FloatingLiteral *
889
1.55k
FloatingLiteral::Create(const ASTContext &C, EmptyShell Empty) {
890
1.55k
  return new (C) FloatingLiteral(C, Empty);
891
1.55k
}
892
893
/// getValueAsApproximateDouble - This returns the value as an inaccurate
894
/// double.  Note that this may cause loss of precision, but is useful for
895
/// debugging dumps, etc.
896
176
double FloatingLiteral::getValueAsApproximateDouble() const {
897
176
  llvm::APFloat V = getValue();
898
176
  bool ignored;
899
176
  V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
900
176
            &ignored);
901
176
  return V.convertToDouble();
902
176
}
903
904
unsigned StringLiteral::mapCharByteWidth(TargetInfo const &Target,
905
4.08M
                                         StringKind SK) {
906
4.08M
  unsigned CharByteWidth = 0;
907
4.08M
  switch (SK) {
908
4.08M
  case Ascii:
909
4.08M
  case UTF8:
910
4.08M
    CharByteWidth = Target.getCharWidth();
911
4.08M
    break;
912
1.09k
  case Wide:
913
1.09k
    CharByteWidth = Target.getWCharWidth();
914
1.09k
    break;
915
131
  case UTF16:
916
131
    CharByteWidth = Target.getChar16Width();
917
131
    break;
918
127
  case UTF32:
919
127
    CharByteWidth = Target.getChar32Width();
920
127
    break;
921
4.08M
  }
922
4.08M
  assert((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple");
923
4.08M
  CharByteWidth /= 8;
924
4.08M
  assert((CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) &&
925
4.08M
         "The only supported character byte widths are 1,2 and 4!");
926
4.08M
  return CharByteWidth;
927
4.08M
}
928
929
StringLiteral::StringLiteral(const ASTContext &Ctx, StringRef Str,
930
                             StringKind Kind, bool Pascal, QualType Ty,
931
                             const SourceLocation *Loc,
932
                             unsigned NumConcatenated)
933
4.07M
    : Expr(StringLiteralClass, Ty, VK_LValue, OK_Ordinary) {
934
4.07M
  assert(Ctx.getAsConstantArrayType(Ty) &&
935
4.07M
         "StringLiteral must be of constant array type!");
936
4.07M
  unsigned CharByteWidth = mapCharByteWidth(Ctx.getTargetInfo(), Kind);
937
4.07M
  unsigned ByteLength = Str.size();
938
4.07M
  assert((ByteLength % CharByteWidth == 0) &&
939
4.07M
         "The size of the data must be a multiple of CharByteWidth!");
940
941
  // Avoid the expensive division. The compiler should be able to figure it
942
  // out by itself. However as of clang 7, even with the appropriate
943
  // llvm_unreachable added just here, it is not able to do so.
944
4.07M
  unsigned Length;
945
4.07M
  switch (CharByteWidth) {
946
4.06M
  case 1:
947
4.06M
    Length = ByteLength;
948
4.06M
    break;
949
445
  case 2:
950
445
    Length = ByteLength / 2;
951
445
    break;
952
902
  case 4:
953
902
    Length = ByteLength / 4;
954
902
    break;
955
0
  default:
956
0
    llvm_unreachable("Unsupported character width!");
957
4.07M
  }
958
959
4.07M
  StringLiteralBits.Kind = Kind;
960
4.07M
  StringLiteralBits.CharByteWidth = CharByteWidth;
961
4.07M
  StringLiteralBits.IsPascal = Pascal;
962
4.07M
  StringLiteralBits.NumConcatenated = NumConcatenated;
963
4.07M
  *getTrailingObjects<unsigned>() = Length;
964
965
  // Initialize the trailing array of SourceLocation.
966
  // This is safe since SourceLocation is POD-like.
967
4.07M
  std::memcpy(getTrailingObjects<SourceLocation>(), Loc,
968
4.07M
              NumConcatenated * sizeof(SourceLocation));
969
970
  // Initialize the trailing array of char holding the string data.
971
4.07M
  std::memcpy(getTrailingObjects<char>(), Str.data(), ByteLength);
972
973
4.07M
  setDependence(ExprDependence::None);
974
4.07M
}
975
976
StringLiteral::StringLiteral(EmptyShell Empty, unsigned NumConcatenated,
977
                             unsigned Length, unsigned CharByteWidth)
978
12.8k
    : Expr(StringLiteralClass, Empty) {
979
12.8k
  StringLiteralBits.CharByteWidth = CharByteWidth;
980
12.8k
  StringLiteralBits.NumConcatenated = NumConcatenated;
981
12.8k
  *getTrailingObjects<unsigned>() = Length;
982
12.8k
}
983
984
StringLiteral *StringLiteral::Create(const ASTContext &Ctx, StringRef Str,
985
                                     StringKind Kind, bool Pascal, QualType Ty,
986
                                     const SourceLocation *Loc,
987
4.07M
                                     unsigned NumConcatenated) {
988
4.07M
  void *Mem = Ctx.Allocate(totalSizeToAlloc<unsigned, SourceLocation, char>(
989
4.07M
                               1, NumConcatenated, Str.size()),
990
4.07M
                           alignof(StringLiteral));
991
4.07M
  return new (Mem)
992
4.07M
      StringLiteral(Ctx, Str, Kind, Pascal, Ty, Loc, NumConcatenated);
993
4.07M
}
994
995
StringLiteral *StringLiteral::CreateEmpty(const ASTContext &Ctx,
996
                                          unsigned NumConcatenated,
997
                                          unsigned Length,
998
12.8k
                                          unsigned CharByteWidth) {
999
12.8k
  void *Mem = Ctx.Allocate(totalSizeToAlloc<unsigned, SourceLocation, char>(
1000
12.8k
                               1, NumConcatenated, Length * CharByteWidth),
1001
12.8k
                           alignof(StringLiteral));
1002
12.8k
  return new (Mem)
1003
12.8k
      StringLiteral(EmptyShell(), NumConcatenated, Length, CharByteWidth);
1004
12.8k
}
1005
1006
1.03k
void StringLiteral::outputString(raw_ostream &OS) const {
1007
1.03k
  switch (getKind()) {
1008
982
  case Ascii: break; // no prefix.
1009
27
  case Wide:  OS << 'L'; break;
1010
9
  case UTF8:  OS << "u8"; break;
1011
8
  case UTF16: OS << 'u'; break;
1012
7
  case UTF32: OS << 'U'; break;
1013
1.03k
  }
1014
1.03k
  OS << '"';
1015
1.03k
  static const char Hex[] = "0123456789ABCDEF";
1016
1017
1.03k
  unsigned LastSlashX = getLength();
1018
10.9k
  for (unsigned I = 0, N = getLength(); I != N; 
++I9.88k
) {
1019
9.88k
    switch (uint32_t Char = getCodeUnit(I)) {
1020
9.78k
    default:
1021
      // FIXME: Convert UTF-8 back to codepoints before rendering.
1022
1023
      // Convert UTF-16 surrogate pairs back to codepoints before rendering.
1024
      // Leave invalid surrogates alone; we'll use \x for those.
1025
9.78k
      if (getKind() == UTF16 && 
I != N - 132
&&
Char >= 0xd80025
&&
1026
1
          Char <= 0xdbff) {
1027
1
        uint32_t Trail = getCodeUnit(I + 1);
1028
1
        if (Trail >= 0xdc00 && Trail <= 0xdfff) {
1029
1
          Char = 0x10000 + ((Char - 0xd800) << 10) + (Trail - 0xdc00);
1030
1
          ++I;
1031
1
        }
1032
1
      }
1033
1034
9.78k
      if (Char > 0xff) {
1035
        // If this is a wide string, output characters over 0xff using \x
1036
        // escapes. Otherwise, this is a UTF-16 or UTF-32 string, and Char is a
1037
        // codepoint: use \x escapes for invalid codepoints.
1038
26
        if (getKind() == Wide ||
1039
13
            (Char >= 0xd800 && 
Char <= 0xdfff5
) || Char >= 0x110000) {
1040
          // FIXME: Is this the best way to print wchar_t?
1041
13
          OS << "\\x";
1042
13
          int Shift = 28;
1043
46
          while ((Char >> Shift) == 0)
1044
33
            Shift -= 4;
1045
84
          for (/**/; Shift >= 0; 
Shift -= 471
)
1046
71
            OS << Hex[(Char >> Shift) & 15];
1047
13
          LastSlashX = I;
1048
13
          break;
1049
13
        }
1050
1051
13
        if (Char > 0xffff)
1052
5
          OS << "\\U00"
1053
5
             << Hex[(Char >> 20) & 15]
1054
5
             << Hex[(Char >> 16) & 15];
1055
8
        else
1056
8
          OS << "\\u";
1057
13
        OS << Hex[(Char >> 12) & 15]
1058
13
           << Hex[(Char >>  8) & 15]
1059
13
           << Hex[(Char >>  4) & 15]
1060
13
           << Hex[(Char >>  0) & 15];
1061
13
        break;
1062
13
      }
1063
1064
      // If we used \x... for the previous character, and this character is a
1065
      // hexadecimal digit, prevent it being slurped as part of the \x.
1066
9.75k
      if (LastSlashX + 1 == I) {
1067
3
        switch (Char) {
1068
1
          case '0': case '1': case '2': case '3': case '4':
1069
1
          case '5': case '6': case '7': case '8': case '9':
1070
2
          
case 'a': 1
case 'b': 1
case 'c': 1
case 'd': 1
case 'e': 1
case 'f':
1071
2
          case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
1072
2
            OS << "\"\"";
1073
3
        }
1074
3
      }
1075
1076
9.75k
      assert(Char <= 0xff &&
1077
9.75k
             "Characters above 0xff should already have been handled.");
1078
1079
9.75k
      if (isPrintable(Char))
1080
9.71k
        OS << (char)Char;
1081
39
      else  // Output anything hard as an octal escape.
1082
39
        OS << '\\'
1083
39
           << (char)('0' + ((Char >> 6) & 7))
1084
39
           << (char)('0' + ((Char >> 3) & 7))
1085
39
           << (char)('0' + ((Char >> 0) & 7));
1086
9.75k
      break;
1087
    // Handle some common non-printable cases to make dumps prettier.
1088
26
    case '\\': OS << "\\\\"; break;
1089
19
    case '"': OS << "\\\""; break;
1090
18
    case '\a': OS << "\\a"; break;
1091
18
    case '\b': OS << "\\b"; break;
1092
2
    case '\f': OS << "\\f"; break;
1093
2
    case '\n': OS << "\\n"; break;
1094
2
    case '\r': OS << "\\r"; break;
1095
18
    case '\t': OS << "\\t"; break;
1096
2
    case '\v': OS << "\\v"; break;
1097
9.88k
    }
1098
9.88k
  }
1099
1.03k
  OS << '"';
1100
1.03k
}
1101
1102
/// getLocationOfByte - Return a source location that points to the specified
1103
/// byte of this string literal.
1104
///
1105
/// Strings are amazingly complex.  They can be formed from multiple tokens and
1106
/// can have escape sequences in them in addition to the usual trigraph and
1107
/// escaped newline business.  This routine handles this complexity.
1108
///
1109
/// The *StartToken sets the first token to be searched in this function and
1110
/// the *StartTokenByteOffset is the byte offset of the first token. Before
1111
/// returning, it updates the *StartToken to the TokNo of the token being found
1112
/// and sets *StartTokenByteOffset to the byte offset of the token in the
1113
/// string.
1114
/// Using these two parameters can reduce the time complexity from O(n^2) to
1115
/// O(n) if one wants to get the location of byte for all the tokens in a
1116
/// string.
1117
///
1118
SourceLocation
1119
StringLiteral::getLocationOfByte(unsigned ByteNo, const SourceManager &SM,
1120
                                 const LangOptions &Features,
1121
                                 const TargetInfo &Target, unsigned *StartToken,
1122
39.2k
                                 unsigned *StartTokenByteOffset) const {
1123
39.2k
  assert((getKind() == StringLiteral::Ascii ||
1124
39.2k
          getKind() == StringLiteral::UTF8) &&
1125
39.2k
         "Only narrow string literals are currently supported");
1126
1127
  // Loop over all of the tokens in this string until we find the one that
1128
  // contains the byte we're looking for.
1129
39.2k
  unsigned TokNo = 0;
1130
39.2k
  unsigned StringOffset = 0;
1131
39.2k
  if (StartToken)
1132
26.7k
    TokNo = *StartToken;
1133
39.2k
  if (StartTokenByteOffset) {
1134
26.7k
    StringOffset = *StartTokenByteOffset;
1135
26.7k
    ByteNo -= StringOffset;
1136
26.7k
  }
1137
41.5k
  while (1) {
1138
41.5k
    assert(TokNo < getNumConcatenated() && "Invalid byte number!");
1139
41.5k
    SourceLocation StrTokLoc = getStrTokenLoc(TokNo);
1140
1141
    // Get the spelling of the string so that we can get the data that makes up
1142
    // the string literal, not the identifier for the macro it is potentially
1143
    // expanded through.
1144
41.5k
    SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc);
1145
1146
    // Re-lex the token to get its length and original spelling.
1147
41.5k
    std::pair<FileID, unsigned> LocInfo =
1148
41.5k
        SM.getDecomposedLoc(StrTokSpellingLoc);
1149
41.5k
    bool Invalid = false;
1150
41.5k
    StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid);
1151
41.5k
    if (Invalid) {
1152
0
      if (StartTokenByteOffset != nullptr)
1153
0
        *StartTokenByteOffset = StringOffset;
1154
0
      if (StartToken != nullptr)
1155
0
        *StartToken = TokNo;
1156
0
      return StrTokSpellingLoc;
1157
0
    }
1158
1159
41.5k
    const char *StrData = Buffer.data()+LocInfo.second;
1160
1161
    // Create a lexer starting at the beginning of this token.
1162
41.5k
    Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), Features,
1163
41.5k
                   Buffer.begin(), StrData, Buffer.end());
1164
41.5k
    Token TheTok;
1165
41.5k
    TheLexer.LexFromRawLexer(TheTok);
1166
1167
    // Use the StringLiteralParser to compute the length of the string in bytes.
1168
41.5k
    StringLiteralParser SLP(TheTok, SM, Features, Target);
1169
41.5k
    unsigned TokNumBytes = SLP.GetStringLength();
1170
1171
    // If the byte is in this token, return the location of the byte.
1172
41.5k
    if (ByteNo < TokNumBytes ||
1173
39.2k
        
(4.19k
ByteNo == TokNumBytes4.19k
&&
TokNo == getNumConcatenated() - 11.99k
)) {
1174
39.2k
      unsigned Offset = SLP.getOffsetOfStringByte(TheTok, ByteNo);
1175
1176
      // Now that we know the offset of the token in the spelling, use the
1177
      // preprocessor to get the offset in the original source.
1178
39.2k
      if (StartTokenByteOffset != nullptr)
1179
26.7k
        *StartTokenByteOffset = StringOffset;
1180
39.2k
      if (StartToken != nullptr)
1181
26.7k
        *StartToken = TokNo;
1182
39.2k
      return Lexer::AdvanceToTokenCharacter(StrTokLoc, Offset, SM, Features);
1183
39.2k
    }
1184
1185
    // Move to the next string token.
1186
2.29k
    StringOffset += TokNumBytes;
1187
2.29k
    ++TokNo;
1188
2.29k
    ByteNo -= TokNumBytes;
1189
2.29k
  }
1190
39.2k
}
1191
1192
/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1193
/// corresponds to, e.g. "sizeof" or "[pre]++".
1194
27.4k
StringRef UnaryOperator::getOpcodeStr(Opcode Op) {
1195
27.4k
  switch (Op) {
1196
27.4k
#define UNARY_OPERATION(Name, Spelling) case UO_##Name: return Spelling;
1197
0
#include "clang/AST/OperationKinds.def"
1198
27.4k
  }
1199
27.4k
  
llvm_unreachable0
("Unknown unary operator");
1200
27.4k
}
1201
1202
UnaryOperatorKind
1203
1.52k
UnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) {
1204
1.52k
  switch (OO) {
1205
0
  default: llvm_unreachable("No unary operator for overloaded function");
1206
156
  case OO_PlusPlus:   return Postfix ? 
UO_PostInc1
:
UO_PreInc155
;
1207
0
  case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec;
1208
267
  case OO_Amp:        return UO_AddrOf;
1209
1.01k
  case OO_Star:       return UO_Deref;
1210
0
  case OO_Plus:       return UO_Plus;
1211
15
  case OO_Minus:      return UO_Minus;
1212
56
  case OO_Tilde:      return UO_Not;
1213
1
  case OO_Exclaim:    return UO_LNot;
1214
22
  case OO_Coawait:    return UO_Coawait;
1215
1.52k
  }
1216
1.52k
}
1217
1218
2.87M
OverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) {
1219
2.87M
  switch (Opc) {
1220
492k
  
case UO_PostInc: 19.8k
case UO_PreInc: return OO_PlusPlus;
1221
143k
  
case UO_PostDec: 1.78k
case UO_PreDec: return OO_MinusMinus;
1222
238k
  case UO_AddrOf: return OO_Amp;
1223
1.20M
  case UO_Deref: return OO_Star;
1224
430
  case UO_Plus: return OO_Plus;
1225
17.2k
  case UO_Minus: return OO_Minus;
1226
88.4k
  case UO_Not: return OO_Tilde;
1227
688k
  case UO_LNot: return OO_Exclaim;
1228
901
  case UO_Coawait: return OO_Coawait;
1229
9
  default: return OO_None;
1230
2.87M
  }
1231
2.87M
}
1232
1233
1234
//===----------------------------------------------------------------------===//
1235
// Postfix Operators.
1236
//===----------------------------------------------------------------------===//
1237
1238
CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs,
1239
                   ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
1240
                   SourceLocation RParenLoc, FPOptionsOverride FPFeatures,
1241
                   unsigned MinNumArgs, ADLCallKind UsesADL)
1242
6.68M
    : Expr(SC, Ty, VK, OK_Ordinary), RParenLoc(RParenLoc) {
1243
6.68M
  NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
1244
6.68M
  unsigned NumPreArgs = PreArgs.size();
1245
6.68M
  CallExprBits.NumPreArgs = NumPreArgs;
1246
6.68M
  assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!");
1247
1248
6.68M
  unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC);
1249
6.68M
  CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects;
1250
6.68M
  assert((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) &&
1251
6.68M
         "OffsetToTrailingObjects overflow!");
1252
1253
6.68M
  CallExprBits.UsesADL = static_cast<bool>(UsesADL);
1254
1255
6.68M
  setCallee(Fn);
1256
6.68M
  for (unsigned I = 0; I != NumPreArgs; 
++I120
)
1257
120
    setPreArg(I, PreArgs[I]);
1258
17.3M
  for (unsigned I = 0; I != Args.size(); 
++I10.6M
)
1259
10.6M
    setArg(I, Args[I]);
1260
6.69M
  for (unsigned I = Args.size(); I != NumArgs; 
++I9.50k
)
1261
9.50k
    setArg(I, nullptr);
1262
1263
6.68M
  setDependence(computeDependence(this, PreArgs));
1264
1265
6.68M
  CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
1266
6.68M
  if (hasStoredFPFeatures())
1267
3.74k
    setStoredFPFeatures(FPFeatures);
1268
6.68M
}
1269
1270
CallExpr::CallExpr(StmtClass SC, unsigned NumPreArgs, unsigned NumArgs,
1271
                   bool HasFPFeatures, EmptyShell Empty)
1272
616k
    : Expr(SC, Empty), NumArgs(NumArgs) {
1273
616k
  CallExprBits.NumPreArgs = NumPreArgs;
1274
616k
  assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!");
1275
1276
616k
  unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC);
1277
616k
  CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects;
1278
616k
  assert((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) &&
1279
616k
         "OffsetToTrailingObjects overflow!");
1280
616k
  CallExprBits.HasFPFeatures = HasFPFeatures;
1281
616k
}
1282
1283
CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr *Fn,
1284
                           ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
1285
                           SourceLocation RParenLoc,
1286
                           FPOptionsOverride FPFeatures, unsigned MinNumArgs,
1287
5.07M
                           ADLCallKind UsesADL) {
1288
5.07M
  unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
1289
5.07M
  unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
1290
5.07M
      /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
1291
5.07M
  void *Mem =
1292
5.07M
      Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, alignof(CallExpr));
1293
5.07M
  return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
1294
5.07M
                            RParenLoc, FPFeatures, MinNumArgs, UsesADL);
1295
5.07M
}
1296
1297
CallExpr *CallExpr::CreateTemporary(void *Mem, Expr *Fn, QualType Ty,
1298
                                    ExprValueKind VK, SourceLocation RParenLoc,
1299
505k
                                    ADLCallKind UsesADL) {
1300
505k
  assert(!(reinterpret_cast<uintptr_t>(Mem) % alignof(CallExpr)) &&
1301
505k
         "Misaligned memory in CallExpr::CreateTemporary!");
1302
505k
  return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, /*Args=*/{}, Ty,
1303
505k
                            VK, RParenLoc, FPOptionsOverride(),
1304
505k
                            /*MinNumArgs=*/0, UsesADL);
1305
505k
}
1306
1307
CallExpr *CallExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
1308
422k
                                bool HasFPFeatures, EmptyShell Empty) {
1309
422k
  unsigned SizeOfTrailingObjects =
1310
422k
      CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, HasFPFeatures);
1311
422k
  void *Mem =
1312
422k
      Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, alignof(CallExpr));
1313
422k
  return new (Mem)
1314
422k
      CallExpr(CallExprClass, /*NumPreArgs=*/0, NumArgs, HasFPFeatures, Empty);
1315
422k
}
1316
1317
7.30M
unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) {
1318
7.30M
  switch (SC) {
1319
5.99M
  case CallExprClass:
1320
5.99M
    return sizeof(CallExpr);
1321
1.08M
  case CXXOperatorCallExprClass:
1322
1.08M
    return sizeof(CXXOperatorCallExpr);
1323
217k
  case CXXMemberCallExprClass:
1324
217k
    return sizeof(CXXMemberCallExpr);
1325
284
  case UserDefinedLiteralClass:
1326
284
    return sizeof(UserDefinedLiteral);
1327
121
  case CUDAKernelCallExprClass:
1328
121
    return sizeof(CUDAKernelCallExpr);
1329
0
  default:
1330
0
    llvm_unreachable("unexpected class deriving from CallExpr!");
1331
7.30M
  }
1332
7.30M
}
1333
1334
13.0M
Decl *Expr::getReferencedDeclOfCallee() {
1335
13.0M
  Expr *CEE = IgnoreParenImpCasts();
1336
1337
13.0M
  while (SubstNonTypeTemplateParmExpr *NTTP =
1338
0
             dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) {
1339
0
    CEE = NTTP->getReplacement()->IgnoreParenImpCasts();
1340
0
  }
1341
1342
  // If we're calling a dereference, look at the pointer instead.
1343
13.0M
  while (true) {
1344
13.0M
    if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) {
1345
1.95k
      if (BO->isPtrMemOp()) {
1346
1.91k
        CEE = BO->getRHS()->IgnoreParenImpCasts();
1347
1.91k
        continue;
1348
1.91k
      }
1349
13.0M
    } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) {
1350
16.6k
      if (UO->getOpcode() == UO_Deref || 
UO->getOpcode() == UO_AddrOf339
||
1351
16.6k
          
UO->getOpcode() == UO_Plus4
) {
1352
16.6k
        CEE = UO->getSubExpr()->IgnoreParenImpCasts();
1353
16.6k
        continue;
1354
16.6k
      }
1355
13.0M
    }
1356
13.0M
    break;
1357
13.0M
  }
1358
1359
13.0M
  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE))
1360
11.5M
    return DRE->getDecl();
1361
1.43M
  if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE))
1362
1.30M
    return ME->getMemberDecl();
1363
131k
  if (auto *BE = dyn_cast<BlockExpr>(CEE))
1364
2.34k
    return BE->getBlockDecl();
1365
1366
128k
  return nullptr;
1367
128k
}
1368
1369
/// If this is a call to a builtin, return the builtin ID. If not, return 0.
1370
3.61M
unsigned CallExpr::getBuiltinCallee() const {
1371
3.61M
  auto *FDecl =
1372
3.61M
      dyn_cast_or_null<FunctionDecl>(getCallee()->getReferencedDeclOfCallee());
1373
3.57M
  return FDecl ? FDecl->getBuiltinID() : 
030.9k
;
1374
3.61M
}
1375
1376
3.19M
bool CallExpr::isUnevaluatedBuiltinCall(const ASTContext &Ctx) const {
1377
3.19M
  if (unsigned BI = getBuiltinCallee())
1378
1.45M
    return Ctx.BuiltinInfo.isUnevaluated(BI);
1379
1.74M
  return false;
1380
1.74M
}
1381
1382
1.23M
QualType CallExpr::getCallReturnType(const ASTContext &Ctx) const {
1383
1.23M
  const Expr *Callee = getCallee();
1384
1.23M
  QualType CalleeType = Callee->getType();
1385
1.23M
  if (const auto *FnTypePtr = CalleeType->getAs<PointerType>()) {
1386
1.01M
    CalleeType = FnTypePtr->getPointeeType();
1387
220k
  } else if (const auto *BPT = CalleeType->getAs<BlockPointerType>()) {
1388
1.55k
    CalleeType = BPT->getPointeeType();
1389
218k
  } else if (CalleeType->isSpecificPlaceholderType(BuiltinType::BoundMember)) {
1390
217k
    if (isa<CXXPseudoDestructorExpr>(Callee->IgnoreParens()))
1391
183
      return Ctx.VoidTy;
1392
1393
    // This should never be overloaded and so should never return null.
1394
217k
    CalleeType = Expr::findBoundMemberType(Callee);
1395
217k
  }
1396
1397
1.23M
  const FunctionType *FnType = CalleeType->castAs<FunctionType>();
1398
1.23M
  return FnType->getReturnType();
1399
1.23M
}
1400
1401
434k
const Attr *CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const {
1402
  // If the return type is a struct, union, or enum that is marked nodiscard,
1403
  // then return the return type attribute.
1404
434k
  if (const TagDecl *TD = getCallReturnType(Ctx)->getAsTagDecl())
1405
7.38k
    if (const auto *A = TD->getAttr<WarnUnusedResultAttr>())
1406
92
      return A;
1407
1408
  // Otherwise, see if the callee is marked nodiscard and return that attribute
1409
  // instead.
1410
434k
  const Decl *D = getCalleeDecl();
1411
434k
  return D ? D->getAttr<WarnUnusedResultAttr>() : 
nullptr0
;
1412
434k
}
1413
1414
20.6M
SourceLocation CallExpr::getBeginLoc() const {
1415
20.6M
  if (isa<CXXOperatorCallExpr>(this))
1416
35
    return cast<CXXOperatorCallExpr>(this)->getBeginLoc();
1417
1418
20.6M
  SourceLocation begin = getCallee()->getBeginLoc();
1419
20.6M
  if (begin.isInvalid() && 
getNumArgs() > 0985
&&
getArg(0)898
)
1420
898
    begin = getArg(0)->getBeginLoc();
1421
20.6M
  return begin;
1422
20.6M
}
1423
2.48M
SourceLocation CallExpr::getEndLoc() const {
1424
2.48M
  if (isa<CXXOperatorCallExpr>(this))
1425
0
    return cast<CXXOperatorCallExpr>(this)->getEndLoc();
1426
1427
2.48M
  SourceLocation end = getRParenLoc();
1428
2.48M
  if (end.isInvalid() && 
getNumArgs() > 00
&&
getArg(getNumArgs() - 1)0
)
1429
0
    end = getArg(getNumArgs() - 1)->getEndLoc();
1430
2.48M
  return end;
1431
2.48M
}
1432
1433
OffsetOfExpr *OffsetOfExpr::Create(const ASTContext &C, QualType type,
1434
                                   SourceLocation OperatorLoc,
1435
                                   TypeSourceInfo *tsi,
1436
                                   ArrayRef<OffsetOfNode> comps,
1437
                                   ArrayRef<Expr*> exprs,
1438
327
                                   SourceLocation RParenLoc) {
1439
327
  void *Mem = C.Allocate(
1440
327
      totalSizeToAlloc<OffsetOfNode, Expr *>(comps.size(), exprs.size()));
1441
1442
327
  return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, comps, exprs,
1443
327
                                RParenLoc);
1444
327
}
1445
1446
OffsetOfExpr *OffsetOfExpr::CreateEmpty(const ASTContext &C,
1447
3
                                        unsigned numComps, unsigned numExprs) {
1448
3
  void *Mem =
1449
3
      C.Allocate(totalSizeToAlloc<OffsetOfNode, Expr *>(numComps, numExprs));
1450
3
  return new (Mem) OffsetOfExpr(numComps, numExprs);
1451
3
}
1452
1453
OffsetOfExpr::OffsetOfExpr(const ASTContext &C, QualType type,
1454
                           SourceLocation OperatorLoc, TypeSourceInfo *tsi,
1455
                           ArrayRef<OffsetOfNode> comps, ArrayRef<Expr *> exprs,
1456
                           SourceLocation RParenLoc)
1457
    : Expr(OffsetOfExprClass, type, VK_RValue, OK_Ordinary),
1458
      OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi),
1459
327
      NumComps(comps.size()), NumExprs(exprs.size()) {
1460
736
  for (unsigned i = 0; i != comps.size(); 
++i409
)
1461
409
    setComponent(i, comps[i]);
1462
368
  for (unsigned i = 0; i != exprs.size(); 
++i41
)
1463
41
    setIndexExpr(i, exprs[i]);
1464
1465
327
  setDependence(computeDependence(this));
1466
327
}
1467
1468
17
IdentifierInfo *OffsetOfNode::getFieldName() const {
1469
17
  assert(getKind() == Field || getKind() == Identifier);
1470
17
  if (getKind() == Field)
1471
2
    return getField()->getIdentifier();
1472
1473
15
  return reinterpret_cast<IdentifierInfo *> (Data & ~(uintptr_t)Mask);
1474
15
}
1475
1476
UnaryExprOrTypeTraitExpr::UnaryExprOrTypeTraitExpr(
1477
    UnaryExprOrTypeTrait ExprKind, Expr *E, QualType resultType,
1478
    SourceLocation op, SourceLocation rp)
1479
    : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary),
1480
19.5k
      OpLoc(op), RParenLoc(rp) {
1481
19.5k
  assert(ExprKind <= UETT_Last && "invalid enum value!");
1482
19.5k
  UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
1483
19.5k
  assert(static_cast<unsigned>(ExprKind) == UnaryExprOrTypeTraitExprBits.Kind &&
1484
19.5k
         "UnaryExprOrTypeTraitExprBits.Kind overflow!");
1485
19.5k
  UnaryExprOrTypeTraitExprBits.IsType = false;
1486
19.5k
  Argument.Ex = E;
1487
19.5k
  setDependence(computeDependence(this));
1488
19.5k
}
1489
1490
MemberExpr::MemberExpr(Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
1491
                       ValueDecl *MemberDecl,
1492
                       const DeclarationNameInfo &NameInfo, QualType T,
1493
                       ExprValueKind VK, ExprObjectKind OK,
1494
                       NonOdrUseReason NOUR)
1495
    : Expr(MemberExprClass, T, VK, OK), Base(Base), MemberDecl(MemberDecl),
1496
1.28M
      MemberDNLoc(NameInfo.getInfo()), MemberLoc(NameInfo.getLoc()) {
1497
1.28M
  assert(!NameInfo.getName() ||
1498
1.28M
         MemberDecl->getDeclName() == NameInfo.getName());
1499
1.28M
  MemberExprBits.IsArrow = IsArrow;
1500
1.28M
  MemberExprBits.HasQualifierOrFoundDecl = false;
1501
1.28M
  MemberExprBits.HasTemplateKWAndArgsInfo = false;
1502
1.28M
  MemberExprBits.HadMultipleCandidates = false;
1503
1.28M
  MemberExprBits.NonOdrUseReason = NOUR;
1504
1.28M
  MemberExprBits.OperatorLoc = OperatorLoc;
1505
1.28M
  setDependence(computeDependence(this));
1506
1.28M
}
1507
1508
MemberExpr *MemberExpr::Create(
1509
    const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc,
1510
    NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
1511
    ValueDecl *MemberDecl, DeclAccessPair FoundDecl,
1512
    DeclarationNameInfo NameInfo, const TemplateArgumentListInfo *TemplateArgs,
1513
1.28M
    QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR) {
1514
1.28M
  bool HasQualOrFound = QualifierLoc || 
FoundDecl.getDecl() != MemberDecl1.28M
||
1515
1.26M
                        FoundDecl.getAccess() != MemberDecl->getAccess();
1516
1.28M
  bool HasTemplateKWAndArgsInfo = TemplateArgs || 
TemplateKWLoc.isValid()1.28M
;
1517
1.28M
  std::size_t Size =
1518
1.28M
      totalSizeToAlloc<MemberExprNameQualifier, ASTTemplateKWAndArgsInfo,
1519
1.28M
                       TemplateArgumentLoc>(
1520
1.28M
          HasQualOrFound ? 
141.6k
:
01.24M
, HasTemplateKWAndArgsInfo ?
11.96k
: 0,
1521
1.28M
          TemplateArgs ? 
TemplateArgs->size()1.89k
: 0);
1522
1523
1.28M
  void *Mem = C.Allocate(Size, alignof(MemberExpr));
1524
1.28M
  MemberExpr *E = new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, MemberDecl,
1525
1.28M
                                       NameInfo, T, VK, OK, NOUR);
1526
1527
  // FIXME: remove remaining dependence computation to computeDependence().
1528
1.28M
  auto Deps = E->getDependence();
1529
1.28M
  if (HasQualOrFound) {
1530
    // FIXME: Wrong. We should be looking at the member declaration we found.
1531
41.6k
    if (QualifierLoc && 
QualifierLoc.getNestedNameSpecifier()->isDependent()9.57k
)
1532
8
      Deps |= ExprDependence::TypeValueInstantiation;
1533
41.6k
    else if (QualifierLoc &&
1534
9.56k
             QualifierLoc.getNestedNameSpecifier()->isInstantiationDependent())
1535
0
      Deps |= ExprDependence::Instantiation;
1536
1537
41.6k
    E->MemberExprBits.HasQualifierOrFoundDecl = true;
1538
1539
41.6k
    MemberExprNameQualifier *NQ =
1540
41.6k
        E->getTrailingObjects<MemberExprNameQualifier>();
1541
41.6k
    NQ->QualifierLoc = QualifierLoc;
1542
41.6k
    NQ->FoundDecl = FoundDecl;
1543
41.6k
  }
1544
1545
1.28M
  E->MemberExprBits.HasTemplateKWAndArgsInfo =
1546
1.28M
      TemplateArgs || 
TemplateKWLoc.isValid()1.28M
;
1547
1548
1.28M
  if (TemplateArgs) {
1549
1.89k
    auto TemplateArgDeps = TemplateArgumentDependence::None;
1550
1.89k
    E->getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1551
1.89k
        TemplateKWLoc, *TemplateArgs,
1552
1.89k
        E->getTrailingObjects<TemplateArgumentLoc>(), TemplateArgDeps);
1553
1.89k
    if (TemplateArgDeps & TemplateArgumentDependence::Instantiation)
1554
0
      Deps |= ExprDependence::Instantiation;
1555
1.28M
  } else if (TemplateKWLoc.isValid()) {
1556
65
    E->getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1557
65
        TemplateKWLoc);
1558
65
  }
1559
1.28M
  E->setDependence(Deps);
1560
1561
1.28M
  return E;
1562
1.28M
}
1563
1564
MemberExpr *MemberExpr::CreateEmpty(const ASTContext &Context,
1565
                                    bool HasQualifier, bool HasFoundDecl,
1566
                                    bool HasTemplateKWAndArgsInfo,
1567
153k
                                    unsigned NumTemplateArgs) {
1568
153k
  assert((!NumTemplateArgs || HasTemplateKWAndArgsInfo) &&
1569
153k
         "template args but no template arg info?");
1570
153k
  bool HasQualOrFound = HasQualifier || 
HasFoundDecl151k
;
1571
153k
  std::size_t Size =
1572
153k
      totalSizeToAlloc<MemberExprNameQualifier, ASTTemplateKWAndArgsInfo,
1573
149k
                       TemplateArgumentLoc>(HasQualOrFound ? 
14.22k
: 0,
1574
153k
                                            HasTemplateKWAndArgsInfo ? 
118
: 0,
1575
153k
                                            NumTemplateArgs);
1576
153k
  void *Mem = Context.Allocate(Size, alignof(MemberExpr));
1577
153k
  return new (Mem) MemberExpr(EmptyShell());
1578
153k
}
1579
1580
86
void MemberExpr::setMemberDecl(ValueDecl *D) {
1581
86
  MemberDecl = D;
1582
86
  setDependence(computeDependence(this));
1583
86
}
1584
1585
4.49M
SourceLocation MemberExpr::getBeginLoc() const {
1586
4.49M
  if (isImplicitAccess()) {
1587
1.80M
    if (hasQualifier())
1588
39.6k
      return getQualifierLoc().getBeginLoc();
1589
1.76M
    return MemberLoc;
1590
1.76M
  }
1591
1592
  // FIXME: We don't want this to happen. Rather, we should be able to
1593
  // detect all kinds of implicit accesses more cleanly.
1594
2.68M
  SourceLocation BaseStartLoc = getBase()->getBeginLoc();
1595
2.68M
  if (BaseStartLoc.isValid())
1596
2.68M
    return BaseStartLoc;
1597
1.04k
  return MemberLoc;
1598
1.04k
}
1599
635k
SourceLocation MemberExpr::getEndLoc() const {
1600
635k
  SourceLocation EndLoc = getMemberNameInfo().getEndLoc();
1601
635k
  if (hasExplicitTemplateArgs())
1602
1.96k
    EndLoc = getRAngleLoc();
1603
633k
  else if (EndLoc.isInvalid())
1604
8.84k
    EndLoc = getBase()->getEndLoc();
1605
635k
  return EndLoc;
1606
635k
}
1607
1608
23.6M
bool CastExpr::CastConsistency() const {
1609
23.6M
  switch (getCastKind()) {
1610
16.6k
  case CK_DerivedToBase:
1611
44.0k
  case CK_UncheckedDerivedToBase:
1612
44.1k
  case CK_DerivedToBaseMemberPointer:
1613
45.0k
  case CK_BaseToDerived:
1614
45.4k
  case CK_BaseToDerivedMemberPointer:
1615
45.4k
    assert(!path_empty() && "Cast kind should have a base path!");
1616
45.4k
    break;
1617
1618
4.52k
  case CK_CPointerToObjCPointerCast:
1619
4.52k
    assert(getType()->isObjCObjectPointerType());
1620
4.52k
    assert(getSubExpr()->getType()->isPointerType());
1621
4.52k
    goto CheckNoBasePath;
1622
1623
83
  case CK_BlockPointerToObjCPointerCast:
1624
83
    assert(getType()->isObjCObjectPointerType());
1625
83
    assert(getSubExpr()->getType()->isBlockPointerType());
1626
83
    goto CheckNoBasePath;
1627
1628
63
  case CK_ReinterpretMemberPointer:
1629
63
    assert(getType()->isMemberPointerType());
1630
63
    assert(getSubExpr()->getType()->isMemberPointerType());
1631
63
    goto CheckNoBasePath;
1632
1633
3.84M
  case CK_BitCast:
1634
    // Arbitrary casts to C pointer types count as bitcasts.
1635
    // Otherwise, we should only have block and ObjC pointer casts
1636
    // here if they stay within the type kind.
1637
3.84M
    if (!getType()->isPointerType()) {
1638
3.61M
      assert(getType()->isObjCObjectPointerType() ==
1639
3.61M
             getSubExpr()->getType()->isObjCObjectPointerType());
1640
3.61M
      assert(getType()->isBlockPointerType() ==
1641
3.61M
             getSubExpr()->getType()->isBlockPointerType());
1642
3.61M
    }
1643
3.84M
    goto CheckNoBasePath;
1644
1645
60
  case CK_AnyPointerToBlockPointerCast:
1646
60
    assert(getType()->isBlockPointerType());
1647
60
    assert(getSubExpr()->getType()->isAnyPointerType() &&
1648
60
           !getSubExpr()->getType()->isBlockPointerType());
1649
60
    goto CheckNoBasePath;
1650
1651
12
  case CK_CopyAndAutoreleaseBlockObject:
1652
12
    assert(getType()->isBlockPointerType());
1653
12
    assert(getSubExpr()->getType()->isBlockPointerType());
1654
12
    goto CheckNoBasePath;
1655
1656
2.12M
  case CK_FunctionToPointerDecay:
1657
2.12M
    assert(getType()->isPointerType());
1658
2.12M
    assert(getSubExpr()->getType()->isFunctionType());
1659
2.12M
    goto CheckNoBasePath;
1660
1661
759
  case CK_AddressSpaceConversion: {
1662
759
    auto Ty = getType();
1663
759
    auto SETy = getSubExpr()->getType();
1664
759
    assert(getValueKindForType(Ty) == Expr::getValueKindForType(SETy));
1665
759
    if (isRValue() && 
!Ty->isDependentType()666
&&
!SETy->isDependentType()666
) {
1666
666
      Ty = Ty->getPointeeType();
1667
666
      SETy = SETy->getPointeeType();
1668
666
    }
1669
759
    assert((Ty->isDependentType() || SETy->isDependentType()) ||
1670
759
           (!Ty.isNull() && !SETy.isNull() &&
1671
759
            Ty.getAddressSpace() != SETy.getAddressSpace()));
1672
759
    goto CheckNoBasePath;
1673
45.0k
  }
1674
  // These should not have an inheritance path.
1675
230
  case CK_Dynamic:
1676
249
  case CK_ToUnion:
1677
216k
  case CK_ArrayToPointerDecay:
1678
216k
  case CK_NullToMemberPointer:
1679
283k
  case CK_NullToPointer:
1680
316k
  case CK_ConstructorConversion:
1681
322k
  case CK_IntegralToPointer:
1682
328k
  case CK_PointerToIntegral:
1683
416k
  case CK_ToVoid:
1684
425k
  case CK_VectorSplat:
1685
3.27M
  case CK_IntegralCast:
1686
3.27M
  case CK_BooleanToSignedIntegral:
1687
3.32M
  case CK_IntegralToFloating:
1688
3.32M
  case CK_FloatingToIntegral:
1689
3.34M
  case CK_FloatingCast:
1690
3.34M
  case CK_ObjCObjectLValueCast:
1691
3.34M
  case CK_FloatingRealToComplex:
1692
3.34M
  case CK_FloatingComplexToReal:
1693
3.34M
  case CK_FloatingComplexCast:
1694
3.34M
  case CK_FloatingComplexToIntegralComplex:
1695
3.34M
  case CK_IntegralRealToComplex:
1696
3.34M
  case CK_IntegralComplexToReal:
1697
3.34M
  case CK_IntegralComplexCast:
1698
3.34M
  case CK_IntegralComplexToFloatingComplex:
1699
3.34M
  case CK_ARCProduceObject:
1700
3.34M
  case CK_ARCConsumeObject:
1701
3.34M
  case CK_ARCReclaimReturnedObject:
1702
3.34M
  case CK_ARCExtendBlockObject:
1703
3.34M
  case CK_ZeroToOCLOpaqueType:
1704
3.34M
  case CK_IntToOCLSampler:
1705
3.34M
  case CK_FloatingToFixedPoint:
1706
3.34M
  case CK_FixedPointToFloating:
1707
3.34M
  case CK_FixedPointCast:
1708
3.34M
  case CK_FixedPointToIntegral:
1709
3.34M
  case CK_IntegralToFixedPoint:
1710
3.34M
    assert(!getType()->isBooleanType() && "unheralded conversion to bool");
1711
3.34M
    goto CheckNoBasePath;
1712
1713
844k
  case CK_Dependent:
1714
11.3M
  case CK_LValueToRValue:
1715
12.6M
  case CK_NoOp:
1716
12.6M
  case CK_AtomicToNonAtomic:
1717
12.6M
  case CK_NonAtomicToAtomic:
1718
12.6M
  case CK_PointerToBoolean:
1719
12.7M
  case CK_IntegralToBoolean:
1720
12.7M
  case CK_FloatingToBoolean:
1721
12.7M
  case CK_MemberPointerToBoolean:
1722
12.7M
  case CK_FloatingComplexToBoolean:
1723
12.7M
  case CK_IntegralComplexToBoolean:
1724
12.7M
  case CK_LValueBitCast:            // -> bool&
1725
12.7M
  case CK_LValueToRValueBitCast:
1726
12.7M
  case CK_UserDefinedConversion:    // operator bool()
1727
14.3M
  case CK_BuiltinFnToFnPtr:
1728
14.3M
  case CK_FixedPointToBoolean:
1729
23.6M
  CheckNoBasePath:
1730
23.6M
    assert(path_empty() && "Cast kind should not have a base path!");
1731
23.6M
    break;
1732
23.6M
  }
1733
23.6M
  return true;
1734
23.6M
}
1735
1736
6.42k
const char *CastExpr::getCastKindName(CastKind CK) {
1737
6.42k
  switch (CK) {
1738
6.42k
#define CAST_OPERATION(Name) case CK_##Name: return #Name;
1739
0
#include "clang/AST/OperationKinds.def"
1740
6.42k
  }
1741
6.42k
  
llvm_unreachable0
("Unhandled cast kind!");
1742
6.42k
}
1743
1744
namespace {
1745
1.81M
  const Expr *skipImplicitTemporary(const Expr *E) {
1746
    // Skip through reference binding to temporary.
1747
1.81M
    if (auto *Materialize = dyn_cast<MaterializeTemporaryExpr>(E))
1748
3.26k
      E = Materialize->getSubExpr();
1749
1750
    // Skip any temporary bindings; they're implicit.
1751
1.81M
    if (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E))
1752
13.8k
      E = Binder->getSubExpr();
1753
1754
1.81M
    return E;
1755
1.81M
  }
1756
}
1757
1758
1.74M
Expr *CastExpr::getSubExprAsWritten() {
1759
1.74M
  const Expr *SubExpr = nullptr;
1760
1.74M
  const CastExpr *E = this;
1761
1.80M
  do {
1762
1.80M
    SubExpr = skipImplicitTemporary(E->getSubExpr());
1763
1764
    // Conversions by constructor and conversion functions have a
1765
    // subexpression describing the call; strip it off.
1766
1.80M
    if (E->getCastKind() == CK_ConstructorConversion)
1767
3.59k
      SubExpr =
1768
3.59k
        skipImplicitTemporary(cast<CXXConstructExpr>(SubExpr->IgnoreImplicit())->getArg(0));
1769
1.80M
    else if (E->getCastKind() == CK_UserDefinedConversion) {
1770
1.57k
      assert((isa<CXXMemberCallExpr>(SubExpr) ||
1771
1.57k
              isa<BlockExpr>(SubExpr)) &&
1772
1.57k
             "Unexpected SubExpr for CK_UserDefinedConversion.");
1773
1.57k
      if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr))
1774
1.57k
        SubExpr = MCE->getImplicitObjectArgument();
1775
1.57k
    }
1776
1777
    // If the subexpression we're left with is an implicit cast, look
1778
    // through that, too.
1779
1.80M
  } while ((E = dyn_cast<ImplicitCastExpr>(SubExpr)));
1780
1781
1.74M
  return const_cast<Expr*>(SubExpr);
1782
1.74M
}
1783
1784
1.63k
NamedDecl *CastExpr::getConversionFunction() const {
1785
1.63k
  const Expr *SubExpr = nullptr;
1786
1787
3.31k
  for (const CastExpr *E = this; E; 
E = dyn_cast<ImplicitCastExpr>(SubExpr)1.68k
) {
1788
1.75k
    SubExpr = skipImplicitTemporary(E->getSubExpr());
1789
1790
1.75k
    if (E->getCastKind() == CK_ConstructorConversion)
1791
0
      return cast<CXXConstructExpr>(SubExpr)->getConstructor();
1792
1793
1.75k
    if (E->getCastKind() == CK_UserDefinedConversion) {
1794
66
      if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr))
1795
66
        return MCE->getMethodDecl();
1796
66
    }
1797
1.75k
  }
1798
1799
1.56k
  return nullptr;
1800
1.63k
}
1801
1802
3.55M
CXXBaseSpecifier **CastExpr::path_buffer() {
1803
3.55M
  switch (getStmtClass()) {
1804
0
#define ABSTRACT_STMT(x)
1805
0
#define CASTEXPR(Type, Base)                                                   \
1806
3.55M
  case Stmt::Type##Class:                                                      \
1807
3.55M
    return static_cast<Type *>(this)->getTrailingObjects<CXXBaseSpecifier *>();
1808
0
#define STMT(Type, Base)
1809
0
#include "clang/AST/StmtNodes.inc"
1810
0
  default:
1811
0
    llvm_unreachable("non-cast expressions not possible here");
1812
3.55M
  }
1813
3.55M
}
1814
1815
const FieldDecl *CastExpr::getTargetFieldForToUnionCast(QualType unionType,
1816
4
                                                        QualType opType) {
1817
4
  auto RD = unionType->castAs<RecordType>()->getDecl();
1818
4
  return getTargetFieldForToUnionCast(RD, opType);
1819
4
}
1820
1821
const FieldDecl *CastExpr::getTargetFieldForToUnionCast(const RecordDecl *RD,
1822
26
                                                        QualType OpType) {
1823
26
  auto &Ctx = RD->getASTContext();
1824
26
  RecordDecl::field_iterator Field, FieldEnd;
1825
26
  for (Field = RD->field_begin(), FieldEnd = RD->field_end();
1826
43
       Field != FieldEnd; 
++Field17
) {
1827
40
    if (Ctx.hasSameUnqualifiedType(Field->getType(), OpType) &&
1828
24
        !Field->isUnnamedBitfield()) {
1829
23
      return *Field;
1830
23
    }
1831
40
  }
1832
3
  return nullptr;
1833
26
}
1834
1835
33.3k
FPOptionsOverride *CastExpr::getTrailingFPFeatures() {
1836
33.3k
  assert(hasStoredFPFeatures());
1837
33.3k
  switch (getStmtClass()) {
1838
26.3k
  case ImplicitCastExprClass:
1839
26.3k
    return static_cast<ImplicitCastExpr *>(this)
1840
26.3k
        ->getTrailingObjects<FPOptionsOverride>();
1841
7.01k
  case CStyleCastExprClass:
1842
7.01k
    return static_cast<CStyleCastExpr *>(this)
1843
7.01k
        ->getTrailingObjects<FPOptionsOverride>();
1844
6
  case CXXFunctionalCastExprClass:
1845
6
    return static_cast<CXXFunctionalCastExpr *>(this)
1846
6
        ->getTrailingObjects<FPOptionsOverride>();
1847
6
  case CXXStaticCastExprClass:
1848
6
    return static_cast<CXXStaticCastExpr *>(this)
1849
6
        ->getTrailingObjects<FPOptionsOverride>();
1850
0
  default:
1851
0
    llvm_unreachable("Cast does not have FPFeatures");
1852
33.3k
  }
1853
33.3k
}
1854
1855
ImplicitCastExpr *ImplicitCastExpr::Create(const ASTContext &C, QualType T,
1856
                                           CastKind Kind, Expr *Operand,
1857
                                           const CXXCastPath *BasePath,
1858
                                           ExprValueKind VK,
1859
18.6M
                                           FPOptionsOverride FPO) {
1860
18.1M
  unsigned PathSize = (BasePath ? 
BasePath->size()442k
: 0);
1861
18.6M
  void *Buffer =
1862
18.6M
      C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
1863
18.6M
          PathSize, FPO.requiresTrailingStorage()));
1864
  // Per C++ [conv.lval]p3, lvalue-to-rvalue conversions on class and
1865
  // std::nullptr_t have special semantics not captured by CK_LValueToRValue.
1866
18.6M
  assert((Kind != CK_LValueToRValue ||
1867
18.6M
          !(T->isNullPtrType() || T->getAsCXXRecordDecl())) &&
1868
18.6M
         "invalid type for lvalue-to-rvalue conversion");
1869
18.6M
  ImplicitCastExpr *E =
1870
18.6M
      new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, FPO, VK);
1871
18.6M
  if (PathSize)
1872
44.3k
    std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
1873
44.3k
                              E->getTrailingObjects<CXXBaseSpecifier *>());
1874
18.6M
  return E;
1875
18.6M
}
1876
1877
ImplicitCastExpr *ImplicitCastExpr::CreateEmpty(const ASTContext &C,
1878
                                                unsigned PathSize,
1879
766k
                                                bool HasFPFeatures) {
1880
766k
  void *Buffer =
1881
766k
      C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
1882
766k
          PathSize, HasFPFeatures));
1883
766k
  return new (Buffer) ImplicitCastExpr(EmptyShell(), PathSize, HasFPFeatures);
1884
766k
}
1885
1886
CStyleCastExpr *CStyleCastExpr::Create(const ASTContext &C, QualType T,
1887
                                       ExprValueKind VK, CastKind K, Expr *Op,
1888
                                       const CXXCastPath *BasePath,
1889
                                       FPOptionsOverride FPO,
1890
                                       TypeSourceInfo *WrittenTy,
1891
4.26M
                                       SourceLocation L, SourceLocation R) {
1892
4.26M
  unsigned PathSize = (BasePath ? BasePath->size() : 
01.79k
);
1893
4.26M
  void *Buffer =
1894
4.26M
      C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
1895
4.26M
          PathSize, FPO.requiresTrailingStorage()));
1896
4.26M
  CStyleCastExpr *E =
1897
4.26M
      new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, FPO, WrittenTy, L, R);
1898
4.26M
  if (PathSize)
1899
139
    std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
1900
139
                              E->getTrailingObjects<CXXBaseSpecifier *>());
1901
4.26M
  return E;
1902
4.26M
}
1903
1904
CStyleCastExpr *CStyleCastExpr::CreateEmpty(const ASTContext &C,
1905
                                            unsigned PathSize,
1906
20.8k
                                            bool HasFPFeatures) {
1907
20.8k
  void *Buffer =
1908
20.8k
      C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
1909
20.8k
          PathSize, HasFPFeatures));
1910
20.8k
  return new (Buffer) CStyleCastExpr(EmptyShell(), PathSize, HasFPFeatures);
1911
20.8k
}
1912
1913
/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1914
/// corresponds to, e.g. "<<=".
1915
378k
StringRef BinaryOperator::getOpcodeStr(Opcode Op) {
1916
378k
  switch (Op) {
1917
378k
#define BINARY_OPERATION(Name, Spelling) case BO_##Name: return Spelling;
1918
0
#include "clang/AST/OperationKinds.def"
1919
378k
  }
1920
378k
  
llvm_unreachable0
("Invalid OpCode!");
1921
378k
}
1922
1923
BinaryOperatorKind
1924
60.1k
BinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) {
1925
60.1k
  switch (OO) {
1926
0
  default: llvm_unreachable("Not an overloadable binary operator");
1927
9.57k
  case OO_Plus: return BO_Add;
1928
8.17k
  case OO_Minus: return BO_Sub;
1929
241
  case OO_Star: return BO_Mul;
1930
904
  case OO_Slash: return BO_Div;
1931
2
  case OO_Percent: return BO_Rem;
1932
64
  case OO_Caret: return BO_Xor;
1933
135
  case OO_Amp: return BO_And;
1934
36
  case OO_Pipe: return BO_Or;
1935
126
  case OO_Equal: return BO_Assign;
1936
137
  case OO_Spaceship: return BO_Cmp;
1937
8.70k
  case OO_Less: return BO_LT;
1938
8.54k
  case OO_Greater: return BO_GT;
1939
42
  case OO_PlusEqual: return BO_AddAssign;
1940
0
  case OO_MinusEqual: return BO_SubAssign;
1941
0
  case OO_StarEqual: return BO_MulAssign;
1942
0
  case OO_SlashEqual: return BO_DivAssign;
1943
0
  case OO_PercentEqual: return BO_RemAssign;
1944
18
  case OO_CaretEqual: return BO_XorAssign;
1945
0
  case OO_AmpEqual: return BO_AndAssign;
1946
9
  case OO_PipeEqual: return BO_OrAssign;
1947
461
  case OO_LessLess: return BO_Shl;
1948
178
  case OO_GreaterGreater: return BO_Shr;
1949
0
  case OO_LessLessEqual: return BO_ShlAssign;
1950
0
  case OO_GreaterGreaterEqual: return BO_ShrAssign;
1951
11.7k
  case OO_EqualEqual: return BO_EQ;
1952
6.51k
  case OO_ExclaimEqual: return BO_NE;
1953
1.33k
  case OO_LessEqual: return BO_LE;
1954
2.60k
  case OO_GreaterEqual: return BO_GE;
1955
561
  case OO_AmpAmp: return BO_LAnd;
1956
4
  case OO_PipePipe: return BO_LOr;
1957
0
  case OO_Comma: return BO_Comma;
1958
1
  case OO_ArrowStar: return BO_PtrMemI;
1959
60.1k
  }
1960
60.1k
}
1961
1962
3.25M
OverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) {
1963
3.25M
  static const OverloadedOperatorKind OverOps[] = {
1964
3.25M
    /* .* Cannot be overloaded */OO_None, OO_ArrowStar,
1965
3.25M
    OO_Star, OO_Slash, OO_Percent,
1966
3.25M
    OO_Plus, OO_Minus,
1967
3.25M
    OO_LessLess, OO_GreaterGreater,
1968
3.25M
    OO_Spaceship,
1969
3.25M
    OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual,
1970
3.25M
    OO_EqualEqual, OO_ExclaimEqual,
1971
3.25M
    OO_Amp,
1972
3.25M
    OO_Caret,
1973
3.25M
    OO_Pipe,
1974
3.25M
    OO_AmpAmp,
1975
3.25M
    OO_PipePipe,
1976
3.25M
    OO_Equal, OO_StarEqual,
1977
3.25M
    OO_SlashEqual, OO_PercentEqual,
1978
3.25M
    OO_PlusEqual, OO_MinusEqual,
1979
3.25M
    OO_LessLessEqual, OO_GreaterGreaterEqual,
1980
3.25M
    OO_AmpEqual, OO_CaretEqual,
1981
3.25M
    OO_PipeEqual,
1982
3.25M
    OO_Comma
1983
3.25M
  };
1984
3.25M
  return OverOps[Opc];
1985
3.25M
}
1986
1987
bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx,
1988
                                                      Opcode Opc,
1989
14.7k
                                                      Expr *LHS, Expr *RHS) {
1990
14.7k
  if (Opc != BO_Add)
1991
999
    return false;
1992
1993
  // Check that we have one pointer and one integer operand.
1994
13.7k
  Expr *PExp;
1995
13.7k
  if (LHS->getType()->isPointerType()) {
1996
13.6k
    if (!RHS->getType()->isIntegerType())
1997
0
      return false;
1998
13.6k
    PExp = LHS;
1999
89
  } else if (RHS->getType()->isPointerType()) {
2000
88
    if (!LHS->getType()->isIntegerType())
2001
0
      return false;
2002
88
    PExp = RHS;
2003
1
  } else {
2004
1
    return false;
2005
1
  }
2006
2007
  // Check that the pointer is a nullptr.
2008
13.7k
  if (!PExp->IgnoreParenCasts()
2009
13.7k
          ->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull))
2010
12.3k
    return false;
2011
2012
  // Check that the pointee type is char-sized.
2013
1.34k
  const PointerType *PTy = PExp->getType()->getAs<PointerType>();
2014
1.34k
  if (!PTy || !PTy->getPointeeType()->isCharType())
2015
1.30k
    return false;
2016
2017
39
  return true;
2018
39
}
2019
2020
static QualType getDecayedSourceLocExprType(const ASTContext &Ctx,
2021
102
                                            SourceLocExpr::IdentKind Kind) {
2022
102
  switch (Kind) {
2023
17
  case SourceLocExpr::File:
2024
36
  case SourceLocExpr::Function: {
2025
36
    QualType ArrTy = Ctx.getStringLiteralArrayType(Ctx.CharTy, 0);
2026
36
    return Ctx.getPointerType(ArrTy->getAsArrayTypeUnsafe()->getElementType());
2027
17
  }
2028
52
  case SourceLocExpr::Line:
2029
66
  case SourceLocExpr::Column:
2030
66
    return Ctx.UnsignedIntTy;
2031
0
  }
2032
0
  llvm_unreachable("unhandled case");
2033
0
}
2034
2035
SourceLocExpr::SourceLocExpr(const ASTContext &Ctx, IdentKind Kind,
2036
                             SourceLocation BLoc, SourceLocation RParenLoc,
2037
                             DeclContext *ParentContext)
2038
    : Expr(SourceLocExprClass, getDecayedSourceLocExprType(Ctx, Kind),
2039
           VK_RValue, OK_Ordinary),
2040
102
      BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext) {
2041
102
  SourceLocExprBits.Kind = Kind;
2042
102
  setDependence(ExprDependence::None);
2043
102
}
2044
2045
0
StringRef SourceLocExpr::getBuiltinStr() const {
2046
0
  switch (getIdentKind()) {
2047
0
  case File:
2048
0
    return "__builtin_FILE";
2049
0
  case Function:
2050
0
    return "__builtin_FUNCTION";
2051
0
  case Line:
2052
0
    return "__builtin_LINE";
2053
0
  case Column:
2054
0
    return "__builtin_COLUMN";
2055
0
  }
2056
0
  llvm_unreachable("unexpected IdentKind!");
2057
0
}
2058
2059
APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
2060
632
                                         const Expr *DefaultExpr) const {
2061
632
  SourceLocation Loc;
2062
632
  const DeclContext *Context;
2063
2064
632
  std::tie(Loc,
2065
632
           Context) = [&]() -> std::pair<SourceLocation, const DeclContext *> {
2066
632
    if (auto *DIE = dyn_cast_or_null<CXXDefaultInitExpr>(DefaultExpr))
2067
184
      return {DIE->getUsedLocation(), DIE->getUsedContext()};
2068
448
    if (auto *DAE = dyn_cast_or_null<CXXDefaultArgExpr>(DefaultExpr))
2069
315
      return {DAE->getUsedLocation(), DAE->getUsedContext()};
2070
133
    return {this->getLocation(), this->getParentContext()};
2071
133
  }();
2072
2073
632
  PresumedLoc PLoc = Ctx.getSourceManager().getPresumedLoc(
2074
632
      Ctx.getSourceManager().getExpansionRange(Loc).getEnd());
2075
2076
268
  auto MakeStringLiteral = [&](StringRef Tmp) {
2077
268
    using LValuePathEntry = APValue::LValuePathEntry;
2078
268
    StringLiteral *Res = Ctx.getPredefinedStringLiteralFromCache(Tmp);
2079
    // Decay the string to a pointer to the first character.
2080
268
    LValuePathEntry Path[1] = {LValuePathEntry::ArrayIndex(0)};
2081
268
    return APValue(Res, CharUnits::Zero(), Path, /*OnePastTheEnd=*/false);
2082
268
  };
2083
2084
632
  switch (getIdentKind()) {
2085
128
  case SourceLocExpr::File:
2086
128
    return MakeStringLiteral(PLoc.getFilename());
2087
140
  case SourceLocExpr::Function: {
2088
140
    const Decl *CurDecl = dyn_cast_or_null<Decl>(Context);
2089
140
    return MakeStringLiteral(
2090
140
        CurDecl ? PredefinedExpr::ComputeName(PredefinedExpr::Function, CurDecl)
2091
0
                : std::string(""));
2092
0
  }
2093
246
  case SourceLocExpr::Line:
2094
364
  case SourceLocExpr::Column: {
2095
364
    llvm::APSInt IntVal(Ctx.getIntWidth(Ctx.UnsignedIntTy),
2096
364
                        /*isUnsigned=*/true);
2097
246
    IntVal = getIdentKind() == SourceLocExpr::Line ? PLoc.getLine()
2098
118
                                                   : PLoc.getColumn();
2099
364
    return APValue(IntVal);
2100
0
  }
2101
0
  }
2102
0
  llvm_unreachable("unhandled case");
2103
0
}
2104
2105
InitListExpr::InitListExpr(const ASTContext &C, SourceLocation lbraceloc,
2106
                           ArrayRef<Expr *> initExprs, SourceLocation rbraceloc)
2107
    : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary),
2108
      InitExprs(C, initExprs.size()), LBraceLoc(lbraceloc),
2109
266k
      RBraceLoc(rbraceloc), AltForm(nullptr, true) {
2110
266k
  sawArrayRangeDesignator(false);
2111
266k
  InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end());
2112
2113
266k
  setDependence(computeDependence(this));
2114
266k
}
2115
2116
110k
void InitListExpr::reserveInits(const ASTContext &C, unsigned NumInits) {
2117
110k
  if (NumInits > InitExprs.size())
2118
87.0k
    InitExprs.reserve(C, NumInits);
2119
110k
}
2120
2121
5.84k
void InitListExpr::resizeInits(const ASTContext &C, unsigned NumInits) {
2122
5.84k
  InitExprs.resize(C, NumInits, nullptr);
2123
5.84k
}
2124
2125
527k
Expr *InitListExpr::updateInit(const ASTContext &C, unsigned Init, Expr *expr) {
2126
527k
  if (Init >= InitExprs.size()) {
2127
523k
    InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, nullptr);
2128
523k
    setInit(Init, expr);
2129
523k
    return nullptr;
2130
523k
  }
2131
2132
4.24k
  Expr *Result = cast_or_null<Expr>(InitExprs[Init]);
2133
4.24k
  setInit(Init, expr);
2134
4.24k
  return Result;
2135
4.24k
}
2136
2137
6.96k
void InitListExpr::setArrayFiller(Expr *filler) {
2138
6.96k
  assert(!hasArrayFiller() && "Filler already set!");
2139
6.96k
  ArrayFillerOrUnionFieldInit = filler;
2140
  // Fill out any "holes" in the array due to designated initializers.
2141
6.96k
  Expr **inits = getInits();
2142
20.5k
  for (unsigned i = 0, e = getNumInits(); i != e; 
++i13.6k
)
2143
13.6k
    if (inits[i] == nullptr)
2144
5.34k
      inits[i] = filler;
2145
6.96k
}
2146
2147
6.76k
bool InitListExpr::isStringLiteralInit() const {
2148
6.76k
  if (getNumInits() != 1)
2149
5.91k
    return false;
2150
857
  const ArrayType *AT = getType()->getAsArrayTypeUnsafe();
2151
857
  if (!AT || !AT->getElementType()->isIntegerType())
2152
300
    return false;
2153
  // It is possible for getInit() to return null.
2154
557
  const Expr *Init = getInit(0);
2155
557
  if (!Init)
2156
0
    return false;
2157
557
  Init = Init->IgnoreParens();
2158
557
  return isa<StringLiteral>(Init) || 
isa<ObjCEncodeExpr>(Init)459
;
2159
557
}
2160
2161
131k
bool InitListExpr::isTransparent() const {
2162
131k
  assert(isSemanticForm() && "syntactic form never semantically transparent");
2163
2164
  // A glvalue InitListExpr is always just sugar.
2165
131k
  if (isGLValue()) {
2166
67
    assert(getNumInits() == 1 && "multiple inits in glvalue init list");
2167
67
    return true;
2168
67
  }
2169
2170
  // Otherwise, we're sugar if and only if we have exactly one initializer that
2171
  // is of the same type.
2172
131k
  if (getNumInits() != 1 || 
!getInit(0)22.4k
)
2173
109k
    return false;
2174
2175
  // Don't confuse aggregate initialization of a struct X { X &x; }; with a
2176
  // transparent struct copy.
2177
22.4k
  if (!getInit(0)->isRValue() && 
getType()->isRecordType()486
)
2178
486
    return false;
2179
2180
21.9k
  return getType().getCanonicalType() ==
2181
21.9k
         getInit(0)->getType().getCanonicalType();
2182
21.9k
}
2183
2184
50.4k
bool InitListExpr::isIdiomaticZeroInitializer(const LangOptions &LangOpts) const {
2185
50.4k
  assert(isSyntacticForm() && "only test syntactic form as zero initializer");
2186
2187
50.4k
  if (LangOpts.CPlusPlus || 
getNumInits() != 18.50k
||
!getInit(0)2.12k
) {
2188
48.2k
    return false;
2189
48.2k
  }
2190
2191
2.12k
  const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(getInit(0)->IgnoreImplicit());
2192
2.12k
  return Lit && 
Lit->getValue() == 0778
;
2193
2.12k
}
2194
2195
588k
SourceLocation InitListExpr::getBeginLoc() const {
2196
588k
  if (InitListExpr *SyntacticForm = getSyntacticForm())
2197
138k
    return SyntacticForm->getBeginLoc();
2198
449k
  SourceLocation Beg = LBraceLoc;
2199
449k
  if (Beg.isInvalid()) {
2200
    // Find the first non-null initializer.
2201
179
    for (InitExprsTy::const_iterator I = InitExprs.begin(),
2202
179
                                     E = InitExprs.end();
2203
179
      I != E; 
++I0
) {
2204
179
      if (Stmt *S = *I) {
2205
179
        Beg = S->getBeginLoc();
2206
179
        break;
2207
179
      }
2208
179
    }
2209
179
  }
2210
449k
  return Beg;
2211
449k
}
2212
2213
421k
SourceLocation InitListExpr::getEndLoc() const {
2214
421k
  if (InitListExpr *SyntacticForm = getSyntacticForm())
2215
90.8k
    return SyntacticForm->getEndLoc();
2216
330k
  SourceLocation End = RBraceLoc;
2217
330k
  if (End.isInvalid()) {
2218
    // Find the first non-null initializer from the end.
2219
40
    for (InitExprsTy::const_reverse_iterator I = InitExprs.rbegin(),
2220
40
         E = InitExprs.rend();
2221
40
         I != E; 
++I0
) {
2222
40
      if (Stmt *S = *I) {
2223
40
        End = S->getEndLoc();
2224
40
        break;
2225
40
      }
2226
40
    }
2227
40
  }
2228
330k
  return End;
2229
330k
}
2230
2231
/// getFunctionType - Return the underlying function type for this block.
2232
///
2233
1.57k
const FunctionProtoType *BlockExpr::getFunctionType() const {
2234
  // The block pointer is never sugared, but the function type might be.
2235
1.57k
  return cast<BlockPointerType>(getType())
2236
1.57k
           ->getPointeeType()->castAs<FunctionProtoType>();
2237
1.57k
}
2238
2239
23.8k
SourceLocation BlockExpr::getCaretLocation() const {
2240
23.8k
  return TheBlock->getCaretLocation();
2241
23.8k
}
2242
6.17k
const Stmt *BlockExpr::getBody() const {
2243
6.17k
  return TheBlock->getBody();
2244
6.17k
}
2245
820
Stmt *BlockExpr::getBody() {
2246
820
  return TheBlock->getBody();
2247
820
}
2248
2249
2250
//===----------------------------------------------------------------------===//
2251
// Generic Expression Routines
2252
//===----------------------------------------------------------------------===//
2253
2254
522k
bool Expr::isReadIfDiscardedInCPlusPlus11() const {
2255
  // In C++11, discarded-value expressions of a certain form are special,
2256
  // according to [expr]p10:
2257
  //   The lvalue-to-rvalue conversion (4.1) is applied only if the
2258
  //   expression is an lvalue of volatile-qualified type and it has
2259
  //   one of the following forms:
2260
522k
  if (!isGLValue() || 
!getType().isVolatileQualified()521k
)
2261
520k
    return false;
2262
2263
1.81k
  const Expr *E = IgnoreParens();
2264
2265
  //   - id-expression (5.1.1),
2266
1.81k
  if (isa<DeclRefExpr>(E))
2267
54
    return true;
2268
2269
  //   - subscripting (5.2.1),
2270
1.75k
  if (isa<ArraySubscriptExpr>(E))
2271
4
    return true;
2272
2273
  //   - class member access (5.2.5),
2274
1.75k
  if (isa<MemberExpr>(E))
2275
8
    return true;
2276
2277
  //   - indirection (5.3.1),
2278
1.74k
  if (auto *UO = dyn_cast<UnaryOperator>(E))
2279
110
    if (UO->getOpcode() == UO_Deref)
2280
60
      return true;
2281
2282
1.68k
  if (auto *BO = dyn_cast<BinaryOperator>(E)) {
2283
    //   - pointer-to-member operation (5.5),
2284
1.56k
    if (BO->isPtrMemOp())
2285
1
      return true;
2286
2287
    //   - comma expression (5.18) where the right operand is one of the above.
2288
1.56k
    if (BO->getOpcode() == BO_Comma)
2289
8
      return BO->getRHS()->isReadIfDiscardedInCPlusPlus11();
2290
1.67k
  }
2291
2292
  //   - conditional expression (5.16) where both the second and the third
2293
  //     operands are one of the above, or
2294
1.67k
  if (auto *CO = dyn_cast<ConditionalOperator>(E))
2295
3
    return CO->getTrueExpr()->isReadIfDiscardedInCPlusPlus11() &&
2296
1
           CO->getFalseExpr()->isReadIfDiscardedInCPlusPlus11();
2297
  // The related edge case of "*x ?: *x".
2298
1.67k
  if (auto *BCO =
2299
1
          dyn_cast<BinaryConditionalOperator>(E)) {
2300
1
    if (auto *OVE = dyn_cast<OpaqueValueExpr>(BCO->getTrueExpr()))
2301
1
      return OVE->getSourceExpr()->isReadIfDiscardedInCPlusPlus11() &&
2302
1
             BCO->getFalseExpr()->isReadIfDiscardedInCPlusPlus11();
2303
1.67k
  }
2304
2305
  // Objective-C++ extensions to the rule.
2306
1.67k
  if (isa<PseudoObjectExpr>(E) || isa<ObjCIvarRefExpr>(E))
2307
0
    return true;
2308
2309
1.67k
  return false;
2310
1.67k
}
2311
2312
/// isUnusedResultAWarning - Return true if this immediate expression should
2313
/// be warned about if the result is unused.  If so, fill in Loc and Ranges
2314
/// with location to warn on and the source range[s] to report with the
2315
/// warning.
2316
bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc,
2317
                                  SourceRange &R1, SourceRange &R2,
2318
2.36M
                                  ASTContext &Ctx) const {
2319
  // Don't warn if the expr is type dependent. The type could end up
2320
  // instantiating to void.
2321
2.36M
  if (isTypeDependent())
2322
826k
    return false;
2323
2324
1.53M
  switch (getStmtClass()) {
2325
19.4k
  default:
2326
19.4k
    if (getType()->isVoidType())
2327
13.6k
      return false;
2328
5.79k
    WarnE = this;
2329
5.79k
    Loc = getExprLoc();
2330
5.79k
    R1 = getSourceRange();
2331
5.79k
    return true;
2332
28.2k
  case ParenExprClass:
2333
28.2k
    return cast<ParenExpr>(this)->getSubExpr()->
2334
28.2k
      isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2335
31
  case GenericSelectionExprClass:
2336
31
    return cast<GenericSelectionExpr>(this)->getResultExpr()->
2337
31
      isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2338
179
  case CoawaitExprClass:
2339
198
  case CoyieldExprClass:
2340
198
    return cast<CoroutineSuspendExpr>(this)->getResumeExpr()->
2341
198
      isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2342
4
  case ChooseExprClass:
2343
4
    return cast<ChooseExpr>(this)->getChosenSubExpr()->
2344
4
      isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2345
221k
  case UnaryOperatorClass: {
2346
221k
    const UnaryOperator *UO = cast<UnaryOperator>(this);
2347
2348
221k
    switch (UO->getOpcode()) {
2349
33
    case UO_Plus:
2350
85
    case UO_Minus:
2351
225
    case UO_AddrOf:
2352
256
    case UO_Not:
2353
400
    case UO_LNot:
2354
801
    case UO_Deref:
2355
801
      break;
2356
0
    case UO_Coawait:
2357
      // This is just the 'operator co_await' call inside the guts of a
2358
      // dependent co_await call.
2359
48.8k
    case UO_PostInc:
2360
49.4k
    case UO_PostDec:
2361
210k
    case UO_PreInc:
2362
217k
    case UO_PreDec:                 // ++/--
2363
217k
      return false;  // Not a warning.
2364
24
    case UO_Real:
2365
44
    case UO_Imag:
2366
      // accessing a piece of a volatile complex is a side-effect.
2367
44
      if (Ctx.getCanonicalType(UO->getSubExpr()->getType())
2368
44
          .isVolatileQualified())
2369
11
        return false;
2370
33
      break;
2371
3.48k
    case UO_Extension:
2372
3.48k
      return UO->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2373
834
    }
2374
834
    WarnE = this;
2375
834
    Loc = UO->getOperatorLoc();
2376
834
    R1 = UO->getSubExpr()->getSourceRange();
2377
834
    return true;
2378
834
  }
2379
687k
  case BinaryOperatorClass: {
2380
687k
    const BinaryOperator *BO = cast<BinaryOperator>(this);
2381
687k
    switch (BO->getOpcode()) {
2382
679k
      default:
2383
679k
        break;
2384
      // Consider the RHS of comma for side effects. LHS was checked by
2385
      // Sema::CheckCommaOperands.
2386
7.74k
      case BO_Comma:
2387
        // ((foo = <blah>), 0) is an idiom for hiding the result (and
2388
        // lvalue-ness) of an assignment written in a macro.
2389
7.74k
        if (IntegerLiteral *IE =
2390
107
              dyn_cast<IntegerLiteral>(BO->getRHS()->IgnoreParens()))
2391
107
          if (IE->getValue() == 0)
2392
54
            return false;
2393
7.68k
        return BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2394
      // Consider '||', '&&' to have side effects if the LHS or RHS does.
2395
70
      case BO_LAnd:
2396
201
      case BO_LOr:
2397
201
        if (!BO->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) ||
2398
164
            !BO->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx))
2399
81
          return false;
2400
120
        break;
2401
679k
    }
2402
679k
    if (BO->isAssignmentOp())
2403
677k
      return false;
2404
1.95k
    WarnE = this;
2405
1.95k
    Loc = BO->getOperatorLoc();
2406
1.95k
    R1 = BO->getLHS()->getSourceRange();
2407
1.95k
    R2 = BO->getRHS()->getSourceRange();
2408
1.95k
    return true;
2409
1.95k
  }
2410
63.2k
  case CompoundAssignOperatorClass:
2411
63.3k
  case VAArgExprClass:
2412
64.6k
  case AtomicExprClass:
2413
64.6k
    return false;
2414
2415
594
  case ConditionalOperatorClass: {
2416
    // If only one of the LHS or RHS is a warning, the operator might
2417
    // be being used for control flow. Only warn if both the LHS and
2418
    // RHS are warnings.
2419
594
    const auto *Exp = cast<ConditionalOperator>(this);
2420
594
    return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) &&
2421
185
           Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2422
63.3k
  }
2423
34
  case BinaryConditionalOperatorClass: {
2424
34
    const auto *Exp = cast<BinaryConditionalOperator>(this);
2425
34
    return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2426
63.3k
  }
2427
2428
3.39k
  case MemberExprClass:
2429
3.39k
    WarnE = this;
2430
3.39k
    Loc = cast<MemberExpr>(this)->getMemberLoc();
2431
3.39k
    R1 = SourceRange(Loc, Loc);
2432
3.39k
    R2 = cast<MemberExpr>(this)->getBase()->getSourceRange();
2433
3.39k
    return true;
2434
2435
385
  case ArraySubscriptExprClass:
2436
385
    WarnE = this;
2437
385
    Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc();
2438
385
    R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange();
2439
385
    R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange();
2440
385
    return true;
2441
2442
23.7k
  case CXXOperatorCallExprClass: {
2443
    // Warn about operator ==,!=,<,>,<=, and >= even when user-defined operator
2444
    // overloads as there is no reasonable way to define these such that they
2445
    // have non-trivial, desirable side-effects. See the -Wunused-comparison
2446
    // warning: operators == and != are commonly typo'ed, and so warning on them
2447
    // provides additional value as well. If this list is updated,
2448
    // DiagnoseUnusedComparison should be as well.
2449
23.7k
    const CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(this);
2450
23.7k
    switch (Op->getOperator()) {
2451
23.7k
    default:
2452
23.7k
      break;
2453
16
    case OO_EqualEqual:
2454
24
    case OO_ExclaimEqual:
2455
47
    case OO_Less:
2456
56
    case OO_Greater:
2457
62
    case OO_GreaterEqual:
2458
68
    case OO_LessEqual:
2459
68
      if (Op->getCallReturnType(Ctx)->isReferenceType() ||
2460
67
          Op->getCallReturnType(Ctx)->isVoidType())
2461
8
        break;
2462
60
      WarnE = this;
2463
60
      Loc = Op->getOperatorLoc();
2464
60
      R1 = Op->getSourceRange();
2465
60
      return true;
2466
23.7k
    }
2467
2468
    // Fallthrough for generic call handling.
2469
23.7k
    LLVM_FALLTHROUGH;
2470
23.7k
  }
2471
373k
  case CallExprClass:
2472
428k
  case CXXMemberCallExprClass:
2473
428k
  case UserDefinedLiteralClass: {
2474
    // If this is a direct call, get the callee.
2475
428k
    const CallExpr *CE = cast<CallExpr>(this);
2476
428k
    if (const Decl *FD = CE->getCalleeDecl()) {
2477
      // If the callee has attribute pure, const, or warn_unused_result, warn
2478
      // about it. void foo() { strlen("bar"); } should warn.
2479
      //
2480
      // Note: If new cases are added here, DiagnoseUnusedExprResult should be
2481
      // updated to match for QoI.
2482
427k
      if (CE->hasUnusedResultAttr(Ctx) ||
2483
427k
          FD->hasAttr<PureAttr>() || 
FD->hasAttr<ConstAttr>()427k
) {
2484
7.43k
        WarnE = this;
2485
7.43k
        Loc = CE->getCallee()->getBeginLoc();
2486
7.43k
        R1 = CE->getCallee()->getSourceRange();
2487
2488
7.43k
        if (unsigned NumArgs = CE->getNumArgs())
2489
7.31k
          R2 = SourceRange(CE->getArg(0)->getBeginLoc(),
2490
7.31k
                           CE->getArg(NumArgs - 1)->getEndLoc());
2491
7.43k
        return true;
2492
7.43k
      }
2493
420k
    }
2494
420k
    return false;
2495
420k
  }
2496
2497
  // If we don't know precisely what we're looking at, let's not warn.
2498
0
  case UnresolvedLookupExprClass:
2499
65
  case CXXUnresolvedConstructExprClass:
2500
1.43k
  case RecoveryExprClass:
2501
1.43k
    return false;
2502
2503
606
  case CXXTemporaryObjectExprClass:
2504
701
  case CXXConstructExprClass: {
2505
701
    if (const CXXRecordDecl *Type = getType()->getAsCXXRecordDecl()) {
2506
701
      const auto *WarnURAttr = Type->getAttr<WarnUnusedResultAttr>();
2507
701
      if (Type->hasAttr<WarnUnusedAttr>() ||
2508
692
          (WarnURAttr && 
WarnURAttr->IsCXX11NoDiscard()4
)) {
2509
13
        WarnE = this;
2510
13
        Loc = getBeginLoc();
2511
13
        R1 = getSourceRange();
2512
13
        return true;
2513
13
      }
2514
688
    }
2515
2516
688
    const auto *CE = cast<CXXConstructExpr>(this);
2517
688
    if (const CXXConstructorDecl *Ctor = CE->getConstructor()) {
2518
688
      const auto *WarnURAttr = Ctor->getAttr<WarnUnusedResultAttr>();
2519
688
      if (WarnURAttr && 
WarnURAttr->IsCXX11NoDiscard()12
) {
2520
9
        WarnE = this;
2521
9
        Loc = getBeginLoc();
2522
9
        R1 = getSourceRange();
2523
2524
9
        if (unsigned NumArgs = CE->getNumArgs())
2525
6
          R2 = SourceRange(CE->getArg(0)->getBeginLoc(),
2526
6
                           CE->getArg(NumArgs - 1)->getEndLoc());
2527
9
        return true;
2528
9
      }
2529
679
    }
2530
2531
679
    return false;
2532
679
  }
2533
2534
9.90k
  case ObjCMessageExprClass: {
2535
9.90k
    const ObjCMessageExpr *ME = cast<ObjCMessageExpr>(this);
2536
9.90k
    if (Ctx.getLangOpts().ObjCAutoRefCount &&
2537
684
        ME->isInstanceMessage() &&
2538
649
        !ME->getType()->isVoidType() &&
2539
176
        ME->getMethodFamily() == OMF_init) {
2540
23
      WarnE = this;
2541
23
      Loc = getExprLoc();
2542
23
      R1 = ME->getSourceRange();
2543
23
      return true;
2544
23
    }
2545
2546
9.87k
    if (const ObjCMethodDecl *MD = ME->getMethodDecl())
2547
9.38k
      if (MD->hasAttr<WarnUnusedResultAttr>()) {
2548
2
        WarnE = this;
2549
2
        Loc = getExprLoc();
2550
2
        return true;
2551
2
      }
2552
2553
9.87k
    return false;
2554
9.87k
  }
2555
2556
0
  case ObjCPropertyRefExprClass:
2557
0
    WarnE = this;
2558
0
    Loc = getExprLoc();
2559
0
    R1 = getSourceRange();
2560
0
    return true;
2561
2562
1.18k
  case PseudoObjectExprClass: {
2563
1.18k
    const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this);
2564
2565
    // Only complain about things that have the form of a getter.
2566
1.18k
    if (isa<UnaryOperator>(PO->getSyntacticForm()) ||
2567
1.15k
        isa<BinaryOperator>(PO->getSyntacticForm()))
2568
956
      return false;
2569
2570
233
    WarnE = this;
2571
233
    Loc = getExprLoc();
2572
233
    R1 = getSourceRange();
2573
233
    return true;
2574
233
  }
2575
2576
3.57k
  case StmtExprClass: {
2577
    // Statement exprs don't logically have side effects themselves, but are
2578
    // sometimes used in macros in ways that give them a type that is unused.
2579
    // For example ({ blah; foo(); }) will end up with a type if foo has a type.
2580
    // however, if the result of the stmt expr is dead, we don't want to emit a
2581
    // warning.
2582
3.57k
    const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt();
2583
3.57k
    if (!CS->body_empty()) {
2584
3.56k
      if (const Expr *E = dyn_cast<Expr>(CS->body_back()))
2585
2.39k
        return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2586
1.16k
      if (const LabelStmt *Label = dyn_cast<LabelStmt>(CS->body_back()))
2587
2
        if (const Expr *E = dyn_cast<Expr>(Label->getSubStmt()))
2588
2
          return E->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2589
1.17k
    }
2590
2591
1.17k
    if (getType()->isVoidType())
2592
1.17k
      return false;
2593
4
    WarnE = this;
2594
4
    Loc = cast<StmtExpr>(this)->getLParenLoc();
2595
4
    R1 = getSourceRange();
2596
4
    return true;
2597
4
  }
2598
343
  case CXXFunctionalCastExprClass:
2599
56.6k
  case CStyleCastExprClass: {
2600
    // Ignore an explicit cast to void, except in C++98 if the operand is a
2601
    // volatile glvalue for which we would trigger an implicit read in any
2602
    // other language mode. (Such an implicit read always happens as part of
2603
    // the lvalue conversion in C, and happens in C++ for expressions of all
2604
    // forms where it seems likely the user intended to trigger a volatile
2605
    // load.)
2606
56.6k
    const CastExpr *CE = cast<CastExpr>(this);
2607
56.6k
    const Expr *SubE = CE->getSubExpr()->IgnoreParens();
2608
56.6k
    if (CE->getCastKind() == CK_ToVoid) {
2609
55.9k
      if (Ctx.getLangOpts().CPlusPlus && 
!Ctx.getLangOpts().CPlusPlus1151.8k
&&
2610
658
          SubE->isReadIfDiscardedInCPlusPlus11()) {
2611
        // Suppress the "unused value" warning for idiomatic usage of
2612
        // '(void)var;' used to suppress "unused variable" warnings.
2613
13
        if (auto *DRE = dyn_cast<DeclRefExpr>(SubE))
2614
12
          if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
2615
12
            if (!VD->isExternallyVisible())
2616
7
              return false;
2617
2618
        // The lvalue-to-rvalue conversion would have no effect for an array.
2619
        // It's implausible that the programmer expected this to result in a
2620
        // volatile array load, so don't warn.
2621
6
        if (SubE->getType()->isArrayType())
2622
1
          return false;
2623
2624
5
        return SubE->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2625
5
      }
2626
55.9k
      return false;
2627
55.9k
    }
2628
2629
    // If this is a cast to a constructor conversion, check the operand.
2630
    // Otherwise, the result of the cast is unused.
2631
639
    if (CE->getCastKind() == CK_ConstructorConversion)
2632
83
      return CE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2633
556
    if (CE->getCastKind() == CK_Dependent)
2634
12
      return false;
2635
2636
544
    WarnE = this;
2637
544
    if (const CXXFunctionalCastExpr *CXXCE =
2638
71
            dyn_cast<CXXFunctionalCastExpr>(this)) {
2639
71
      Loc = CXXCE->getBeginLoc();
2640
71
      R1 = CXXCE->getSubExpr()->getSourceRange();
2641
473
    } else {
2642
473
      const CStyleCastExpr *CStyleCE = cast<CStyleCastExpr>(this);
2643
473
      Loc = CStyleCE->getLParenLoc();
2644
473
      R1 = CStyleCE->getSubExpr()->getSourceRange();
2645
473
    }
2646
544
    return true;
2647
544
  }
2648
1.49k
  case ImplicitCastExprClass: {
2649
1.49k
    const CastExpr *ICE = cast<ImplicitCastExpr>(this);
2650
2651
    // lvalue-to-rvalue conversion on a volatile lvalue is a side-effect.
2652
1.49k
    if (ICE->getCastKind() == CK_LValueToRValue &&
2653
1.06k
        ICE->getSubExpr()->getType().isVolatileQualified())
2654
61
      return false;
2655
2656
1.43k
    return ICE->getSubExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2657
1.43k
  }
2658
0
  case CXXDefaultArgExprClass:
2659
0
    return (cast<CXXDefaultArgExpr>(this)
2660
0
            ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx));
2661
0
  case CXXDefaultInitExprClass:
2662
0
    return (cast<CXXDefaultInitExpr>(this)
2663
0
            ->getExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx));
2664
2665
1.45k
  case CXXNewExprClass:
2666
    // FIXME: In theory, there might be new expressions that don't have side
2667
    // effects (e.g. a placement new with an uninitialized POD).
2668
5.89k
  case CXXDeleteExprClass:
2669
5.89k
    return false;
2670
0
  case MaterializeTemporaryExprClass:
2671
0
    return cast<MaterializeTemporaryExpr>(this)
2672
0
        ->getSubExpr()
2673
0
        ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2674
322
  case CXXBindTemporaryExprClass:
2675
322
    return cast<CXXBindTemporaryExpr>(this)->getSubExpr()
2676
322
               ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2677
1.14k
  case ExprWithCleanupsClass:
2678
1.14k
    return cast<ExprWithCleanups>(this)->getSubExpr()
2679
1.14k
               ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2680
1.53M
  }
2681
1.53M
}
2682
2683
/// isOBJCGCCandidate - Check if an expression is objc gc'able.
2684
/// returns true, if it is; false otherwise.
2685
495
bool Expr::isOBJCGCCandidate(ASTContext &Ctx) const {
2686
495
  const Expr *E = IgnoreParens();
2687
495
  switch (E->getStmtClass()) {
2688
4
  default:
2689
4
    return false;
2690
64
  case ObjCIvarRefExprClass:
2691
64
    return true;
2692
15
  case Expr::UnaryOperatorClass:
2693
15
    return cast<UnaryOperator>(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
2694
149
  case ImplicitCastExprClass:
2695
149
    return cast<ImplicitCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
2696
0
  case MaterializeTemporaryExprClass:
2697
0
    return cast<MaterializeTemporaryExpr>(E)->getSubExpr()->isOBJCGCCandidate(
2698
0
        Ctx);
2699
3
  case CStyleCastExprClass:
2700
3
    return cast<CStyleCastExpr>(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
2701
69
  case DeclRefExprClass: {
2702
69
    const Decl *D = cast<DeclRefExpr>(E)->getDecl();
2703
2704
69
    if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2705
69
      if (VD->hasGlobalStorage())
2706
56
        return true;
2707
13
      QualType T = VD->getType();
2708
      // dereferencing to a  pointer is always a gc'able candidate,
2709
      // unless it is __weak.
2710
13
      return T->isPointerType() &&
2711
11
             (Ctx.getObjCGCAttrKind(T) != Qualifiers::Weak);
2712
13
    }
2713
0
    return false;
2714
0
  }
2715
56
  case MemberExprClass: {
2716
56
    const MemberExpr *M = cast<MemberExpr>(E);
2717
56
    return M->getBase()->isOBJCGCCandidate(Ctx);
2718
0
  }
2719
135
  case ArraySubscriptExprClass:
2720
135
    return cast<ArraySubscriptExpr>(E)->getBase()->isOBJCGCCandidate(Ctx);
2721
495
  }
2722
495
}
2723
2724
0
bool Expr::isBoundMemberFunction(ASTContext &Ctx) const {
2725
0
  if (isTypeDependent())
2726
0
    return false;
2727
0
  return ClassifyLValue(Ctx) == Expr::LV_MemberFunction;
2728
0
}
2729
2730
241k
QualType Expr::findBoundMemberType(const Expr *expr) {
2731
241k
  assert(expr->hasPlaceholderType(BuiltinType::BoundMember));
2732
2733
  // Bound member expressions are always one of these possibilities:
2734
  //   x->m      x.m      x->*y      x.*y
2735
  // (possibly parenthesized)
2736
2737
241k
  expr = expr->IgnoreParens();
2738
241k
  if (const MemberExpr *mem = dyn_cast<MemberExpr>(expr)) {
2739
240k
    assert(isa<CXXMethodDecl>(mem->getMemberDecl()));
2740
240k
    return mem->getMemberDecl()->getType();
2741
240k
  }
2742
2743
494
  if (const BinaryOperator *op = dyn_cast<BinaryOperator>(expr)) {
2744
484
    QualType type = op->getRHS()->getType()->castAs<MemberPointerType>()
2745
484
                      ->getPointeeType();
2746
484
    assert(type->isFunctionType());
2747
484
    return type;
2748
484
  }
2749
2750
10
  assert(isa<UnresolvedMemberExpr>(expr) || isa<CXXPseudoDestructorExpr>(expr));
2751
10
  return QualType();
2752
10
}
2753
2754
8.77M
Expr *Expr::IgnoreImpCasts() {
2755
8.77M
  return IgnoreExprNodes(this, IgnoreImplicitCastsSingleStep);
2756
8.77M
}
2757
2758
1.07k
Expr *Expr::IgnoreCasts() {
2759
1.07k
  return IgnoreExprNodes(this, IgnoreCastsSingleStep);
2760
1.07k
}
2761
2762
5.46M
Expr *Expr::IgnoreImplicit() {
2763
5.46M
  return IgnoreExprNodes(this, IgnoreImplicitSingleStep);
2764
5.46M
}
2765
2766
1.47k
Expr *Expr::IgnoreImplicitAsWritten() {
2767
1.47k
  return IgnoreExprNodes(this, IgnoreImplicitAsWrittenSingleStep);
2768
1.47k
}
2769
2770
93.3M
Expr *Expr::IgnoreParens() {
2771
93.3M
  return IgnoreExprNodes(this, IgnoreParensSingleStep);
2772
93.3M
}
2773
2774
106M
Expr *Expr::IgnoreParenImpCasts() {
2775
106M
  return IgnoreExprNodes(this, IgnoreParensSingleStep,
2776
106M
                         IgnoreImplicitCastsExtraSingleStep);
2777
106M
}
2778
2779
71.5M
Expr *Expr::IgnoreParenCasts() {
2780
71.5M
  return IgnoreExprNodes(this, IgnoreParensSingleStep, IgnoreCastsSingleStep);
2781
71.5M
}
2782
2783
245k
Expr *Expr::IgnoreConversionOperatorSingleStep() {
2784
245k
  if (auto *MCE = dyn_cast<CXXMemberCallExpr>(this)) {
2785
692
    if (MCE->getMethodDecl() && 
isa<CXXConversionDecl>(MCE->getMethodDecl())690
)
2786
66
      return MCE->getImplicitObjectArgument();
2787
245k
  }
2788
245k
  return this;
2789
245k
}
2790
2791
58.6k
Expr *Expr::IgnoreParenLValueCasts() {
2792
58.6k
  return IgnoreExprNodes(this, IgnoreParensSingleStep,
2793
58.6k
                         IgnoreLValueCastsSingleStep);
2794
58.6k
}
2795
2796
35.7k
Expr *Expr::IgnoreParenBaseCasts() {
2797
35.7k
  return IgnoreExprNodes(this, IgnoreParensSingleStep,
2798
35.7k
                         IgnoreBaseCastsSingleStep);
2799
35.7k
}
2800
2801
23.6k
Expr *Expr::IgnoreParenNoopCasts(const ASTContext &Ctx) {
2802
27.3k
  auto IgnoreNoopCastsSingleStep = [&Ctx](Expr *E) {
2803
27.3k
    if (auto *CE = dyn_cast<CastExpr>(E)) {
2804
      // We ignore integer <-> casts that are of the same width, ptr<->ptr and
2805
      // ptr<->int casts of the same width. We also ignore all identity casts.
2806
4.09k
      Expr *SubExpr = CE->getSubExpr();
2807
4.09k
      bool IsIdentityCast =
2808
4.09k
          Ctx.hasSameUnqualifiedType(E->getType(), SubExpr->getType());
2809
4.09k
      bool IsSameWidthCast = (E->getType()->isPointerType() ||
2810
3.07k
                              E->getType()->isIntegralType(Ctx)) &&
2811
2.26k
                             (SubExpr->getType()->isPointerType() ||
2812
1.78k
                              SubExpr->getType()->isIntegralType(Ctx)) &&
2813
1.73k
                             (Ctx.getTypeSize(E->getType()) ==
2814
1.73k
                              Ctx.getTypeSize(SubExpr->getType()));
2815
2816
4.09k
      if (IsIdentityCast || 
IsSameWidthCast1.37k
)
2817
3.03k
        return SubExpr;
2818
23.2k
    } else if (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
2819
0
      return NTTP->getReplacement();
2820
2821
24.2k
    return E;
2822
24.2k
  };
2823
23.6k
  return IgnoreExprNodes(this, IgnoreParensSingleStep,
2824
23.6k
                         IgnoreNoopCastsSingleStep);
2825
23.6k
}
2826
2827
34.5k
Expr *Expr::IgnoreUnlessSpelledInSource() {
2828
37.1k
  auto IgnoreImplicitConstructorSingleStep = [](Expr *E) {
2829
37.1k
    if (auto *Cast = dyn_cast<CXXFunctionalCastExpr>(E)) {
2830
21
      auto *SE = Cast->getSubExpr();
2831
21
      if (SE->getSourceRange() == E->getSourceRange())
2832
9
        return SE;
2833
37.1k
    }
2834
2835
37.1k
    if (auto *C = dyn_cast<CXXConstructExpr>(E)) {
2836
4.20k
      auto NumArgs = C->getNumArgs();
2837
4.20k
      if (NumArgs == 1 ||
2838
3.90k
          (NumArgs > 1 && 
isa<CXXDefaultArgExpr>(C->getArg(1))23
)) {
2839
300
        Expr *A = C->getArg(0);
2840
300
        if (A->getSourceRange() == E->getSourceRange() || 
C->isElidable()263
)
2841
49
          return A;
2842
37.1k
      }
2843
4.20k
    }
2844
37.1k
    return E;
2845
37.1k
  };
2846
37.1k
  auto IgnoreImplicitMemberCallSingleStep = [](Expr *E) {
2847
37.1k
    if (auto *C = dyn_cast<CXXMemberCallExpr>(E)) {
2848
22
      Expr *ExprNode = C->getImplicitObjectArgument();
2849
22
      if (ExprNode->getSourceRange() == E->getSourceRange()) {
2850
11
        return ExprNode;
2851
11
      }
2852
11
      if (auto *PE = dyn_cast<ParenExpr>(ExprNode)) {
2853
1
        if (PE->getSourceRange() == C->getSourceRange()) {
2854
0
          return cast<Expr>(PE);
2855
0
        }
2856
11
      }
2857
11
      ExprNode = ExprNode->IgnoreParenImpCasts();
2858
11
      if (ExprNode->getSourceRange() == E->getSourceRange())
2859
0
        return ExprNode;
2860
37.1k
    }
2861
37.1k
    return E;
2862
37.1k
  };
2863
34.5k
  return IgnoreExprNodes(
2864
34.5k
      this, IgnoreImplicitSingleStep, IgnoreImplicitCastsExtraSingleStep,
2865
34.5k
      IgnoreParensOnlySingleStep, IgnoreImplicitConstructorSingleStep,
2866
34.5k
      IgnoreImplicitMemberCallSingleStep);
2867
34.5k
}
2868
2869
690k
bool Expr::isDefaultArgument() const {
2870
690k
  const Expr *E = this;
2871
690k
  if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E))
2872
166k
    E = M->getSubExpr();
2873
2874
841k
  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
2875
150k
    E = ICE->getSubExprAsWritten();
2876
2877
690k
  return isa<CXXDefaultArgExpr>(E);
2878
690k
}
2879
2880
/// Skip over any no-op casts and any temporary-binding
2881
/// expressions.
2882
129k
static const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) {
2883
129k
  if (const MaterializeTemporaryExpr *M = dyn_cast<MaterializeTemporaryExpr>(E))
2884
68.2k
    E = M->getSubExpr();
2885
2886
175k
  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
2887
51.0k
    if (ICE->getCastKind() == CK_NoOp)
2888
45.9k
      E = ICE->getSubExpr();
2889
5.09k
    else
2890
5.09k
      break;
2891
51.0k
  }
2892
2893
144k
  while (const CXXBindTemporaryExpr *BE = dyn_cast<CXXBindTemporaryExpr>(E))
2894
14.2k
    E = BE->getSubExpr();
2895
2896
129k
  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
2897
10.4k
    if (ICE->getCastKind() == CK_NoOp)
2898
0
      E = ICE->getSubExpr();
2899
10.4k
    else
2900
10.4k
      break;
2901
10.4k
  }
2902
2903
129k
  return E->IgnoreParens();
2904
129k
}
2905
2906
/// isTemporaryObject - Determines if this expression produces a
2907
/// temporary of the given class type.
2908
129k
bool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const {
2909
129k
  if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy)))
2910
19
    return false;
2911
2912
129k
  const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this);
2913
2914
  // Temporaries are by definition pr-values of class type.
2915
129k
  if (!E->Classify(C).isPRValue()) {
2916
    // In this context, property reference is a message call and is pr-value.
2917
54.9k
    if (!isa<ObjCPropertyRefExpr>(E))
2918
54.9k
      return false;
2919
74.8k
  }
2920
2921
  // Black-list a few cases which yield pr-values of class type that don't
2922
  // refer to temporaries of that type:
2923
2924
  // - implicit derived-to-base conversions
2925
74.8k
  if (isa<ImplicitCastExpr>(E)) {
2926
9.60k
    switch (cast<ImplicitCastExpr>(E)->getCastKind()) {
2927
0
    case CK_DerivedToBase:
2928
0
    case CK_UncheckedDerivedToBase:
2929
0
      return false;
2930
9.60k
    default:
2931
9.60k
      break;
2932
74.8k
    }
2933
74.8k
  }
2934
2935
  // - member expressions (all)
2936
74.8k
  if (isa<MemberExpr>(E))
2937
0
    return false;
2938
2939
74.8k
  if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E))
2940
48
    if (BO->isPtrMemOp())
2941
0
      return false;
2942
2943
  // - opaque values (all)
2944
74.8k
  if (isa<OpaqueValueExpr>(E))
2945
13
    return false;
2946
2947
74.8k
  return true;
2948
74.8k
}
2949
2950
9.59M
bool Expr::isImplicitCXXThis() const {
2951
9.59M
  const Expr *E = this;
2952
2953
  // Strip away parentheses and casts we don't care about.
2954
10.9M
  while (true) {
2955
10.9M
    if (const ParenExpr *Paren = dyn_cast<ParenExpr>(E)) {
2956
73.8k
      E = Paren->getSubExpr();
2957
73.8k
      continue;
2958
73.8k
    }
2959
2960
10.8M
    if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
2961
1.18M
      if (ICE->getCastKind() == CK_NoOp ||
2962
833k
          ICE->getCastKind() == CK_LValueToRValue ||
2963
107k
          ICE->getCastKind() == CK_DerivedToBase ||
2964
1.18M
          
ICE->getCastKind() == CK_UncheckedDerivedToBase107k
) {
2965
1.18M
        E = ICE->getSubExpr();
2966
1.18M
        continue;
2967
1.18M
      }
2968
9.69M
    }
2969
2970
9.69M
    if (const UnaryOperator* UnOp = dyn_cast<UnaryOperator>(E)) {
2971
8.65k
      if (UnOp->getOpcode() == UO_Extension) {
2972
0
        E = UnOp->getSubExpr();
2973
0
        continue;
2974
0
      }
2975
9.69M
    }
2976
2977
9.69M
    if (const MaterializeTemporaryExpr *M
2978
99.5k
                                      = dyn_cast<MaterializeTemporaryExpr>(E)) {
2979
99.5k
      E = M->getSubExpr();
2980
99.5k
      continue;
2981
99.5k
    }
2982
2983
9.59M
    break;
2984
9.59M
  }
2985
2986
9.59M
  if (const CXXThisExpr *This = dyn_cast<CXXThisExpr>(E))
2987
2.73M
    return This->isImplicit();
2988
2989
6.86M
  return false;
2990
6.86M
}
2991
2992
/// hasAnyTypeDependentArguments - Determines if any of the expressions
2993
/// in Exprs is type-dependent.
2994
16.6M
bool Expr::hasAnyTypeDependentArguments(ArrayRef<Expr *> Exprs) {
2995
36.2M
  for (unsigned I = 0; I < Exprs.size(); 
++I19.5M
)
2996
19.9M
    if (Exprs[I]->isTypeDependent())
2997
435k
      return true;
2998
2999
16.2M
  return false;
3000
16.6M
}
3001
3002
bool Expr::isConstantInitializer(ASTContext &Ctx, bool IsForRef,
3003
72.6k
                                 const Expr **Culprit) const {
3004
72.6k
  assert(!isValueDependent() &&
3005
72.6k
         "Expression evaluator can't be called on a dependent expression.");
3006
3007
  // This function is attempting whether an expression is an initializer
3008
  // which can be evaluated at compile-time. It very closely parallels
3009
  // ConstExprEmitter in CGExprConstant.cpp; if they don't match, it
3010
  // will lead to unexpected results.  Like ConstExprEmitter, it falls back
3011
  // to isEvaluatable most of the time.
3012
  //
3013
  // If we ever capture reference-binding directly in the AST, we can
3014
  // kill the second parameter.
3015
3016
72.6k
  if (IsForRef) {
3017
134
    EvalResult Result;
3018
134
    if (EvaluateAsLValue(Result, Ctx) && 
!Result.HasSideEffects90
)
3019
90
      return true;
3020
44
    if (Culprit)
3021
44
      *Culprit = this;
3022
44
    return false;
3023
44
  }
3024
3025
72.5k
  switch (getStmtClass()) {
3026
14.2k
  default: break;
3027
192
  case Stmt::ExprWithCleanupsClass:
3028
192
    return cast<ExprWithCleanups>(this)->getSubExpr()->isConstantInitializer(
3029
192
        Ctx, IsForRef, Culprit);
3030
209
  case StringLiteralClass:
3031
271
  case ObjCEncodeExprClass:
3032
271
    return true;
3033
21
  case CXXTemporaryObjectExprClass:
3034
5.52k
  case CXXConstructExprClass: {
3035
5.52k
    const CXXConstructExpr *CE = cast<CXXConstructExpr>(this);
3036
3037
5.52k
    if (CE->getConstructor()->isTrivial() &&
3038
4.14k
        CE->getConstructor()->getParent()->hasTrivialDestructor()) {
3039
      // Trivial default constructor
3040
4.13k
      if (!CE->getNumArgs()) 
return true3.88k
;
3041
3042
      // Trivial copy constructor
3043
250
      assert(CE->getNumArgs() == 1 && "trivial ctor with > 1 argument");
3044
250
      return CE->getArg(0)->isConstantInitializer(Ctx, false, Culprit);
3045
250
    }
3046
3047
1.39k
    break;
3048
1.39k
  }
3049
4.83k
  case ConstantExprClass: {
3050
    // FIXME: We should be able to return "true" here, but it can lead to extra
3051
    // error messages. E.g. in Sema/array-init.c.
3052
4.83k
    const Expr *Exp = cast<ConstantExpr>(this)->getSubExpr();
3053
4.83k
    return Exp->isConstantInitializer(Ctx, false, Culprit);
3054
1.39k
  }
3055
88
  case CompoundLiteralExprClass: {
3056
    // This handles gcc's extension that allows global initializers like
3057
    // "struct x {int x;} x = (struct x) {};".
3058
    // FIXME: This accepts other cases it shouldn't!
3059
88
    const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer();
3060
88
    return Exp->isConstantInitializer(Ctx, false, Culprit);
3061
1.39k
  }
3062
30
  case DesignatedInitUpdateExprClass: {
3063
30
    const DesignatedInitUpdateExpr *DIUE = cast<DesignatedInitUpdateExpr>(this);
3064
30
    return DIUE->getBase()->isConstantInitializer(Ctx, false, Culprit) &&
3065
24
           DIUE->getUpdater()->isConstantInitializer(Ctx, false, Culprit);
3066
1.39k
  }
3067
9.97k
  case InitListExprClass: {
3068
9.97k
    const InitListExpr *ILE = cast<InitListExpr>(this);
3069
9.97k
    assert(ILE->isSemanticForm() && "InitListExpr must be in semantic form");
3070
9.97k
    if (ILE->getType()->isArrayType()) {
3071
3.85k
      unsigned numInits = ILE->getNumInits();
3072
24.6k
      for (unsigned i = 0; i < numInits; 
i++20.7k
) {
3073
20.9k
        if (!ILE->getInit(i)->isConstantInitializer(Ctx, false, Culprit))
3074
157
          return false;
3075
20.9k
      }
3076
3.70k
      return true;
3077
6.11k
    }
3078
3079
6.11k
    if (ILE->getType()->isRecordType()) {
3080
5.35k
      unsigned ElementNo = 0;
3081
5.35k
      RecordDecl *RD = ILE->getType()->castAs<RecordType>()->getDecl();
3082
13.6k
      for (const auto *Field : RD->fields()) {
3083
        // If this is a union, skip all the fields that aren't being initialized.
3084
13.6k
        if (RD->isUnion() && 
ILE->getInitializedFieldInUnion() != Field1.11k
)
3085
554
          continue;
3086
3087
        // Don't emit anonymous bitfields, they just affect layout.
3088
13.1k
        if (Field->isUnnamedBitfield())
3089
61
          continue;
3090
3091
13.0k
        if (ElementNo < ILE->getNumInits()) {
3092
12.9k
          const Expr *Elt = ILE->getInit(ElementNo++);
3093
12.9k
          if (Field->isBitField()) {
3094
            // Bitfields have to evaluate to an integer.
3095
239
            EvalResult Result;
3096
239
            if (!Elt->EvaluateAsInt(Result, Ctx)) {
3097
3
              if (Culprit)
3098
3
                *Culprit = Elt;
3099
3
              return false;
3100
3
            }
3101
12.7k
          } else {
3102
12.7k
            bool RefType = Field->getType()->isReferenceType();
3103
12.7k
            if (!Elt->isConstantInitializer(Ctx, RefType, Culprit))
3104
160
              return false;
3105
12.7k
          }
3106
12.9k
        }
3107
13.0k
      }
3108
5.18k
      return true;
3109
765
    }
3110
3111
765
    break;
3112
765
  }
3113
6.48k
  case ImplicitValueInitExprClass:
3114
6.53k
  case NoInitExprClass:
3115
6.53k
    return true;
3116
629
  case ParenExprClass:
3117
629
    return cast<ParenExpr>(this)->getSubExpr()
3118
629
      ->isConstantInitializer(Ctx, IsForRef, Culprit);
3119
3
  case GenericSelectionExprClass:
3120
3
    return cast<GenericSelectionExpr>(this)->getResultExpr()
3121
3
      ->isConstantInitializer(Ctx, IsForRef, Culprit);
3122
4
  case ChooseExprClass:
3123
4
    if (cast<ChooseExpr>(this)->isConditionDependent()) {
3124
0
      if (Culprit)
3125
0
        *Culprit = this;
3126
0
      return false;
3127
0
    }
3128
4
    return cast<ChooseExpr>(this)->getChosenSubExpr()
3129
4
      ->isConstantInitializer(Ctx, IsForRef, Culprit);
3130
1.44k
  case UnaryOperatorClass: {
3131
1.44k
    const UnaryOperator* Exp = cast<UnaryOperator>(this);
3132
1.44k
    if (Exp->getOpcode() == UO_Extension)
3133
9
      return Exp->getSubExpr()->isConstantInitializer(Ctx, false, Culprit);
3134
1.43k
    break;
3135
1.43k
  }
3136
43
  case CXXFunctionalCastExprClass:
3137
78
  case CXXStaticCastExprClass:
3138
26.9k
  case ImplicitCastExprClass:
3139
28.5k
  case CStyleCastExprClass:
3140
28.5k
  case ObjCBridgedCastExprClass:
3141
28.5k
  case CXXDynamicCastExprClass:
3142
28.6k
  case CXXReinterpretCastExprClass:
3143
28.6k
  case CXXAddrspaceCastExprClass:
3144
28.6k
  case CXXConstCastExprClass: {
3145
28.6k
    const CastExpr *CE = cast<CastExpr>(this);
3146
3147
    // Handle misc casts we want to ignore.
3148
28.6k
    if (CE->getCastKind() == CK_NoOp ||
3149
27.4k
        CE->getCastKind() == CK_LValueToRValue ||
3150
25.7k
        CE->getCastKind() == CK_ToUnion ||
3151
25.7k
        CE->getCastKind() == CK_ConstructorConversion ||
3152
25.7k
        CE->getCastKind() == CK_NonAtomicToAtomic ||
3153
25.7k
        CE->getCastKind() == CK_AtomicToNonAtomic ||
3154
25.7k
        CE->getCastKind() == CK_IntToOCLSampler)
3155
2.97k
      return CE->getSubExpr()->isConstantInitializer(Ctx, false, Culprit);
3156
3157
25.6k
    break;
3158
25.6k
  }
3159
104
  case MaterializeTemporaryExprClass:
3160
104
    return cast<MaterializeTemporaryExpr>(this)
3161
104
        ->getSubExpr()
3162
104
        ->isConstantInitializer(Ctx, false, Culprit);
3163
3164
16
  case SubstNonTypeTemplateParmExprClass:
3165
16
    return cast<SubstNonTypeTemplateParmExpr>(this)->getReplacement()
3166
16
      ->isConstantInitializer(Ctx, false, Culprit);
3167
0
  case CXXDefaultArgExprClass:
3168
0
    return cast<CXXDefaultArgExpr>(this)->getExpr()
3169
0
      ->isConstantInitializer(Ctx, false, Culprit);
3170
0
  case CXXDefaultInitExprClass:
3171
0
    return cast<CXXDefaultInitExpr>(this)->getExpr()
3172
0
      ->isConstantInitializer(Ctx, false, Culprit);
3173
43.5k
  }
3174
  // Allow certain forms of UB in constant initializers: signed integer
3175
  // overflow and floating-point division by zero. We'll give a warning on
3176
  // these, but they're common enough that we have to accept them.
3177
43.5k
  if (isEvaluatable(Ctx, SE_AllowUndefinedBehavior))
3178
39.2k
    return true;
3179
4.26k
  if (Culprit)
3180
2.39k
    *Culprit = this;
3181
4.26k
  return false;
3182
4.26k
}
3183
3184
206k
bool CallExpr::isBuiltinAssumeFalse(const ASTContext &Ctx) const {
3185
206k
  const FunctionDecl* FD = getDirectCallee();
3186
206k
  if (!FD || (FD->getBuiltinID() != Builtin::BI__assume &&
3187
206k
              FD->getBuiltinID() != Builtin::BI__builtin_assume))
3188
206k
    return false;
3189
3190
55
  const Expr* Arg = getArg(0);
3191
55
  bool ArgVal;
3192
55
  return !Arg->isValueDependent() &&
3193
55
         Arg->EvaluateAsBooleanCondition(ArgVal, Ctx) && 
!ArgVal21
;
3194
55
}
3195
3196
namespace {
3197
  /// Look for any side effects within a Stmt.
3198
  class SideEffectFinder : public ConstEvaluatedExprVisitor<SideEffectFinder> {
3199
    typedef ConstEvaluatedExprVisitor<SideEffectFinder> Inherited;
3200
    const bool IncludePossibleEffects;
3201
    bool HasSideEffects;
3202
3203
  public:
3204
    explicit SideEffectFinder(const ASTContext &Context, bool IncludePossible)
3205
      : Inherited(Context),
3206
26
        IncludePossibleEffects(IncludePossible), HasSideEffects(false) { }
3207
3208
26
    bool hasSideEffects() const { return HasSideEffects; }
3209
3210
5
    void VisitDecl(const Decl *D) {
3211
5
      if (!D)
3212
0
        return;
3213
3214
      // We assume the caller checks subexpressions (eg, the initializer, VLA
3215
      // bounds) for side-effects on our behalf.
3216
5
      if (auto *VD = dyn_cast<VarDecl>(D)) {
3217
        // Registering a destructor is a side-effect.
3218
3
        if (IncludePossibleEffects && 
VD->isThisDeclarationADefinition()2
&&
3219
2
            VD->needsDestruction(Context))
3220
2
          HasSideEffects = true;
3221
3
      }
3222
5
    }
3223
3224
5
    void VisitDeclStmt(const DeclStmt *DS) {
3225
5
      for (auto *D : DS->decls())
3226
5
        VisitDecl(D);
3227
5
      Inherited::VisitDeclStmt(DS);
3228
5
    }
3229
3230
49
    void VisitExpr(const Expr *E) {
3231
49
      if (!HasSideEffects &&
3232
37
          E->HasSideEffects(Context, IncludePossibleEffects))
3233
13
        HasSideEffects = true;
3234
49
    }
3235
  };
3236
}
3237
3238
bool Expr::HasSideEffects(const ASTContext &Ctx,
3239
557k
                          bool IncludePossibleEffects) const {
3240
  // In circumstances where we care about definite side effects instead of
3241
  // potential side effects, we want to ignore expressions that are part of a
3242
  // macro expansion as a potential side effect.
3243
557k
  if (!IncludePossibleEffects && 
getExprLoc().isMacroID()19.5k
)
3244
2.80k
    return false;
3245
3246
554k
  switch (getStmtClass()) {
3247
0
  case NoStmtClass:
3248
0
  #define ABSTRACT_STMT(Type)
3249
0
  #define STMT(Type, Base) case Type##Class:
3250
0
  #define EXPR(Type, Base)
3251
0
  #include "clang/AST/StmtNodes.inc"
3252
0
    llvm_unreachable("unexpected Expr kind");
3253
3254
0
  case DependentScopeDeclRefExprClass:
3255
11
  case CXXUnresolvedConstructExprClass:
3256
11
  case CXXDependentScopeMemberExprClass:
3257
13
  case UnresolvedLookupExprClass:
3258
13
  case UnresolvedMemberExprClass:
3259
13
  case PackExpansionExprClass:
3260
13
  case SubstNonTypeTemplateParmPackExprClass:
3261
13
  case FunctionParmPackExprClass:
3262
13
  case TypoExprClass:
3263
114
  case RecoveryExprClass:
3264
114
  case CXXFoldExprClass:
3265
    // Make a conservative assumption for dependent nodes.
3266
114
    return IncludePossibleEffects;
3267
3268
99.7k
  case DeclRefExprClass:
3269
99.7k
  case ObjCIvarRefExprClass:
3270
99.8k
  case PredefinedExprClass:
3271
153k
  case IntegerLiteralClass:
3272
153k
  case FixedPointLiteralClass:
3273
156k
  case FloatingLiteralClass:
3274
156k
  case ImaginaryLiteralClass:
3275
165k
  case StringLiteralClass:
3276
168k
  case CharacterLiteralClass:
3277
168k
  case OffsetOfExprClass:
3278
183k
  case ImplicitValueInitExprClass:
3279
184k
  case UnaryExprOrTypeTraitExprClass:
3280
184k
  case AddrLabelExprClass:
3281
184k
  case GNUNullExprClass:
3282
185k
  case ArrayInitIndexExprClass:
3283
185k
  case NoInitExprClass:
3284
196k
  case CXXBoolLiteralExprClass:
3285
199k
  case CXXNullPtrLiteralExprClass:
3286
200k
  case CXXThisExprClass:
3287
200k
  case CXXScalarValueInitExprClass:
3288
201k
  case TypeTraitExprClass:
3289
201k
  case ArrayTypeTraitExprClass:
3290
201k
  case ExpressionTraitExprClass:
3291
201k
  case CXXNoexceptExprClass:
3292
201k
  case SizeOfPackExprClass:
3293
201k
  case ObjCStringLiteralClass:
3294
201k
  case ObjCEncodeExprClass:
3295
201k
  case ObjCBoolLiteralExprClass:
3296
201k
  case ObjCAvailabilityCheckExprClass:
3297
201k
  case CXXUuidofExprClass:
3298
203k
  case OpaqueValueExprClass:
3299
203k
  case SourceLocExprClass:
3300
203k
  case ConceptSpecializationExprClass:
3301
203k
  case RequiresExprClass:
3302
    // These never have a side-effect.
3303
203k
    return false;
3304
3305
11.4k
  case ConstantExprClass:
3306
    // FIXME: Move this into the "return false;" block above.
3307
11.4k
    return cast<ConstantExpr>(this)->getSubExpr()->HasSideEffects(
3308
11.4k
        Ctx, IncludePossibleEffects);
3309
3310
8.62k
  case CallExprClass:
3311
9.01k
  case CXXOperatorCallExprClass:
3312
11.6k
  case CXXMemberCallExprClass:
3313
11.6k
  case CUDAKernelCallExprClass:
3314
11.6k
  case UserDefinedLiteralClass: {
3315
    // We don't know a call definitely has side effects, except for calls
3316
    // to pure/const functions that definitely don't.
3317
    // If the call itself is considered side-effect free, check the operands.
3318
11.6k
    const Decl *FD = cast<CallExpr>(this)->getCalleeDecl();
3319
11.6k
    bool IsPure = FD && 
(11.6k
FD->hasAttr<ConstAttr>()11.6k
||
FD->hasAttr<PureAttr>()11.5k
);
3320
11.6k
    if (IsPure || 
!IncludePossibleEffects11.5k
)
3321
842
      break;
3322
10.7k
    return true;
3323
10.7k
  }
3324
3325
52
  case BlockExprClass:
3326
213
  case CXXBindTemporaryExprClass:
3327
213
    if (!IncludePossibleEffects)
3328
142
      break;
3329
71
    return true;
3330
3331
0
  case MSPropertyRefExprClass:
3332
0
  case MSPropertySubscriptExprClass:
3333
1.83k
  case CompoundAssignOperatorClass:
3334
1.83k
  case VAArgExprClass:
3335
1.83k
  case AtomicExprClass:
3336
1.84k
  case CXXThrowExprClass:
3337
2.00k
  case CXXNewExprClass:
3338
2.00k
  case CXXDeleteExprClass:
3339
2.00k
  case CoawaitExprClass:
3340
2.00k
  case DependentCoawaitExprClass:
3341
2.00k
  case CoyieldExprClass:
3342
    // These always have a side-effect.
3343
2.00k
    return true;
3344
3345
26
  case StmtExprClass: {
3346
    // StmtExprs have a side-effect if any substatement does.
3347
26
    SideEffectFinder Finder(Ctx, IncludePossibleEffects);
3348
26
    Finder.Visit(cast<StmtExpr>(this)->getSubStmt());
3349
26
    return Finder.hasSideEffects();
3350
2.00k
  }
3351
3352
12.8k
  case ExprWithCleanupsClass:
3353
12.8k
    if (IncludePossibleEffects)
3354
12.8k
      if (cast<ExprWithCleanups>(this)->cleanupsHaveSideEffects())
3355
232
        return true;
3356
12.5k
    break;
3357
3358
7.81k
  case ParenExprClass:
3359
9.36k
  case ArraySubscriptExprClass:
3360
9.36k
  case MatrixSubscriptExprClass:
3361
9.36k
  case OMPArraySectionExprClass:
3362
9.36k
  case OMPArrayShapingExprClass:
3363
9.36k
  case OMPIteratorExprClass:
3364
45.2k
  case MemberExprClass:
3365
45.7k
  case ConditionalOperatorClass:
3366
45.7k
  case BinaryConditionalOperatorClass:
3367
45.9k
  case CompoundLiteralExprClass:
3368
46.0k
  case ExtVectorElementExprClass:
3369
46.0k
  case DesignatedInitExprClass:
3370
46.0k
  case DesignatedInitUpdateExprClass:
3371
46.7k
  case ArrayInitLoopExprClass:
3372
46.7k
  case ParenListExprClass:
3373
46.7k
  case CXXPseudoDestructorExprClass:
3374
46.7k
  case CXXRewrittenBinaryOperatorClass:
3375
46.8k
  case CXXStdInitializerListExprClass:
3376
55.9k
  case SubstNonTypeTemplateParmExprClass:
3377
63.6k
  case MaterializeTemporaryExprClass:
3378
63.6k
  case ShuffleVectorExprClass:
3379
63.6k
  case ConvertVectorExprClass:
3380
63.6k
  case AsTypeExprClass:
3381
    // These have a side-effect if any subexpression does.
3382
63.6k
    break;
3383
3384
9.88k
  case UnaryOperatorClass:
3385
9.88k
    if (cast<UnaryOperator>(this)->isIncrementDecrementOp())
3386
487
      return true;
3387
9.39k
    break;
3388
3389
14.2k
  case BinaryOperatorClass:
3390
14.2k
    if (cast<BinaryOperator>(this)->isAssignmentOp())
3391
774
      return true;
3392
13.4k
    break;
3393
3394
18.4k
  case InitListExprClass:
3395
    // FIXME: The children for an InitListExpr doesn't include the array filler.
3396
18.4k
    if (const Expr *E = cast<InitListExpr>(this)->getArrayFiller())
3397
550
      if (E->HasSideEffects(Ctx, IncludePossibleEffects))
3398
4
        return true;
3399
18.4k
    break;
3400
3401
1
  case GenericSelectionExprClass:
3402
1
    return cast<GenericSelectionExpr>(this)->getResultExpr()->
3403
1
        HasSideEffects(Ctx, IncludePossibleEffects);
3404
3405
4
  case ChooseExprClass:
3406
4
    return cast<ChooseExpr>(this)->getChosenSubExpr()->HasSideEffects(
3407
4
        Ctx, IncludePossibleEffects);
3408
3409
4
  case CXXDefaultArgExprClass:
3410
4
    return cast<CXXDefaultArgExpr>(this)->getExpr()->HasSideEffects(
3411
4
        Ctx, IncludePossibleEffects);
3412
3413
1.66k
  case CXXDefaultInitExprClass: {
3414
1.66k
    const FieldDecl *FD = cast<CXXDefaultInitExpr>(this)->getField();
3415
1.66k
    if (const Expr *E = FD->getInClassInitializer())
3416
1.66k
      return E->HasSideEffects(Ctx, IncludePossibleEffects);
3417
    // If we've not yet parsed the initializer, assume it has side-effects.
3418
0
    return true;
3419
0
  }
3420
3421
71
  case CXXDynamicCastExprClass: {
3422
    // A dynamic_cast expression has side-effects if it can throw.
3423
71
    const CXXDynamicCastExpr *DCE = cast<CXXDynamicCastExpr>(this);
3424
71
    if (DCE->getTypeAsWritten()->isReferenceType() &&
3425
22
        DCE->getCastKind() == CK_Dynamic)
3426
22
      return true;
3427
49
    }
3428
49
    LLVM_FALLTHROUGH;
3429
145k
  case ImplicitCastExprClass:
3430
149k
  case CStyleCastExprClass:
3431
166k
  case CXXStaticCastExprClass:
3432
166k
  case CXXReinterpretCastExprClass:
3433
166k
  case CXXConstCastExprClass:
3434
166k
  case CXXAddrspaceCastExprClass:
3435
168k
  case CXXFunctionalCastExprClass:
3436
168k
  case BuiltinBitCastExprClass: {
3437
    // While volatile reads are side-effecting in both C and C++, we treat them
3438
    // as having possible (not definite) side-effects. This allows idiomatic
3439
    // code to behave without warning, such as sizeof(*v) for a volatile-
3440
    // qualified pointer.
3441
168k
    if (!IncludePossibleEffects)
3442
2.39k
      break;
3443
3444
165k
    const CastExpr *CE = cast<CastExpr>(this);
3445
165k
    if (CE->getCastKind() == CK_LValueToRValue &&
3446
71.5k
        CE->getSubExpr()->getType().isVolatileQualified())
3447
1.14k
      return true;
3448
164k
    break;
3449
164k
  }
3450
3451
42
  case CXXTypeidExprClass:
3452
    // typeid might throw if its subexpression is potentially-evaluated, so has
3453
    // side-effects in that case whether or not its subexpression does.
3454
42
    return cast<CXXTypeidExpr>(this)->isPotentiallyEvaluated();
3455
3456
29.3k
  case CXXConstructExprClass:
3457
35.7k
  case CXXTemporaryObjectExprClass: {
3458
35.7k
    const CXXConstructExpr *CE = cast<CXXConstructExpr>(this);
3459
35.7k
    if (!CE->getConstructor()->isTrivial() && 
IncludePossibleEffects14.6k
)
3460
14.5k
      return true;
3461
    // A trivial constructor does not add any side-effects of its own. Just look
3462
    // at its arguments.
3463
21.2k
    break;
3464
21.2k
  }
3465
3466
0
  case CXXInheritedCtorInitExprClass: {
3467
0
    const auto *ICIE = cast<CXXInheritedCtorInitExpr>(this);
3468
0
    if (!ICIE->getConstructor()->isTrivial() && IncludePossibleEffects)
3469
0
      return true;
3470
0
    break;
3471
0
  }
3472
3473
1.22k
  case LambdaExprClass: {
3474
1.22k
    const LambdaExpr *LE = cast<LambdaExpr>(this);
3475
1.22k
    for (Expr *E : LE->capture_inits())
3476
97
      if (E && 
E->HasSideEffects(Ctx, IncludePossibleEffects)96
)
3477
6
        return true;
3478
1.22k
    return false;
3479
1.22k
  }
3480
3481
15
  case PseudoObjectExprClass: {
3482
    // Only look for side-effects in the semantic form, and look past
3483
    // OpaqueValueExpr bindings in that form.
3484
15
    const PseudoObjectExpr *PO = cast<PseudoObjectExpr>(this);
3485
15
    for (PseudoObjectExpr::const_semantics_iterator I = PO->semantics_begin(),
3486
15
                                                    E = PO->semantics_end();
3487
41
         I != E; 
++I26
) {
3488
28
      const Expr *Subexpr = *I;
3489
28
      if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(Subexpr))
3490
13
        Subexpr = OVE->getSourceExpr();
3491
28
      if (Subexpr->HasSideEffects(Ctx, IncludePossibleEffects))
3492
2
        return true;
3493
28
    }
3494
13
    return false;
3495
15
  }
3496
3497
0
  case ObjCBoxedExprClass:
3498
0
  case ObjCArrayLiteralClass:
3499
0
  case ObjCDictionaryLiteralClass:
3500
0
  case ObjCSelectorExprClass:
3501
0
  case ObjCProtocolExprClass:
3502
0
  case ObjCIsaExprClass:
3503
0
  case ObjCIndirectCopyRestoreExprClass:
3504
0
  case ObjCSubscriptRefExprClass:
3505
7
  case ObjCBridgedCastExprClass:
3506
58
  case ObjCMessageExprClass:
3507
58
  case ObjCPropertyRefExprClass:
3508
  // FIXME: Classify these cases better.
3509
58
    if (IncludePossibleEffects)
3510
39
      return true;
3511
19
    break;
3512
306k
  }
3513
3514
  // Recurse to children.
3515
306k
  for (const Stmt *SubStmt : children())
3516
342k
    if (SubStmt &&
3517
342k
        cast<Expr>(SubStmt)->HasSideEffects(Ctx, IncludePossibleEffects))
3518
15.2k
      return true;
3519
3520
291k
  return false;
3521
306k
}
3522
3523
160k
FPOptions Expr::getFPFeaturesInEffect(const LangOptions &LO) const {
3524
160k
  if (auto Call = dyn_cast<CallExpr>(this))
3525
3.24k
    return Call->getFPFeaturesInEffect(LO);
3526
157k
  if (auto UO = dyn_cast<UnaryOperator>(this))
3527
1.11k
    return UO->getFPFeaturesInEffect(LO);
3528
156k
  if (auto BO = dyn_cast<BinaryOperator>(this))
3529
80.3k
    return BO->getFPFeaturesInEffect(LO);
3530
76.0k
  if (auto Cast = dyn_cast<CastExpr>(this))
3531
74.5k
    return Cast->getFPFeaturesInEffect(LO);
3532
1.44k
  return FPOptions::defaultWithoutTrailingStorage(LO);
3533
1.44k
}
3534
3535
namespace {
3536
  /// Look for a call to a non-trivial function within an expression.
3537
  class NonTrivialCallFinder : public ConstEvaluatedExprVisitor<NonTrivialCallFinder>
3538
  {
3539
    typedef ConstEvaluatedExprVisitor<NonTrivialCallFinder> Inherited;
3540
3541
    bool NonTrivial;
3542
3543
  public:
3544
    explicit NonTrivialCallFinder(const ASTContext &Context)
3545
4.44k
      : Inherited(Context), NonTrivial(false) { }
3546
3547
4.44k
    bool hasNonTrivialCall() const { return NonTrivial; }
3548
3549
524
    void VisitCallExpr(const CallExpr *E) {
3550
524
      if (const CXXMethodDecl *Method
3551
280
          = dyn_cast_or_null<const CXXMethodDecl>(E->getCalleeDecl())) {
3552
280
        if (Method->isTrivial()) {
3553
          // Recurse to children of the call.
3554
186
          Inherited::VisitStmt(E);
3555
186
          return;
3556
186
        }
3557
338
      }
3558
3559
338
      NonTrivial = true;
3560
338
    }
3561
3562
228
    void VisitCXXConstructExpr(const CXXConstructExpr *E) {
3563
228
      if (E->getConstructor()->isTrivial()) {
3564
        // Recurse to children of the call.
3565
185
        Inherited::VisitStmt(E);
3566
185
        return;
3567
185
      }
3568
3569
43
      NonTrivial = true;
3570
43
    }
3571
3572
122
    void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E) {
3573
122
      if (E->getTemporary()->getDestructor()->isTrivial()) {
3574
0
        Inherited::VisitStmt(E);
3575
0
        return;
3576
0
      }
3577
3578
122
      NonTrivial = true;
3579
122
    }
3580
  };
3581
}
3582
3583
4.44k
bool Expr::hasNonTrivialCall(const ASTContext &Ctx) const {
3584
4.44k
  NonTrivialCallFinder Finder(Ctx);
3585
4.44k
  Finder.Visit(this);
3586
4.44k
  return Finder.hasNonTrivialCall();
3587
4.44k
}
3588
3589
/// isNullPointerConstant - C99 6.3.2.3p3 - Return whether this is a null
3590
/// pointer constant or not, as well as the specific kind of constant detected.
3591
/// Null pointer constants can be integer constant expressions with the
3592
/// value zero, casts of zero to void*, nullptr (C++0X), or __null
3593
/// (a GNU extension).
3594
Expr::NullPointerConstantKind
3595
Expr::isNullPointerConstant(ASTContext &Ctx,
3596
2.73M
                            NullPointerConstantValueDependence NPC) const {
3597
2.73M
  if (isValueDependent() &&
3598
18.8k
      (!Ctx.getLangOpts().CPlusPlus11 || 
Ctx.getLangOpts().MSVCCompat18.8k
)) {
3599
    // Error-dependent expr should never be a null pointer.
3600
22
    if (containsErrors())
3601
2
      return NPCK_NotNull;
3602
20
    switch (NPC) {
3603
0
    case NPC_NeverValueDependent:
3604
0
      llvm_unreachable("Unexpected value dependent expression!");
3605
16
    case NPC_ValueDependentIsNull:
3606
16
      if (isTypeDependent() || getType()->isIntegralType(Ctx))
3607
7
        return NPCK_ZeroExpression;
3608
9
      else
3609
9
        return NPCK_NotNull;
3610
3611
4
    case NPC_ValueDependentIsNotNull:
3612
4
      return NPCK_NotNull;
3613
2.73M
    }
3614
2.73M
  }
3615
3616
  // Strip off a cast to void*, if it exists. Except in C++.
3617
2.73M
  if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) {
3618
165k
    if (!Ctx.getLangOpts().CPlusPlus) {
3619
      // Check that it is a cast to void*.
3620
138k
      if (const PointerType *PT = CE->getType()->getAs<PointerType>()) {
3621
136k
        QualType Pointee = PT->getPointeeType();
3622
136k
        Qualifiers Qs = Pointee.getQualifiers();
3623
        // Only (void*)0 or equivalent are treated as nullptr. If pointee type
3624
        // has non-default address space it is not treated as nullptr.
3625
        // (__generic void*)0 in OpenCL 2.0 should not be treated as nullptr
3626
        // since it cannot be assigned to a pointer to constant address space.
3627
136k
        if ((Ctx.getLangOpts().OpenCLVersion >= 200 &&
3628
1.51k
             Pointee.getAddressSpace() == LangAS::opencl_generic) ||
3629
135k
            (Ctx.getLangOpts().OpenCL &&
3630
2.82k
             Ctx.getLangOpts().OpenCLVersion < 200 &&
3631
1.94k
             Pointee.getAddressSpace() == LangAS::opencl_private))
3632
1.00k
          Qs.removeAddressSpace();
3633
3634
136k
        if (Pointee->isVoidType() && 
Qs.empty()8.12k
&& // to void*
3635
6.66k
            CE->getSubExpr()->getType()->isIntegerType()) // from int
3636
5.70k
          return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
3637
2.56M
      }
3638
138k
    }
3639
2.56M
  } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
3640
    // Ignore the ImplicitCastExpr type entirely.
3641
138k
    return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
3642
2.43M
  } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
3643
    // Accept ((void*)0) as a null pointer constant, as many other
3644
    // implementations do.
3645
26.7k
    return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
3646
2.40M
  } else if (const GenericSelectionExpr *GE =
3647
1
               dyn_cast<GenericSelectionExpr>(this)) {
3648
1
    if (GE->isResultDependent())
3649
0
      return NPCK_NotNull;
3650
1
    return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC);
3651
2.40M
  } else if (const ChooseExpr *CE = dyn_cast<ChooseExpr>(this)) {
3652
1
    if (CE->isConditionDependent())
3653
0
      return NPCK_NotNull;
3654
1
    return CE->getChosenSubExpr()->isNullPointerConstant(Ctx, NPC);
3655
2.40M
  } else if (const CXXDefaultArgExpr *DefaultArg
3656
98
               = dyn_cast<CXXDefaultArgExpr>(this)) {
3657
    // See through default argument expressions.
3658
98
    return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC);
3659
2.40M
  } else if (const CXXDefaultInitExpr *DefaultInit
3660
0
               = dyn_cast<CXXDefaultInitExpr>(this)) {
3661
    // See through default initializer expressions.
3662
0
    return DefaultInit->getExpr()->isNullPointerConstant(Ctx, NPC);
3663
2.40M
  } else if (isa<GNUNullExpr>(this)) {
3664
    // The GNU __null extension is always a null pointer constant.
3665
8.46k
    return NPCK_GNUNull;
3666
2.39M
  } else if (const MaterializeTemporaryExpr *M
3667
7
                                   = dyn_cast<MaterializeTemporaryExpr>(this)) {
3668
7
    return M->getSubExpr()->isNullPointerConstant(Ctx, NPC);
3669
2.39M
  } else if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(this)) {
3670
1.55k
    if (const Expr *Source = OVE->getSourceExpr())
3671
1.06k
      return Source->isNullPointerConstant(Ctx, NPC);
3672
2.55M
  }
3673
3674
  // If the expression has no type information, it cannot be a null pointer
3675
  // constant.
3676
2.55M
  if (getType().isNull())
3677
10
    return NPCK_NotNull;
3678
3679
  // C++11 nullptr_t is always a null pointer constant.
3680
2.55M
  if (getType()->isNullPtrType())
3681
93.7k
    return NPCK_CXX11_nullptr;
3682
3683
2.45M
  if (const RecordType *UT = getType()->getAsUnionType())
3684
6
    if (!Ctx.getLangOpts().CPlusPlus11 &&
3685
6
        UT && UT->getDecl()->hasAttr<TransparentUnionAttr>())
3686
6
      if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){
3687
0
        const Expr *InitExpr = CLE->getInitializer();
3688
0
        if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr))
3689
0
          return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC);
3690
2.45M
      }
3691
  // This expression must be an integer type.
3692
2.45M
  if (!getType()->isIntegerType() ||
3693
583k
      (Ctx.getLangOpts().CPlusPlus && 
getType()->isEnumeralType()469k
))
3694
1.87M
    return NPCK_NotNull;
3695
3696
580k
  if (Ctx.getLangOpts().CPlusPlus11) {
3697
    // C++11 [conv.ptr]p1: A null pointer constant is an integer literal with
3698
    // value zero or a prvalue of type std::nullptr_t.
3699
    // Microsoft mode permits C++98 rules reflecting MSVC behavior.
3700
414k
    const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(this);
3701
414k
    if (Lit && 
!Lit->getValue()196k
)
3702
117k
      return NPCK_ZeroLiteral;
3703
296k
    else if (!Ctx.getLangOpts().MSVCCompat || 
!isCXX98IntegralConstantExpr(Ctx)590
)
3704
296k
      return NPCK_NotNull;
3705
166k
  } else {
3706
    // If we have an integer constant expression, we need to *evaluate* it and
3707
    // test for the value 0.
3708
166k
    if (!isIntegerConstantExpr(Ctx))
3709
82.0k
      return NPCK_NotNull;
3710
84.9k
  }
3711
3712
84.9k
  if (EvaluateKnownConstInt(Ctx) != 0)
3713
35.0k
    return NPCK_NotNull;
3714
3715
49.8k
  if (isa<IntegerLiteral>(this))
3716
48.2k
    return NPCK_ZeroLiteral;
3717
1.60k
  return NPCK_ZeroExpression;
3718
1.60k
}
3719
3720
/// If this expression is an l-value for an Objective C
3721
/// property, find the underlying property reference expression.
3722
0
const ObjCPropertyRefExpr *Expr::getObjCProperty() const {
3723
0
  const Expr *E = this;
3724
0
  while (true) {
3725
0
    assert((E->getValueKind() == VK_LValue &&
3726
0
            E->getObjectKind() == OK_ObjCProperty) &&
3727
0
           "expression is not a property reference");
3728
0
    E = E->IgnoreParenCasts();
3729
0
    if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
3730
0
      if (BO->getOpcode() == BO_Comma) {
3731
0
        E = BO->getRHS();
3732
0
        continue;
3733
0
      }
3734
0
    }
3735
3736
0
    break;
3737
0
  }
3738
3739
0
  return cast<ObjCPropertyRefExpr>(E);
3740
0
}
3741
3742
375
bool Expr::isObjCSelfExpr() const {
3743
375
  const Expr *E = IgnoreParenImpCasts();
3744
3745
375
  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E);
3746
375
  if (!DRE)
3747
143
    return false;
3748
3749
232
  const ImplicitParamDecl *Param = dyn_cast<ImplicitParamDecl>(DRE->getDecl());
3750
232
  if (!Param)
3751
113
    return false;
3752
3753
119
  const ObjCMethodDecl *M = dyn_cast<ObjCMethodDecl>(Param->getDeclContext());
3754
119
  if (!M)
3755
0
    return false;
3756
3757
119
  return M->getSelfDecl() == Param;
3758
119
}
3759
3760
14.2M
FieldDecl *Expr::getSourceBitField() {
3761
14.2M
  Expr *E = this->IgnoreParens();
3762
3763
17.0M
  while (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
3764
2.85M
    if (ICE->getCastKind() == CK_LValueToRValue ||
3765
34.7k
        (ICE->getValueKind() != VK_RValue && 
ICE->getCastKind() == CK_NoOp47
))
3766
2.81M
      E = ICE->getSubExpr()->IgnoreParens();
3767
34.7k
    else
3768
34.7k
      break;
3769
2.85M
  }
3770
3771
14.2M
  if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E))
3772
198k
    if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl()))
3773
198k
      if (Field->isBitField())
3774
5.25k
        return Field;
3775
3776
14.2M
  if (ObjCIvarRefExpr *IvarRef = dyn_cast<ObjCIvarRefExpr>(E)) {
3777
1.74k
    FieldDecl *Ivar = IvarRef->getDecl();
3778
1.74k
    if (Ivar->isBitField())
3779
214
      return Ivar;
3780
14.2M
  }
3781
3782
14.2M
  if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E)) {
3783
5.16M
    if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl()))
3784
15
      if (Field->isBitField())
3785
0
        return Field;
3786
3787
5.16M
    if (BindingDecl *BD = dyn_cast<BindingDecl>(DeclRef->getDecl()))
3788
247
      if (Expr *E = BD->getBinding())
3789
247
        return E->getSourceBitField();
3790
14.2M
  }
3791
3792
14.2M
  if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) {
3793
1.98M
    if (BinOp->isAssignmentOp() && 
BinOp->getLHS()967
)
3794
967
      return BinOp->getLHS()->getSourceBitField();
3795
3796
1.97M
    if (BinOp->getOpcode() == BO_Comma && 
BinOp->getRHS()130
)
3797
130
      return BinOp->getRHS()->getSourceBitField();
3798
14.2M
  }
3799
3800
14.2M
  if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(E))
3801
94.3k
    if (UnOp->isPrefix() && 
UnOp->isIncrementDecrementOp()2.95k
)
3802
2.95k
      return UnOp->getSubExpr()->getSourceBitField();
3803
3804
14.2M
  return nullptr;
3805
14.2M
}
3806
3807
313k
bool Expr::refersToVectorElement() const {
3808
  // FIXME: Why do we not just look at the ObjectKind here?
3809
313k
  const Expr *E = this->IgnoreParens();
3810
3811
318k
  while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
3812
12.1k
    if (ICE->getValueKind() != VK_RValue &&
3813
12.1k
        ICE->getCastKind() == CK_NoOp)
3814
5.08k
      E = ICE->getSubExpr()->IgnoreParens();
3815
7.08k
    else
3816
7.08k
      break;
3817
12.1k
  }
3818
3819
313k
  if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E))
3820
3.58k
    return ASE->getBase()->getType()->isVectorType();
3821
3822
310k
  if (isa<ExtVectorElementExpr>(E))
3823
9
    return true;
3824
3825
310k
  if (auto *DRE = dyn_cast<DeclRefExpr>(E))
3826
177k
    if (auto *BD = dyn_cast<BindingDecl>(DRE->getDecl()))
3827
1
      if (auto *E = BD->getBinding())
3828
1
        return E->refersToVectorElement();
3829
3830
310k
  return false;
3831
310k
}
3832
3833
909
bool Expr::refersToGlobalRegisterVar() const {
3834
909
  const Expr *E = this->IgnoreParenImpCasts();
3835
3836
909
  if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
3837
614
    if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
3838
614
      if (VD->getStorageClass() == SC_Register &&
3839
145
          VD->hasAttr<AsmLabelAttr>() && 
!VD->isLocalVarDecl()2
)
3840
2
        return true;
3841
3842
907
  return false;
3843
907
}
3844
3845
561k
bool Expr::isSameComparisonOperand(const Expr* E1, const Expr* E2) {
3846
561k
  E1 = E1->IgnoreParens();
3847
561k
  E2 = E2->IgnoreParens();
3848
3849
561k
  if (E1->getStmtClass() != E2->getStmtClass())
3850
286k
    return false;
3851
3852
274k
  switch (E1->getStmtClass()) {
3853
67.2k
    default:
3854
67.2k
      return false;
3855
9
    case CXXThisExprClass:
3856
9
      return true;
3857
4.16k
    case DeclRefExprClass: {
3858
      // DeclRefExpr without an ImplicitCastExpr can happen for integral
3859
      // template parameters.
3860
4.16k
      const auto *DRE1 = cast<DeclRefExpr>(E1);
3861
4.16k
      const auto *DRE2 = cast<DeclRefExpr>(E2);
3862
4.16k
      return DRE1->isRValue() && 
DRE2->isRValue()3.78k
&&
3863
3.78k
             DRE1->getDecl() == DRE2->getDecl();
3864
0
    }
3865
203k
    case ImplicitCastExprClass: {
3866
      // Peel off implicit casts.
3867
204k
      while (true) {
3868
204k
        const auto *ICE1 = dyn_cast<ImplicitCastExpr>(E1);
3869
204k
        const auto *ICE2 = dyn_cast<ImplicitCastExpr>(E2);
3870
204k
        if (!ICE1 || 
!ICE2203k
)
3871
1.32k
          return false;
3872
203k
        if (ICE1->getCastKind() != ICE2->getCastKind())
3873
930
          return false;
3874
202k
        E1 = ICE1->getSubExpr()->IgnoreParens();
3875
202k
        E2 = ICE2->getSubExpr()->IgnoreParens();
3876
        // The final cast must be one of these types.
3877
202k
        if (ICE1->getCastKind() == CK_LValueToRValue ||
3878
1.57k
            ICE1->getCastKind() == CK_ArrayToPointerDecay ||
3879
201k
            
ICE1->getCastKind() == CK_FunctionToPointerDecay1.36k
) {
3880
201k
          break;
3881
201k
        }
3882
202k
      }
3883
3884
201k
      const auto *DRE1 = dyn_cast<DeclRefExpr>(E1);
3885
201k
      const auto *DRE2 = dyn_cast<DeclRefExpr>(E2);
3886
201k
      if (DRE1 && 
DRE2192k
)
3887
188k
        return declaresSameEntity(DRE1->getDecl(), DRE2->getDecl());
3888
3889
12.8k
      const auto *Ivar1 = dyn_cast<ObjCIvarRefExpr>(E1);
3890
12.8k
      const auto *Ivar2 = dyn_cast<ObjCIvarRefExpr>(E2);
3891
12.8k
      if (Ivar1 && 
Ivar217
) {
3892
8
        return Ivar1->isFreeIvar() && 
Ivar2->isFreeIvar()7
&&
3893
7
               declaresSameEntity(Ivar1->getDecl(), Ivar2->getDecl());
3894
8
      }
3895
3896
12.8k
      const auto *Array1 = dyn_cast<ArraySubscriptExpr>(E1);
3897
12.8k
      const auto *Array2 = dyn_cast<ArraySubscriptExpr>(E2);
3898
12.8k
      if (Array1 && 
Array2307
) {
3899
295
        if (!isSameComparisonOperand(Array1->getBase(), Array2->getBase()))
3900
212
          return false;
3901
3902
83
        auto Idx1 = Array1->getIdx();
3903
83
        auto Idx2 = Array2->getIdx();
3904
83
        const auto Integer1 = dyn_cast<IntegerLiteral>(Idx1);
3905
83
        const auto Integer2 = dyn_cast<IntegerLiteral>(Idx2);
3906
83
        if (Integer1 && 
Integer275
) {
3907
75
          if (!llvm::APInt::isSameValue(Integer1->getValue(),
3908
75
                                        Integer2->getValue()))
3909
72
            return false;
3910
8
        } else {
3911
8
          if (!isSameComparisonOperand(Idx1, Idx2))
3912
3
            return false;
3913
8
        }
3914
3915
8
        return true;
3916
8
      }
3917
3918
      // Walk the MemberExpr chain.
3919
15.1k
      
while (12.5k
isa<MemberExpr>(E1) &&
isa<MemberExpr>(E2)6.04k
) {
3920
4.51k
        const auto *ME1 = cast<MemberExpr>(E1);
3921
4.51k
        const auto *ME2 = cast<MemberExpr>(E2);
3922
4.51k
        if (!declaresSameEntity(ME1->getMemberDecl(), ME2->getMemberDecl()))
3923
1.90k
          return false;
3924
2.61k
        if (const auto *D = dyn_cast<VarDecl>(ME1->getMemberDecl()))
3925
1
          if (D->isStaticDataMember())
3926
1
            return true;
3927
2.61k
        E1 = ME1->getBase()->IgnoreParenImpCasts();
3928
2.61k
        E2 = ME2->getBase()->IgnoreParenImpCasts();
3929
2.61k
      }
3930
3931
10.6k
      if (isa<CXXThisExpr>(E1) && 
isa<CXXThisExpr>(E2)139
)
3932
2
        return true;
3933
3934
      // A static member variable can end the MemberExpr chain with either
3935
      // a MemberExpr or a DeclRefExpr.
3936
21.3k
      
auto getAnyDecl = [](const Expr *E) -> const ValueDecl * 10.6k
{
3937
21.3k
        if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
3938
12.6k
          return DRE->getDecl();
3939
8.65k
        if (const auto *ME = dyn_cast<MemberExpr>(E))
3940
5.99k
          return ME->getMemberDecl();
3941
2.66k
        return nullptr;
3942
2.66k
      };
3943
3944
10.6k
      const ValueDecl *VD1 = getAnyDecl(E1);
3945
10.6k
      const ValueDecl *VD2 = getAnyDecl(E2);
3946
10.6k
      return declaresSameEntity(VD1, VD2);
3947
10.6k
    }
3948
274k
  }
3949
274k
}
3950
3951
/// isArrow - Return true if the base expression is a pointer to vector,
3952
/// return false if the base expression is a vector.
3953
365
bool ExtVectorElementExpr::isArrow() const {
3954
365
  return getBase()->getType()->isPointerType();
3955
365
}
3956
3957
292
unsigned ExtVectorElementExpr::getNumElements() const {
3958
292
  if (const VectorType *VT = getType()->getAs<VectorType>())
3959
65
    return VT->getNumElements();
3960
227
  return 1;
3961
227
}
3962
3963
/// containsDuplicateElements - Return true if any element access is repeated.
3964
89
bool ExtVectorElementExpr::containsDuplicateElements() const {
3965
  // FIXME: Refactor this code to an accessor on the AST node which returns the
3966
  // "type" of component access, and share with code below and in Sema.
3967
89
  StringRef Comp = Accessor->getName();
3968
3969
  // Halving swizzles do not contain duplicate elements.
3970
89
  if (Comp == "hi" || 
Comp == "lo"87
||
Comp == "even"73
||
Comp == "odd"62
)
3971
28
    return false;
3972
3973
  // Advance past s-char prefix on hex swizzles.
3974
61
  if (Comp[0] == 's' || Comp[0] == 'S')
3975
0
    Comp = Comp.substr(1);
3976
3977
136
  for (unsigned i = 0, e = Comp.size(); i != e; 
++i75
)
3978
83
    if (Comp.substr(i + 1).find(Comp[i]) != StringRef::npos)
3979
8
        return true;
3980
3981
53
  return false;
3982
61
}
3983
3984
/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
3985
void ExtVectorElementExpr::getEncodedElementAccess(
3986
292
    SmallVectorImpl<uint32_t> &Elts) const {
3987
292
  StringRef Comp = Accessor->getName();
3988
292
  bool isNumericAccessor = false;
3989
292
  if (Comp[0] == 's' || 
Comp[0] == 'S'285
) {
3990
7
    Comp = Comp.substr(1);
3991
7
    isNumericAccessor = true;
3992
7
  }
3993
3994
292
  bool isHi =   Comp == "hi";
3995
292
  bool isLo =   Comp == "lo";
3996
292
  bool isEven = Comp == "even";
3997
292
  bool isOdd  = Comp == "odd";
3998
3999
703
  for (unsigned i = 0, e = getNumElements(); i != e; 
++i411
) {
4000
411
    uint64_t Index;
4001
4002
411
    if (isHi)
4003
14
      Index = e + i;
4004
397
    else if (isLo)
4005
46
      Index = i;
4006
351
    else if (isEven)
4007
5
      Index = 2 * i;
4008
346
    else if (isOdd)
4009
2
      Index = 2 * i + 1;
4010
344
    else
4011
344
      Index = ExtVectorType::getAccessorIdx(Comp[i], isNumericAccessor);
4012
4013
411
    Elts.push_back(Index);
4014
411
  }
4015
292
}
4016
4017
ShuffleVectorExpr::ShuffleVectorExpr(const ASTContext &C, ArrayRef<Expr *> args,
4018
                                     QualType Type, SourceLocation BLoc,
4019
                                     SourceLocation RP)
4020
    : Expr(ShuffleVectorExprClass, Type, VK_RValue, OK_Ordinary),
4021
143k
      BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) {
4022
143k
  SubExprs = new (C) Stmt*[args.size()];
4023
1.41M
  for (unsigned i = 0; i != args.size(); 
i++1.27M
)
4024
1.27M
    SubExprs[i] = args[i];
4025
4026
143k
  setDependence(computeDependence(this));
4027
143k
}
4028
4029
2
void ShuffleVectorExpr::setExprs(const ASTContext &C, ArrayRef<Expr *> Exprs) {
4030
2
  if (SubExprs) 
C.Deallocate(SubExprs)0
;
4031
4032
2
  this->NumExprs = Exprs.size();
4033
2
  SubExprs = new (C) Stmt*[NumExprs];
4034
2
  memcpy(SubExprs, Exprs.data(), sizeof(Expr *) * Exprs.size());
4035
2
}
4036
4037
GenericSelectionExpr::GenericSelectionExpr(
4038
    const ASTContext &, SourceLocation GenericLoc, Expr *ControllingExpr,
4039
    ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs,
4040
    SourceLocation DefaultLoc, SourceLocation RParenLoc,
4041
    bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
4042
    : Expr(GenericSelectionExprClass, AssocExprs[ResultIndex]->getType(),
4043
           AssocExprs[ResultIndex]->getValueKind(),
4044
           AssocExprs[ResultIndex]->getObjectKind()),
4045
      NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex),
4046
437
      DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4047
437
  assert(AssocTypes.size() == AssocExprs.size() &&
4048
437
         "Must have the same number of association expressions"
4049
437
         " and TypeSourceInfo!");
4050
437
  assert(ResultIndex < NumAssocs && "ResultIndex is out-of-bounds!");
4051
4052
437
  GenericSelectionExprBits.GenericLoc = GenericLoc;
4053
437
  getTrailingObjects<Stmt *>()[ControllingIndex] = ControllingExpr;
4054
437
  std::copy(AssocExprs.begin(), AssocExprs.end(),
4055
437
            getTrailingObjects<Stmt *>() + AssocExprStartIndex);
4056
437
  std::copy(AssocTypes.begin(), AssocTypes.end(),
4057
437
            getTrailingObjects<TypeSourceInfo *>());
4058
4059
437
  setDependence(computeDependence(this, ContainsUnexpandedParameterPack));
4060
437
}
4061
4062
GenericSelectionExpr::GenericSelectionExpr(
4063
    const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr,
4064
    ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs,
4065
    SourceLocation DefaultLoc, SourceLocation RParenLoc,
4066
    bool ContainsUnexpandedParameterPack)
4067
    : Expr(GenericSelectionExprClass, Context.DependentTy, VK_RValue,
4068
           OK_Ordinary),
4069
      NumAssocs(AssocExprs.size()), ResultIndex(ResultDependentIndex),
4070
10
      DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4071
10
  assert(AssocTypes.size() == AssocExprs.size() &&
4072
10
         "Must have the same number of association expressions"
4073
10
         " and TypeSourceInfo!");
4074
4075
10
  GenericSelectionExprBits.GenericLoc = GenericLoc;
4076
10
  getTrailingObjects<Stmt *>()[ControllingIndex] = ControllingExpr;
4077
10
  std::copy(AssocExprs.begin(), AssocExprs.end(),
4078
10
            getTrailingObjects<Stmt *>() + AssocExprStartIndex);
4079
10
  std::copy(AssocTypes.begin(), AssocTypes.end(),
4080
10
            getTrailingObjects<TypeSourceInfo *>());
4081
4082
10
  setDependence(computeDependence(this, ContainsUnexpandedParameterPack));
4083
10
}
4084
4085
GenericSelectionExpr::GenericSelectionExpr(EmptyShell Empty, unsigned NumAssocs)
4086
9
    : Expr(GenericSelectionExprClass, Empty), NumAssocs(NumAssocs) {}
4087
4088
GenericSelectionExpr *GenericSelectionExpr::Create(
4089
    const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr,
4090
    ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs,
4091
    SourceLocation DefaultLoc, SourceLocation RParenLoc,
4092
437
    bool ContainsUnexpandedParameterPack, unsigned ResultIndex) {
4093
437
  unsigned NumAssocs = AssocExprs.size();
4094
437
  void *Mem = Context.Allocate(
4095
437
      totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4096
437
      alignof(GenericSelectionExpr));
4097
437
  return new (Mem) GenericSelectionExpr(
4098
437
      Context, GenericLoc, ControllingExpr, AssocTypes, AssocExprs, DefaultLoc,
4099
437
      RParenLoc, ContainsUnexpandedParameterPack, ResultIndex);
4100
437
}
4101
4102
GenericSelectionExpr *GenericSelectionExpr::Create(
4103
    const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr,
4104
    ArrayRef<TypeSourceInfo *> AssocTypes, ArrayRef<Expr *> AssocExprs,
4105
    SourceLocation DefaultLoc, SourceLocation RParenLoc,
4106
10
    bool ContainsUnexpandedParameterPack) {
4107
10
  unsigned NumAssocs = AssocExprs.size();
4108
10
  void *Mem = Context.Allocate(
4109
10
      totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4110
10
      alignof(GenericSelectionExpr));
4111
10
  return new (Mem) GenericSelectionExpr(
4112
10
      Context, GenericLoc, ControllingExpr, AssocTypes, AssocExprs, DefaultLoc,
4113
10
      RParenLoc, ContainsUnexpandedParameterPack);
4114
10
}
4115
4116
GenericSelectionExpr *
4117
GenericSelectionExpr::CreateEmpty(const ASTContext &Context,
4118
9
                                  unsigned NumAssocs) {
4119
9
  void *Mem = Context.Allocate(
4120
9
      totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4121
9
      alignof(GenericSelectionExpr));
4122
9
  return new (Mem) GenericSelectionExpr(EmptyShell(), NumAssocs);
4123
9
}
4124
4125
//===----------------------------------------------------------------------===//
4126
//  DesignatedInitExpr
4127
//===----------------------------------------------------------------------===//
4128
4129
4.11k
IdentifierInfo *DesignatedInitExpr::Designator::getFieldName() const {
4130
4.11k
  assert(Kind == FieldDesignator && "Only valid on a field designator");
4131
4.11k
  if (Field.NameOrField & 0x01)
4132
3.92k
    return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01);
4133
193
  else
4134
193
    return getField()->getIdentifier();
4135
4.11k
}
4136
4137
DesignatedInitExpr::DesignatedInitExpr(const ASTContext &C, QualType Ty,
4138
                                       llvm::ArrayRef<Designator> Designators,
4139
                                       SourceLocation EqualOrColonLoc,
4140
                                       bool GNUSyntax,
4141
                                       ArrayRef<Expr *> IndexExprs, Expr *Init)
4142
    : Expr(DesignatedInitExprClass, Ty, Init->getValueKind(),
4143
           Init->getObjectKind()),
4144
      EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax),
4145
1.93k
      NumDesignators(Designators.size()), NumSubExprs(IndexExprs.size() + 1) {
4146
1.93k
  this->Designators = new (C) Designator[NumDesignators];
4147
4148
  // Record the initializer itself.
4149
1.93k
  child_iterator Child = child_begin();
4150
1.93k
  *Child++ = Init;
4151
4152
  // Copy the designators and their subexpressions, computing
4153
  // value-dependence along the way.
4154
1.93k
  unsigned IndexIdx = 0;
4155
4.21k
  for (unsigned I = 0; I != NumDesignators; 
++I2.27k
) {
4156
2.27k
    this->Designators[I] = Designators[I];
4157
2.27k
    if (this->Designators[I].isArrayDesignator()) {
4158
      // Copy the index expressions into permanent storage.
4159
371
      *Child++ = IndexExprs[IndexIdx++];
4160
1.90k
    } else if (this->Designators[I].isArrayRangeDesignator()) {
4161
      // Copy the start/end expressions into permanent storage.
4162
27
      *Child++ = IndexExprs[IndexIdx++];
4163
27
      *Child++ = IndexExprs[IndexIdx++];
4164
27
    }
4165
2.27k
  }
4166
4167
1.93k
  assert(IndexIdx == IndexExprs.size() && "Wrong number of index expressions");
4168
1.93k
  setDependence(computeDependence(this));
4169
1.93k
}
4170
4171
DesignatedInitExpr *
4172
DesignatedInitExpr::Create(const ASTContext &C,
4173
                           llvm::ArrayRef<Designator> Designators,
4174
                           ArrayRef<Expr*> IndexExprs,
4175
                           SourceLocation ColonOrEqualLoc,
4176
1.93k
                           bool UsesColonSyntax, Expr *Init) {
4177
1.93k
  void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(IndexExprs.size() + 1),
4178
1.93k
                         alignof(DesignatedInitExpr));
4179
1.93k
  return new (Mem) DesignatedInitExpr(C, C.VoidTy, Designators,
4180
1.93k
                                      ColonOrEqualLoc, UsesColonSyntax,
4181
1.93k
                                      IndexExprs, Init);
4182
1.93k
}
4183
4184
DesignatedInitExpr *DesignatedInitExpr::CreateEmpty(const ASTContext &C,
4185
38
                                                    unsigned NumIndexExprs) {
4186
38
  void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(NumIndexExprs + 1),
4187
38
                         alignof(DesignatedInitExpr));
4188
38
  return new (Mem) DesignatedInitExpr(NumIndexExprs + 1);
4189
38
}
4190
4191
void DesignatedInitExpr::setDesignators(const ASTContext &C,
4192
                                        const Designator *Desigs,
4193
38
                                        unsigned NumDesigs) {
4194
38
  Designators = new (C) Designator[NumDesigs];
4195
38
  NumDesignators = NumDesigs;
4196
85
  for (unsigned I = 0; I != NumDesigs; 
++I47
)
4197
47
    Designators[I] = Desigs[I];
4198
38
}
4199
4200
68
SourceRange DesignatedInitExpr::getDesignatorsSourceRange() const {
4201
68
  DesignatedInitExpr *DIE = const_cast<DesignatedInitExpr*>(this);
4202
68
  if (size() == 1)
4203
0
    return DIE->getDesignator(0)->getSourceRange();
4204
68
  return SourceRange(DIE->getDesignator(0)->getBeginLoc(),
4205
68
                     DIE->getDesignator(size() - 1)->getEndLoc());
4206
68
}
4207
4208
5.11k
SourceLocation DesignatedInitExpr::getBeginLoc() const {
4209
5.11k
  SourceLocation StartLoc;
4210
5.11k
  auto *DIE = const_cast<DesignatedInitExpr *>(this);
4211
5.11k
  Designator &First = *DIE->getDesignator(0);
4212
5.11k
  if (First.isFieldDesignator())
4213
4.74k
    StartLoc = GNUSyntax ? 
First.Field.FieldLoc24
:
First.Field.DotLoc4.71k
;
4214
373
  else
4215
373
    StartLoc = First.ArrayOrRange.LBracketLoc;
4216
5.11k
  return StartLoc;
4217
5.11k
}
4218
4219
963
SourceLocation DesignatedInitExpr::getEndLoc() const {
4220
963
  return getInit()->getEndLoc();
4221
963
}
4222
4223
1.10k
Expr *DesignatedInitExpr::getArrayIndex(const Designator& D) const {
4224
1.10k
  assert(D.Kind == Designator::ArrayDesignator && "Requires array designator");
4225
1.10k
  return getSubExpr(D.ArrayOrRange.Index + 1);
4226
1.10k
}
4227
4228
90
Expr *DesignatedInitExpr::getArrayRangeStart(const Designator &D) const {
4229
90
  assert(D.Kind == Designator::ArrayRangeDesignator &&
4230
90
         "Requires array range designator");
4231
90
  return getSubExpr(D.ArrayOrRange.Index + 1);
4232
90
}
4233
4234
132
Expr *DesignatedInitExpr::getArrayRangeEnd(const Designator &D) const {
4235
132
  assert(D.Kind == Designator::ArrayRangeDesignator &&
4236
132
         "Requires array range designator");
4237
132
  return getSubExpr(D.ArrayOrRange.Index + 2);
4238
132
}
4239
4240
/// Replaces the designator at index @p Idx with the series
4241
/// of designators in [First, Last).
4242
void DesignatedInitExpr::ExpandDesignator(const ASTContext &C, unsigned Idx,
4243
                                          const Designator *First,
4244
34
                                          const Designator *Last) {
4245
34
  unsigned NumNewDesignators = Last - First;
4246
34
  if (NumNewDesignators == 0) {
4247
0
    std::copy_backward(Designators + Idx + 1,
4248
0
                       Designators + NumDesignators,
4249
0
                       Designators + Idx);
4250
0
    --NumNewDesignators;
4251
0
    return;
4252
34
  } else if (NumNewDesignators == 1) {
4253
0
    Designators[Idx] = *First;
4254
0
    return;
4255
0
  }
4256
4257
34
  Designator *NewDesignators
4258
34
    = new (C) Designator[NumDesignators - 1 + NumNewDesignators];
4259
34
  std::copy(Designators, Designators + Idx, NewDesignators);
4260
34
  std::copy(First, Last, NewDesignators + Idx);
4261
34
  std::copy(Designators + Idx + 1, Designators + NumDesignators,
4262
34
            NewDesignators + Idx + NumNewDesignators);
4263
34
  Designators = NewDesignators;
4264
34
  NumDesignators = NumDesignators - 1 + NumNewDesignators;
4265
34
}
4266
4267
DesignatedInitUpdateExpr::DesignatedInitUpdateExpr(const ASTContext &C,
4268
                                                   SourceLocation lBraceLoc,
4269
                                                   Expr *baseExpr,
4270
                                                   SourceLocation rBraceLoc)
4271
    : Expr(DesignatedInitUpdateExprClass, baseExpr->getType(), VK_RValue,
4272
53
           OK_Ordinary) {
4273
53
  BaseAndUpdaterExprs[0] = baseExpr;
4274
4275
53
  InitListExpr *ILE = new (C) InitListExpr(C, lBraceLoc, None, rBraceLoc);
4276
53
  ILE->setType(baseExpr->getType());
4277
53
  BaseAndUpdaterExprs[1] = ILE;
4278
4279
  // FIXME: this is wrong, set it correctly.
4280
53
  setDependence(ExprDependence::None);
4281
53
}
4282
4283
111
SourceLocation DesignatedInitUpdateExpr::getBeginLoc() const {
4284
111
  return getBase()->getBeginLoc();
4285
111
}
4286
4287
24
SourceLocation DesignatedInitUpdateExpr::getEndLoc() const {
4288
24
  return getBase()->getEndLoc();
4289
24
}
4290
4291
ParenListExpr::ParenListExpr(SourceLocation LParenLoc, ArrayRef<Expr *> Exprs,
4292
                             SourceLocation RParenLoc)
4293
    : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary),
4294
718k
      LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
4295
718k
  ParenListExprBits.NumExprs = Exprs.size();
4296
4297
1.68M
  for (unsigned I = 0, N = Exprs.size(); I != N; 
++I971k
)
4298
971k
    getTrailingObjects<Stmt *>()[I] = Exprs[I];
4299
718k
  setDependence(computeDependence(this));
4300
718k
}
4301
4302
ParenListExpr::ParenListExpr(EmptyShell Empty, unsigned NumExprs)
4303
39.5k
    : Expr(ParenListExprClass, Empty) {
4304
39.5k
  ParenListExprBits.NumExprs = NumExprs;
4305
39.5k
}
4306
4307
ParenListExpr *ParenListExpr::Create(const ASTContext &Ctx,
4308
                                     SourceLocation LParenLoc,
4309
                                     ArrayRef<Expr *> Exprs,
4310
718k
                                     SourceLocation RParenLoc) {
4311
718k
  void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(Exprs.size()),
4312
718k
                           alignof(ParenListExpr));
4313
718k
  return new (Mem) ParenListExpr(LParenLoc, Exprs, RParenLoc);
4314
718k
}
4315
4316
ParenListExpr *ParenListExpr::CreateEmpty(const ASTContext &Ctx,
4317
39.5k
                                          unsigned NumExprs) {
4318
39.5k
  void *Mem =
4319
39.5k
      Ctx.Allocate(totalSizeToAlloc<Stmt *>(NumExprs), alignof(ParenListExpr));
4320
39.5k
  return new (Mem) ParenListExpr(EmptyShell(), NumExprs);
4321
39.5k
}
4322
4323
BinaryOperator::BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs,
4324
                               Opcode opc, QualType ResTy, ExprValueKind VK,
4325
                               ExprObjectKind OK, SourceLocation opLoc,
4326
                               FPOptionsOverride FPFeatures)
4327
7.15M
    : Expr(BinaryOperatorClass, ResTy, VK, OK) {
4328
7.15M
  BinaryOperatorBits.Opc = opc;
4329
7.15M
  assert(!isCompoundAssignmentOp() &&
4330
7.15M
         "Use CompoundAssignOperator for compound assignments");
4331
7.15M
  BinaryOperatorBits.OpLoc = opLoc;
4332
7.15M
  SubExprs[LHS] = lhs;
4333
7.15M
  SubExprs[RHS] = rhs;
4334
7.15M
  BinaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
4335
7.15M
  if (hasStoredFPFeatures())
4336
7.04k
    setStoredFPFeatures(FPFeatures);
4337
7.15M
  setDependence(computeDependence(this));
4338
7.15M
}
4339
4340
BinaryOperator::BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs,
4341
                               Opcode opc, QualType ResTy, ExprValueKind VK,
4342
                               ExprObjectKind OK, SourceLocation opLoc,
4343
                               FPOptionsOverride FPFeatures, bool dead2)
4344
165k
    : Expr(CompoundAssignOperatorClass, ResTy, VK, OK) {
4345
165k
  BinaryOperatorBits.Opc = opc;
4346
165k
  assert(isCompoundAssignmentOp() &&
4347
165k
         "Use CompoundAssignOperator for compound assignments");
4348
165k
  BinaryOperatorBits.OpLoc = opLoc;
4349
165k
  SubExprs[LHS] = lhs;
4350
165k
  SubExprs[RHS] = rhs;
4351
165k
  BinaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
4352
165k
  if (hasStoredFPFeatures())
4353
153
    setStoredFPFeatures(FPFeatures);
4354
165k
  setDependence(computeDependence(this));
4355
165k
}
4356
4357
BinaryOperator *BinaryOperator::CreateEmpty(const ASTContext &C,
4358
484k
                                            bool HasFPFeatures) {
4359
484k
  unsigned Extra = sizeOfTrailingObjects(HasFPFeatures);
4360
484k
  void *Mem =
4361
484k
      C.Allocate(sizeof(BinaryOperator) + Extra, alignof(BinaryOperator));
4362
484k
  return new (Mem) BinaryOperator(EmptyShell());
4363
484k
}
4364
4365
BinaryOperator *BinaryOperator::Create(const ASTContext &C, Expr *lhs,
4366
                                       Expr *rhs, Opcode opc, QualType ResTy,
4367
                                       ExprValueKind VK, ExprObjectKind OK,
4368
                                       SourceLocation opLoc,
4369
7.15M
                                       FPOptionsOverride FPFeatures) {
4370
7.15M
  bool HasFPFeatures = FPFeatures.requiresTrailingStorage();
4371
7.15M
  unsigned Extra = sizeOfTrailingObjects(HasFPFeatures);
4372
7.15M
  void *Mem =
4373
7.15M
      C.Allocate(sizeof(BinaryOperator) + Extra, alignof(BinaryOperator));
4374
7.15M
  return new (Mem)
4375
7.15M
      BinaryOperator(C, lhs, rhs, opc, ResTy, VK, OK, opLoc, FPFeatures);
4376
7.15M
}
4377
4378
CompoundAssignOperator *
4379
30.1k
CompoundAssignOperator::CreateEmpty(const ASTContext &C, bool HasFPFeatures) {
4380
30.1k
  unsigned Extra = sizeOfTrailingObjects(HasFPFeatures);
4381
30.1k
  void *Mem = C.Allocate(sizeof(CompoundAssignOperator) + Extra,
4382
30.1k
                         alignof(CompoundAssignOperator));
4383
30.1k
  return new (Mem) CompoundAssignOperator(C, EmptyShell(), HasFPFeatures);
4384
30.1k
}
4385
4386
CompoundAssignOperator *
4387
CompoundAssignOperator::Create(const ASTContext &C, Expr *lhs, Expr *rhs,
4388
                               Opcode opc, QualType ResTy, ExprValueKind VK,
4389
                               ExprObjectKind OK, SourceLocation opLoc,
4390
                               FPOptionsOverride FPFeatures,
4391
165k
                               QualType CompLHSType, QualType CompResultType) {
4392
165k
  bool HasFPFeatures = FPFeatures.requiresTrailingStorage();
4393
165k
  unsigned Extra = sizeOfTrailingObjects(HasFPFeatures);
4394
165k
  void *Mem = C.Allocate(sizeof(CompoundAssignOperator) + Extra,
4395
165k
                         alignof(CompoundAssignOperator));
4396
165k
  return new (Mem)
4397
165k
      CompoundAssignOperator(C, lhs, rhs, opc, ResTy, VK, OK, opLoc, FPFeatures,
4398
165k
                             CompLHSType, CompResultType);
4399
165k
}
4400
4401
UnaryOperator *UnaryOperator::CreateEmpty(const ASTContext &C,
4402
224k
                                          bool hasFPFeatures) {
4403
224k
  void *Mem = C.Allocate(totalSizeToAlloc<FPOptionsOverride>(hasFPFeatures),
4404
224k
                         alignof(UnaryOperator));
4405
224k
  return new (Mem) UnaryOperator(hasFPFeatures, EmptyShell());
4406
224k
}
4407
4408
UnaryOperator::UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc,
4409
                             QualType type, ExprValueKind VK, ExprObjectKind OK,
4410
                             SourceLocation l, bool CanOverflow,
4411
                             FPOptionsOverride FPFeatures)
4412
2.97M
    : Expr(UnaryOperatorClass, type, VK, OK), Val(input) {
4413
2.97M
  UnaryOperatorBits.Opc = opc;
4414
2.97M
  UnaryOperatorBits.CanOverflow = CanOverflow;
4415
2.97M
  UnaryOperatorBits.Loc = l;
4416
2.97M
  UnaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
4417
2.97M
  if (hasStoredFPFeatures())
4418
448
    setStoredFPFeatures(FPFeatures);
4419
2.97M
  setDependence(computeDependence(this, Ctx));
4420
2.97M
}
4421
4422
UnaryOperator *UnaryOperator::Create(const ASTContext &C, Expr *input,
4423
                                     Opcode opc, QualType type,
4424
                                     ExprValueKind VK, ExprObjectKind OK,
4425
                                     SourceLocation l, bool CanOverflow,
4426
2.97M
                                     FPOptionsOverride FPFeatures) {
4427
2.97M
  bool HasFPFeatures = FPFeatures.requiresTrailingStorage();
4428
2.97M
  unsigned Size = totalSizeToAlloc<FPOptionsOverride>(HasFPFeatures);
4429
2.97M
  void *Mem = C.Allocate(Size, alignof(UnaryOperator));
4430
2.97M
  return new (Mem)
4431
2.97M
      UnaryOperator(C, input, opc, type, VK, OK, l, CanOverflow, FPFeatures);
4432
2.97M
}
4433
4434
6
const OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) {
4435
6
  if (const ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(e))
4436
2
    e = ewc->getSubExpr();
4437
6
  if (const MaterializeTemporaryExpr *m = dyn_cast<MaterializeTemporaryExpr>(e))
4438
0
    e = m->getSubExpr();
4439
6
  e = cast<CXXConstructExpr>(e)->getArg(0);
4440
12
  while (const ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(e))
4441
6
    e = ice->getSubExpr();
4442
6
  return cast<OpaqueValueExpr>(e);
4443
6
}
4444
4445
PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &Context,
4446
                                           EmptyShell sh,
4447
248
                                           unsigned numSemanticExprs) {
4448
248
  void *buffer =
4449
248
      Context.Allocate(totalSizeToAlloc<Expr *>(1 + numSemanticExprs),
4450
248
                       alignof(PseudoObjectExpr));
4451
248
  return new(buffer) PseudoObjectExpr(sh, numSemanticExprs);
4452
248
}
4453
4454
PseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs)
4455
248
  : Expr(PseudoObjectExprClass, shell) {
4456
248
  PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1;
4457
248
}
4458
4459
PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &C, Expr *syntax,
4460
                                           ArrayRef<Expr*> semantics,
4461
6.28k
                                           unsigned resultIndex) {
4462
6.28k
  assert(syntax && "no syntactic expression!");
4463
6.28k
  assert(semantics.size() && "no semantic expressions!");
4464
4465
6.28k
  QualType type;
4466
6.28k
  ExprValueKind VK;
4467
6.28k
  if (resultIndex == NoResult) {
4468
48
    type = C.VoidTy;
4469
48
    VK = VK_RValue;
4470
6.23k
  } else {
4471
6.23k
    assert(resultIndex < semantics.size());
4472
6.23k
    type = semantics[resultIndex]->getType();
4473
6.23k
    VK = semantics[resultIndex]->getValueKind();
4474
6.23k
    assert(semantics[resultIndex]->getObjectKind() == OK_Ordinary);
4475
6.23k
  }
4476
4477
6.28k
  void *buffer = C.Allocate(totalSizeToAlloc<Expr *>(semantics.size() + 1),
4478
6.28k
                            alignof(PseudoObjectExpr));
4479
6.28k
  return new(buffer) PseudoObjectExpr(type, VK, syntax, semantics,
4480
6.28k
                                      resultIndex);
4481
6.28k
}
4482
4483
PseudoObjectExpr::PseudoObjectExpr(QualType type, ExprValueKind VK,
4484
                                   Expr *syntax, ArrayRef<Expr *> semantics,
4485
                                   unsigned resultIndex)
4486
6.28k
    : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary) {
4487
6.28k
  PseudoObjectExprBits.NumSubExprs = semantics.size() + 1;
4488
6.28k
  PseudoObjectExprBits.ResultIndex = resultIndex + 1;
4489
4490
23.2k
  for (unsigned i = 0, e = semantics.size() + 1; i != e; 
++i16.9k
) {
4491
10.7k
    Expr *E = (i == 0 ? 
syntax6.28k
: semantics[i-1]);
4492
16.9k
    getSubExprsBuffer()[i] = E;
4493
4494
16.9k
    if (isa<OpaqueValueExpr>(E))
4495
16.9k
      assert(cast<OpaqueValueExpr>(E)->getSourceExpr() != nullptr &&
4496
16.9k
             "opaque-value semantic expressions for pseudo-object "
4497
16.9k
             "operations must have sources");
4498
16.9k
  }
4499
4500
6.28k
  setDependence(computeDependence(this));
4501
6.28k
}
4502
4503
//===----------------------------------------------------------------------===//
4504
//  Child Iterators for iterating over subexpressions/substatements
4505
//===----------------------------------------------------------------------===//
4506
4507
// UnaryExprOrTypeTraitExpr
4508
85.6k
Stmt::child_range UnaryExprOrTypeTraitExpr::children() {
4509
85.6k
  const_child_range CCR =
4510
85.6k
      const_cast<const UnaryExprOrTypeTraitExpr *>(this)->children();
4511
85.6k
  return child_range(cast_away_const(CCR.begin()), cast_away_const(CCR.end()));
4512
85.6k
}
4513
4514
85.6k
Stmt::const_child_range UnaryExprOrTypeTraitExpr::children() const {
4515
  // If this is of a type and the type is a VLA type (and not a typedef), the
4516
  // size expression of the VLA needs to be treated as an executable expression.
4517
  // Why isn't this weirdness documented better in StmtIterator?
4518
85.6k
  if (isArgumentType()) {
4519
80.2k
    if (const VariableArrayType *T =
4520
28
            dyn_cast<VariableArrayType>(getArgumentType().getTypePtr()))
4521
28
      return const_child_range(const_child_iterator(T), const_child_iterator());
4522
80.1k
    return const_child_range(const_child_iterator(), const_child_iterator());
4523
80.1k
  }
4524
5.38k
  return const_child_range(&Argument.Ex, &Argument.Ex + 1);
4525
5.38k
}
4526
4527
AtomicExpr::AtomicExpr(SourceLocation BLoc, ArrayRef<Expr *> args, QualType t,
4528
                       AtomicOp op, SourceLocation RP)
4529
    : Expr(AtomicExprClass, t, VK_RValue, OK_Ordinary),
4530
5.43k
      NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) {
4531
5.43k
  assert(args.size() == getNumSubExprs(op) && "wrong number of subexpressions");
4532
20.9k
  for (unsigned i = 0; i != args.size(); 
i++15.5k
)
4533
15.5k
    SubExprs[i] = args[i];
4534
5.43k
  setDependence(computeDependence(this));
4535
5.43k
}
4536
4537
5.81k
unsigned AtomicExpr::getNumSubExprs(AtomicOp Op) {
4538
5.81k
  switch (Op) {
4539
33
  case AO__c11_atomic_init:
4540
42
  case AO__opencl_atomic_init:
4541
996
  case AO__c11_atomic_load:
4542
1.57k
  case AO__atomic_load_n:
4543
1.57k
    return 2;
4544
4545
72
  case AO__opencl_atomic_load:
4546
1.02k
  case AO__c11_atomic_store:
4547
1.87k
  case AO__c11_atomic_exchange:
4548
1.99k
  case AO__atomic_load:
4549
2.10k
  case AO__atomic_store:
4550
2.13k
  case AO__atomic_store_n:
4551
2.14k
  case AO__atomic_exchange_n:
4552
2.32k
  case AO__c11_atomic_fetch_add:
4553
2.42k
  case AO__c11_atomic_fetch_sub:
4554
2.44k
  case AO__c11_atomic_fetch_and:
4555
2.45k
  case AO__c11_atomic_fetch_or:
4556
2.47k
  case AO__c11_atomic_fetch_xor:
4557
2.49k
  case AO__c11_atomic_fetch_max:
4558
2.51k
  case AO__c11_atomic_fetch_min:
4559
2.54k
  case AO__atomic_fetch_add:
4560
2.57k
  case AO__atomic_fetch_sub:
4561
2.58k
  case AO__atomic_fetch_and:
4562
2.60k
  case AO__atomic_fetch_or:
4563
2.61k
  case AO__atomic_fetch_xor:
4564
2.63k
  case AO__atomic_fetch_nand:
4565
3.73k
  case AO__atomic_add_fetch:
4566
3.74k
  case AO__atomic_sub_fetch:
4567
3.74k
  case A