Coverage Report

Created: 2022-01-18 06:27

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