Coverage Report

Created: 2022-05-17 06:19

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