Coverage Report

Created: 2021-08-24 07:12

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