Coverage Report

Created: 2020-10-24 06:27

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