Coverage Report

Created: 2022-07-16 07:03

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