Coverage Report

Created: 2023-11-11 10:31

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