35#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/Format.h"
37#include "llvm/Support/raw_ostream.h"
49 if (
auto *BO = dyn_cast<BinaryOperator>(
E)) {
50 if (BO->getOpcode() == BO_Comma) {
57 if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(
E)) {
58 E = MTE->getSubExpr();
79 return cast<CXXRecordDecl>(
D);
89 if (
const auto *CE = dyn_cast<CastExpr>(
E)) {
90 if ((CE->getCastKind() == CK_DerivedToBase ||
91 CE->getCastKind() == CK_UncheckedDerivedToBase) &&
100 if (CE->getCastKind() == CK_NoOp) {
101 E = CE->getSubExpr();
104 }
else if (
const auto *ME = dyn_cast<MemberExpr>(
E)) {
105 if (!ME->isArrow()) {
106 assert(ME->getBase()->getType()->getAsRecordDecl());
107 if (
const auto *Field = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
108 if (!Field->isBitField() && !Field->getType()->isReferenceType()) {
115 }
else if (
const auto *BO = dyn_cast<BinaryOperator>(
E)) {
116 if (BO->getOpcode() == BO_PtrMemD) {
117 assert(BO->getRHS()->isPRValue());
123 if (BO->getOpcode() == BO_Comma) {
124 CommaLHSs.push_back(BO->getLHS());
145 switch (UO->getOpcode()) {
147 return UO->getSubExpr()->isKnownToHaveBooleanValue(Semantic);
159 return CE->getSubExpr()->isKnownToHaveBooleanValue(Semantic);
162 switch (BO->getOpcode()) {
163 default:
return false;
178 return BO->getLHS()->isKnownToHaveBooleanValue(Semantic) &&
179 BO->getRHS()->isKnownToHaveBooleanValue(Semantic);
183 return BO->getRHS()->isKnownToHaveBooleanValue(Semantic);
188 return CO->getTrueExpr()->isKnownToHaveBooleanValue(Semantic) &&
189 CO->getFalseExpr()->isKnownToHaveBooleanValue(Semantic);
191 if (isa<ObjCBoolLiteralExpr>(
E))
194 if (
const auto *OVE = dyn_cast<OpaqueValueExpr>(
E))
195 return OVE->getSourceExpr()->isKnownToHaveBooleanValue(Semantic);
198 if (!Semantic && FD->getType()->isUnsignedIntegerType() &&
199 !FD->getBitWidth()->isValueDependent() &&
200 FD->getBitWidthValue(FD->getASTContext()) == 1)
209 bool IgnoreTemplateOrMacroSubstitution)
const {
211 const Decl *
D =
nullptr;
213 if (
const auto *ME = dyn_cast<MemberExpr>(
E))
214 D = ME->getMemberDecl();
215 else if (
const auto *DRE = dyn_cast<DeclRefExpr>(
E))
217 else if (
const auto *IRE = dyn_cast<ObjCIvarRefExpr>(
E))
221 StrictFlexArraysLevel,
222 IgnoreTemplateOrMacroSubstitution);
232 if (
Value.isMemberPointer())
233 return Value.getMemberPointerDecl();
235 if (
Value.isLValue() &&
Value.getLValueOffset().isZero())
249 template <
class E,
class T>
252 return static_cast<const E*
>(
expr)->getExprLoc();
262 return static_cast<const E *
>(
expr)->getBeginLoc();
270 const auto *ED = cast<EnumDecl>(ECD->getDeclContext());
271 if (ED->isCompleteDefinition())
280#define ABSTRACT_STMT(type)
281#define STMT(type, base) \
282 case Stmt::type##Class: break;
283#define EXPR(type, base) \
284 case Stmt::type##Class: return getExprLocImpl<type>(this, &type::getExprLoc);
285#include "clang/AST/StmtNodes.inc"
287 llvm_unreachable(
"unknown expression kind");
298 "Invalid StorageKind Value");
308 if (!
Value.getInt().needsCleanup())
324 bool IsImmediateInvocation)
325 :
FullExpr(ConstantExprClass, SubExpr) {
334 ::new (getTrailingObjects<APValue>())
APValue();
339 bool IsImmediateInvocation) {
340 assert(!isa<ConstantExpr>(
E));
343 unsigned Size = totalSizeToAlloc<APValue, uint64_t>(
347 return new (Mem)
ConstantExpr(
E, StorageKind, IsImmediateInvocation);
358ConstantExpr::ConstantExpr(EmptyShell
Empty,
364 ::new (getTrailingObjects<APValue>())
APValue();
371 unsigned Size = totalSizeToAlloc<APValue, uint64_t>(
380 "Invalid storage for this value kind");
386 Int64Result() = *
Value.getInt().getRawData();
395 APValueResult() = std::move(
Value);
398 llvm_unreachable(
"Invalid ResultKind Bits");
404 return APValueResult().
getInt();
409 llvm_unreachable(
"invalid Accessor");
417 return APValueResult();
427 llvm_unreachable(
"invalid ResultKind");
431 bool RefersToEnclosingVariableOrCapture,
QualType T,
441 RefersToEnclosingVariableOrCapture;
442 DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter =
false;
449DeclRefExpr::DeclRefExpr(
const ASTContext &Ctx,
452 bool RefersToEnclosingVariableOrCapture,
461 new (getTrailingObjects<NestedNameSpecifierLoc>())
465 *getTrailingObjects<NamedDecl *>() = FoundD;
467 = (TemplateArgs || TemplateKWLoc.
isValid()) ? 1 : 0;
469 RefersToEnclosingVariableOrCapture;
470 DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter =
false;
473 auto Deps = TemplateArgumentDependence::None;
474 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
475 TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
477 assert(!(Deps & TemplateArgumentDependence::Dependent) &&
478 "built a DeclRefExpr with dependent template args");
479 }
else if (TemplateKWLoc.
isValid()) {
480 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
491 bool RefersToEnclosingVariableOrCapture,
496 return Create(Context, QualifierLoc, TemplateKWLoc,
D,
497 RefersToEnclosingVariableOrCapture,
499 T, VK, FoundD, TemplateArgs, NOUR);
505 bool RefersToEnclosingVariableOrCapture,
515 bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.
isValid();
519 QualifierLoc ? 1 : 0, FoundD ? 1 : 0,
520 HasTemplateKWAndArgsInfo ? 1 : 0,
521 TemplateArgs ? TemplateArgs->
size() : 0);
524 return new (Mem)
DeclRefExpr(Context, QualifierLoc, TemplateKWLoc,
D,
525 RefersToEnclosingVariableOrCapture, NameInfo,
526 FoundD, TemplateArgs,
T, VK, NOUR);
532 bool HasTemplateKWAndArgsInfo,
533 unsigned NumTemplateArgs) {
534 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
538 HasQualifier ? 1 : 0, HasFoundDecl ? 1 : 0, HasTemplateKWAndArgsInfo,
546 if (
getType()->isUndeducedType())
562SYCLUniqueStableNameExpr::SYCLUniqueStableNameExpr(
SourceLocation OpLoc,
568 OpLoc(OpLoc), LParen(LParen), RParen(RParen) {
569 setTypeSourceInfo(TSI);
573SYCLUniqueStableNameExpr::SYCLUniqueStableNameExpr(EmptyShell
Empty,
600 const NamedDecl *ND) -> std::optional<unsigned> {
601 if (
const auto *RD = dyn_cast<CXXRecordDecl>(ND))
602 return RD->getDeviceLambdaManglingNumber();
611 llvm::raw_string_ostream Out(Buffer);
612 Ctx->mangleCanonicalTypeName(Ty, Out);
622 assert((getIdentKind() == IK) &&
623 "IdentKind do not fit in PredefinedExprBitfields!");
624 bool HasFunctionName = SL !=
nullptr;
633PredefinedExpr::PredefinedExpr(EmptyShell
Empty,
bool HasFunctionName)
641 bool HasFunctionName = SL !=
nullptr;
642 void *Mem = Ctx.
Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName),
648 bool HasFunctionName) {
649 void *Mem = Ctx.
Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName),
659 return "__FUNCTION__";
661 return "__FUNCDNAME__";
663 return "L__FUNCTION__";
665 return "__PRETTY_FUNCTION__";
667 return "__FUNCSIG__";
669 return "L__FUNCSIG__";
673 llvm_unreachable(
"Unknown ident kind for PredefinedExpr");
679 const Decl *CurrentDecl,
680 bool ForceElaboratedPrinting) {
684 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(CurrentDecl)) {
685 std::unique_ptr<MangleContext> MC;
688 if (MC->shouldMangleDeclName(ND)) {
690 llvm::raw_svector_ostream Out(Buffer);
696 else if (ND->hasAttr<CUDAGlobalAttr>())
700 MC->mangleName(GD, Out);
702 if (!Buffer.empty() && Buffer.front() ==
'\01')
703 return std::string(Buffer.substr(1));
704 return std::string(Buffer);
706 return std::string(ND->getIdentifier()->getName());
710 if (isa<BlockDecl>(CurrentDecl)) {
715 if (DC->isFileContext())
719 llvm::raw_svector_ostream Out(Buffer);
720 if (
auto *DCBlock = dyn_cast<BlockDecl>(DC))
723 else if (
auto *DCDecl = dyn_cast<Decl>(DC))
725 return std::string(Out.str());
727 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurrentDecl)) {
729 bool IsFuncOrFunctionInNonMSVCCompatEnv =
731 IK == PredefinedIdentKind ::Function) &&
733 bool IsLFunctionInMSVCCommpatEnv =
735 bool IsFuncOrFunctionOrLFunctionOrFuncDName =
740 if ((ForceElaboratedPrinting &&
741 (IsFuncOrFunctionInNonMSVCCompatEnv || IsLFunctionInMSVCCommpatEnv)) ||
742 (!ForceElaboratedPrinting && IsFuncOrFunctionOrLFunctionOrFuncDName))
743 return FD->getNameAsString();
746 llvm::raw_svector_ostream Out(Name);
758 std::string remapPath(StringRef
Path)
const override {
761 return std::string(p);
773 llvm::raw_string_ostream POut(Proto);
780 if (FD->hasWrittenPrototype())
781 FT = dyn_cast<FunctionProtoType>(AFT);
786 case CC_C: POut <<
"__cdecl ";
break;
797 FD->printQualifiedName(POut, Policy);
802 return std::string(Name);
807 for (
unsigned i = 0, e =
Decl->getNumParams(); i != e; ++i) {
809 POut <<
Decl->getParamDecl(i)->getType().stream(Policy);
812 if (FT->isVariadic()) {
813 if (FD->getNumParams()) POut <<
", ";
818 !
Decl->getNumParams()) {
825 assert(FT &&
"We must have a written prototype in this case.");
828 if (FT->isVolatile())
840 while (isa_and_nonnull<NamedDecl>(Ctx)) {
842 = dyn_cast<ClassTemplateSpecializationDecl>(Ctx);
844 Specs.push_back(Spec);
848 std::string TemplateParams;
849 llvm::raw_string_ostream TOut(TemplateParams);
852 D->getSpecializedTemplate()->getTemplateParameters();
854 assert(Params->
size() == Args.
size());
855 for (
unsigned i = 0, numParams = Params->
size(); i != numParams; ++i) {
857 if (Param.empty())
continue;
858 TOut << Param <<
" = ";
867 = FD->getTemplateSpecializationInfo();
872 assert(Params->
size() == Args->
size());
873 for (
unsigned i = 0, e = Params->
size(); i != e; ++i) {
875 if (Param.empty())
continue;
876 TOut << Param <<
" = ";
877 Args->
get(i).
print(Policy, TOut,
true);
883 if (!TemplateParams.empty()) {
885 TemplateParams.resize(TemplateParams.size() - 2);
886 POut <<
" [" << TemplateParams <<
"]";
895 if (isa<CXXMethodDecl>(FD) &&
896 cast<CXXMethodDecl>(FD)->getParent()->isLambda())
897 Proto =
"auto " + Proto;
898 else if (FT && FT->getReturnType()->getAs<
DecltypeType>())
903 else if (!isa<CXXConstructorDecl>(FD) && !isa<CXXDestructorDecl>(FD))
908 return std::string(Name);
910 if (
const CapturedDecl *CD = dyn_cast<CapturedDecl>(CurrentDecl)) {
914 if (DC->isFunctionOrMethod() && (DC->getDeclKind() != Decl::Captured)) {
918 llvm_unreachable(
"CapturedDecl not inside a function or method");
920 if (
const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(CurrentDecl)) {
922 llvm::raw_svector_ostream Out(Name);
923 Out << (MD->isInstanceMethod() ?
'-' :
'+');
932 dyn_cast<ObjCCategoryImplDecl>(MD->getDeclContext()))
933 Out <<
'(' << *CID <<
')';
936 MD->getSelector().print(Out);
939 return std::string(Name);
941 if (isa<TranslationUnitDecl>(CurrentDecl) &&
950 const llvm::APInt &Val) {
954 BitWidth = Val.getBitWidth();
955 unsigned NumWords = Val.getNumWords();
956 const uint64_t* Words = Val.getRawData();
958 pVal =
new (
C) uint64_t[NumWords];
959 std::copy(Words, Words + NumWords,
pVal);
960 }
else if (NumWords == 1)
966IntegerLiteral::IntegerLiteral(
const ASTContext &
C,
const llvm::APInt &
V,
969 assert(
type->isIntegerType() &&
"Illegal type in IntegerLiteral");
970 assert(
V.getBitWidth() ==
C.getIntWidth(
type) &&
971 "Integer type is not the correct size for constant.");
987FixedPointLiteral::FixedPointLiteral(
const ASTContext &
C,
const llvm::APInt &
V,
992 assert(
type->isFixedPointType() &&
"Illegal type in FixedPointLiteral");
993 assert(
V.getBitWidth() ==
C.getTypeInfo(
type).Width &&
994 "Fixed point type is not the correct size for constant.");
1000 const llvm::APInt &
V,
1018 S, llvm::APSInt::getUnsigned(
getValue().getZExtValue()), Scale);
1019 return std::string(S);
1041 StringRef Escaped = escapeCStyle<EscapeChar::Single>(Val);
1042 if (!Escaped.empty()) {
1043 OS <<
"'" << Escaped <<
"'";
1052 OS <<
"'" << (char)Val <<
"'";
1054 OS <<
"'\\x" << llvm::format(
"%02x", Val) <<
"'";
1055 else if (Val <= 0xFFFF)
1056 OS <<
"'\\u" << llvm::format(
"%04x", Val) <<
"'";
1058 OS <<
"'\\U" << llvm::format(
"%08x", Val) <<
"'";
1062FloatingLiteral::FloatingLiteral(
const ASTContext &
C,
const llvm::APFloat &
V,
1065 setSemantics(
V.getSemantics());
1073 setRawSemantics(llvm::APFloatBase::S_IEEEhalf);
1094 V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
1096 return V.convertToDouble();
1101 unsigned CharByteWidth = 0;
1105 CharByteWidth =
Target.getCharWidth();
1108 CharByteWidth =
Target.getWCharWidth();
1111 CharByteWidth =
Target.getChar16Width();
1114 CharByteWidth =
Target.getChar32Width();
1117 return sizeof(char);
1119 assert((CharByteWidth & 7) == 0 &&
"Assumes character size is byte multiple");
1121 assert((CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) &&
1122 "The only supported character byte widths are 1,2 and 4!");
1123 return CharByteWidth;
1126StringLiteral::StringLiteral(
const ASTContext &Ctx, StringRef Str,
1129 unsigned NumConcatenated)
1132 unsigned Length = Str.size();
1139 "StringLiteral must be of constant array type!");
1140 unsigned CharByteWidth = mapCharByteWidth(Ctx.
getTargetInfo(), Kind);
1141 unsigned ByteLength = Str.size();
1142 assert((ByteLength % CharByteWidth == 0) &&
1143 "The size of the data must be a multiple of CharByteWidth!");
1148 switch (CharByteWidth) {
1150 Length = ByteLength;
1153 Length = ByteLength / 2;
1156 Length = ByteLength / 4;
1159 llvm_unreachable(
"Unsupported character width!");
1165 assert(!Pascal &&
"Can't make an unevaluated Pascal string");
1170 *getTrailingObjects<unsigned>() = Length;
1174 std::memcpy(getTrailingObjects<SourceLocation>(), Loc,
1178 std::memcpy(getTrailingObjects<char>(), Str.data(), Str.size());
1183StringLiteral::StringLiteral(EmptyShell
Empty,
unsigned NumConcatenated,
1184 unsigned Length,
unsigned CharByteWidth)
1188 *getTrailingObjects<unsigned>() = Length;
1194 unsigned NumConcatenated) {
1195 void *Mem = Ctx.
Allocate(totalSizeToAlloc<unsigned, SourceLocation, char>(
1196 1, NumConcatenated, Str.size()),
1203 unsigned NumConcatenated,
1205 unsigned CharByteWidth) {
1206 void *Mem = Ctx.
Allocate(totalSizeToAlloc<unsigned, SourceLocation, char>(
1207 1, NumConcatenated, Length * CharByteWidth),
1232 static const char Hex[] =
"0123456789ABCDEF";
1235 for (
unsigned I = 0, N =
getLength(); I != N; ++I) {
1237 StringRef Escaped = escapeCStyle<EscapeChar::Double>(Char);
1238 if (Escaped.empty()) {
1244 Char >= 0xd800 && Char <= 0xdbff) {
1246 if (Trail >= 0xdc00 && Trail <= 0xdfff) {
1247 Char = 0x10000 + ((Char - 0xd800) << 10) + (Trail - 0xdc00);
1257 (Char >= 0xd800 && Char <= 0xdfff) || Char >= 0x110000) {
1261 while ((Char >> Shift) == 0)
1263 for (; Shift >= 0; Shift -= 4)
1264 OS << Hex[(Char >> Shift) & 15];
1271 << Hex[(Char >> 20) & 15]
1272 << Hex[(Char >> 16) & 15];
1275 OS << Hex[(Char >> 12) & 15]
1276 << Hex[(Char >> 8) & 15]
1277 << Hex[(Char >> 4) & 15]
1278 << Hex[(Char >> 0) & 15];
1284 if (LastSlashX + 1 == I) {
1286 case '0':
case '1':
case '2':
case '3':
case '4':
1287 case '5':
case '6':
case '7':
case '8':
case '9':
1288 case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
1289 case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
1294 assert(Char <= 0xff &&
1295 "Characters above 0xff should already have been handled.");
1301 << (char)(
'0' + ((Char >> 6) & 7))
1302 << (char)(
'0' + ((Char >> 3) & 7))
1303 << (char)(
'0' + ((Char >> 0) & 7));
1332 unsigned *StartTokenByteOffset)
const {
1336 "Only narrow string literals are currently supported");
1341 unsigned StringOffset = 0;
1343 TokNo = *StartToken;
1344 if (StartTokenByteOffset) {
1345 StringOffset = *StartTokenByteOffset;
1346 ByteNo -= StringOffset;
1358 std::pair<FileID, unsigned> LocInfo =
1359 SM.getDecomposedLoc(StrTokSpellingLoc);
1361 StringRef Buffer =
SM.getBufferData(LocInfo.first, &
Invalid);
1363 if (StartTokenByteOffset !=
nullptr)
1364 *StartTokenByteOffset = StringOffset;
1365 if (StartToken !=
nullptr)
1366 *StartToken = TokNo;
1367 return StrTokSpellingLoc;
1370 const char *StrData = Buffer.data()+LocInfo.second;
1373 Lexer TheLexer(
SM.getLocForStartOfFile(LocInfo.first), Features,
1374 Buffer.begin(), StrData, Buffer.end());
1383 if (ByteNo < TokNumBytes ||
1389 if (StartTokenByteOffset !=
nullptr)
1390 *StartTokenByteOffset = StringOffset;
1391 if (StartToken !=
nullptr)
1392 *StartToken = TokNo;
1397 StringOffset += TokNumBytes;
1399 ByteNo -= TokNumBytes;
1407#define UNARY_OPERATION(Name, Spelling) case UO_##Name: return Spelling;
1408#include "clang/AST/OperationKinds.def"
1410 llvm_unreachable(
"Unknown unary operator");
1416 default: llvm_unreachable(
"No unary operator for overloaded function");
1417 case OO_PlusPlus:
return Postfix ? UO_PostInc : UO_PreInc;
1418 case OO_MinusMinus:
return Postfix ? UO_PostDec : UO_PreDec;
1419 case OO_Amp:
return UO_AddrOf;
1420 case OO_Star:
return UO_Deref;
1421 case OO_Plus:
return UO_Plus;
1422 case OO_Minus:
return UO_Minus;
1423 case OO_Tilde:
return UO_Not;
1424 case OO_Exclaim:
return UO_LNot;
1425 case OO_Coawait:
return UO_Coawait;
1431 case UO_PostInc:
case UO_PreInc:
return OO_PlusPlus;
1432 case UO_PostDec:
case UO_PreDec:
return OO_MinusMinus;
1433 case UO_AddrOf:
return OO_Amp;
1434 case UO_Deref:
return OO_Star;
1435 case UO_Plus:
return OO_Plus;
1436 case UO_Minus:
return OO_Minus;
1437 case UO_Not:
return OO_Tilde;
1438 case UO_LNot:
return OO_Exclaim;
1439 case UO_Coawait:
return OO_Coawait;
1454 NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
1455 unsigned NumPreArgs = PreArgs.size();
1457 assert((NumPreArgs ==
getNumPreArgs()) &&
"NumPreArgs overflow!");
1459 unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC);
1460 CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects;
1461 assert((
CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) &&
1462 "OffsetToTrailingObjects overflow!");
1467 for (
unsigned I = 0; I != NumPreArgs; ++I)
1469 for (
unsigned I = 0; I != Args.size(); ++I)
1471 for (
unsigned I = Args.size(); I != NumArgs; ++I)
1485 assert((NumPreArgs ==
getNumPreArgs()) &&
"NumPreArgs overflow!");
1487 unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC);
1488 CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects;
1489 assert((
CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) &&
1490 "OffsetToTrailingObjects overflow!");
1499 unsigned NumArgs = std::max<unsigned>(Args.size(), MinNumArgs);
1504 return new (Mem)
CallExpr(CallExprClass, Fn, {}, Args, Ty, VK,
1505 RParenLoc, FPFeatures, MinNumArgs,
UsesADL);
1512 "Misaligned memory in CallExpr::CreateTemporary!");
1513 return new (Mem)
CallExpr(CallExprClass, Fn, {}, {}, Ty,
1520 unsigned SizeOfTrailingObjects =
1528unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) {
1532 case CXXOperatorCallExprClass:
1534 case CXXMemberCallExprClass:
1536 case UserDefinedLiteralClass:
1538 case CUDAKernelCallExprClass:
1541 llvm_unreachable(
"unexpected class deriving from CallExpr!");
1548 while (
auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE))
1553 if (
auto *BO = dyn_cast<BinaryOperator>(CEE)) {
1554 if (BO->isPtrMemOp()) {
1558 }
else if (
auto *UO = dyn_cast<UnaryOperator>(CEE)) {
1559 if (UO->getOpcode() == UO_Deref || UO->getOpcode() == UO_AddrOf ||
1560 UO->getOpcode() == UO_Plus) {
1568 if (
auto *DRE = dyn_cast<DeclRefExpr>(CEE))
1569 return DRE->getDecl();
1570 if (
auto *ME = dyn_cast<MemberExpr>(CEE))
1571 return ME->getMemberDecl();
1572 if (
auto *BE = dyn_cast<BlockExpr>(CEE))
1573 return BE->getBlockDecl();
1581 return FDecl ? FDecl->getBuiltinID() : 0;
1592 QualType CalleeType = Callee->getType();
1598 if (isa<CXXPseudoDestructorExpr>(Callee->IgnoreParens()))
1601 if (isa<UnresolvedMemberExpr>(Callee->IgnoreParens()))
1606 assert(!CalleeType.
isNull());
1624 if (
const auto *A = TD->getAttr<WarnUnusedResultAttr>())
1628 TD = TD->desugar()->getAs<TypedefType>())
1629 if (
const auto *A = TD->getDecl()->getAttr<WarnUnusedResultAttr>())
1635 return D ?
D->
getAttr<WarnUnusedResultAttr>() :
nullptr;
1639 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(
this))
1640 return OCE->getBeginLoc();
1648 if (
const auto *OCE = dyn_cast<CXXOperatorCallExpr>(
this))
1649 return OCE->getEndLoc();
1663 void *Mem =
C.Allocate(
1664 totalSizeToAlloc<OffsetOfNode, Expr *>(comps.size(), exprs.size()));
1671 unsigned numComps,
unsigned numExprs) {
1673 C.Allocate(totalSizeToAlloc<OffsetOfNode, Expr *>(numComps, numExprs));
1682 OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi),
1683 NumComps(comps.size()), NumExprs(exprs.size()) {
1684 for (
unsigned i = 0; i != comps.size(); ++i)
1686 for (
unsigned i = 0; i != exprs.size(); ++i)
1704 OpLoc(op), RParenLoc(rp) {
1705 assert(ExprKind <=
UETT_Last &&
"invalid enum value!");
1708 "UnaryExprOrTypeTraitExprBits.Kind overflow!");
1722 :
Expr(MemberExprClass,
T, VK, OK),
Base(
Base), MemberDecl(MemberDecl),
1723 MemberDNLoc(NameInfo.
getInfo()), MemberLoc(NameInfo.getLoc()) {
1729 FoundDecl.getDecl() != MemberDecl ||
1732 TemplateArgs || TemplateKWLoc.
isValid();
1738 new (getTrailingObjects<NestedNameSpecifierLoc>())
1741 *getTrailingObjects<DeclAccessPair>() = FoundDecl;
1743 auto Deps = TemplateArgumentDependence::None;
1744 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1745 TemplateKWLoc, *TemplateArgs, getTrailingObjects<TemplateArgumentLoc>(),
1747 }
else if (TemplateKWLoc.
isValid()) {
1748 getTrailingObjects<ASTTemplateKWAndArgsInfo>()->initializeFrom(
1761 bool HasFoundDecl = FoundDecl.getDecl() != MemberDecl ||
1763 bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.
isValid();
1767 HasQualifier, HasFoundDecl, HasTemplateKWAndArgsInfo,
1768 TemplateArgs ? TemplateArgs->
size() : 0);
1770 void *Mem =
C.Allocate(Size,
alignof(
MemberExpr));
1771 return new (Mem)
MemberExpr(
Base, IsArrow, OperatorLoc, QualifierLoc,
1772 TemplateKWLoc, MemberDecl, FoundDecl, NameInfo,
1773 TemplateArgs,
T, VK, OK, NOUR);
1777 bool HasQualifier,
bool HasFoundDecl,
1778 bool HasTemplateKWAndArgsInfo,
1779 unsigned NumTemplateArgs) {
1780 assert((!NumTemplateArgs || HasTemplateKWAndArgsInfo) &&
1781 "template args but no template arg info?");
1785 HasQualifier, HasFoundDecl, HasTemplateKWAndArgsInfo,
1793 if (
getType()->isUndeducedType())
1809 return BaseStartLoc;
1821bool CastExpr::CastConsistency()
const {
1823 case CK_DerivedToBase:
1824 case CK_UncheckedDerivedToBase:
1825 case CK_DerivedToBaseMemberPointer:
1826 case CK_BaseToDerived:
1827 case CK_BaseToDerivedMemberPointer:
1828 assert(!
path_empty() &&
"Cast kind should have a base path!");
1831 case CK_CPointerToObjCPointerCast:
1832 assert(
getType()->isObjCObjectPointerType());
1834 goto CheckNoBasePath;
1836 case CK_BlockPointerToObjCPointerCast:
1837 assert(
getType()->isObjCObjectPointerType());
1839 goto CheckNoBasePath;
1841 case CK_ReinterpretMemberPointer:
1842 assert(
getType()->isMemberPointerType());
1844 goto CheckNoBasePath;
1850 if (!
getType()->isPointerType()) {
1851 assert(
getType()->isObjCObjectPointerType() ==
1853 assert(
getType()->isBlockPointerType() ==
1856 goto CheckNoBasePath;
1858 case CK_AnyPointerToBlockPointerCast:
1859 assert(
getType()->isBlockPointerType());
1862 goto CheckNoBasePath;
1864 case CK_CopyAndAutoreleaseBlockObject:
1865 assert(
getType()->isBlockPointerType());
1867 goto CheckNoBasePath;
1869 case CK_FunctionToPointerDecay:
1870 assert(
getType()->isPointerType());
1872 goto CheckNoBasePath;
1874 case CK_AddressSpaceConversion: {
1883 (!Ty.
isNull() && !SETy.isNull() &&
1885 goto CheckNoBasePath;
1890 case CK_ArrayToPointerDecay:
1891 case CK_NullToMemberPointer:
1892 case CK_NullToPointer:
1893 case CK_ConstructorConversion:
1894 case CK_IntegralToPointer:
1895 case CK_PointerToIntegral:
1897 case CK_VectorSplat:
1898 case CK_IntegralCast:
1899 case CK_BooleanToSignedIntegral:
1900 case CK_IntegralToFloating:
1901 case CK_FloatingToIntegral:
1902 case CK_FloatingCast:
1903 case CK_ObjCObjectLValueCast:
1904 case CK_FloatingRealToComplex:
1905 case CK_FloatingComplexToReal:
1906 case CK_FloatingComplexCast:
1907 case CK_FloatingComplexToIntegralComplex:
1908 case CK_IntegralRealToComplex:
1909 case CK_IntegralComplexToReal:
1910 case CK_IntegralComplexCast:
1911 case CK_IntegralComplexToFloatingComplex:
1912 case CK_ARCProduceObject:
1913 case CK_ARCConsumeObject:
1914 case CK_ARCReclaimReturnedObject:
1915 case CK_ARCExtendBlockObject:
1916 case CK_ZeroToOCLOpaqueType:
1917 case CK_IntToOCLSampler:
1918 case CK_FloatingToFixedPoint:
1919 case CK_FixedPointToFloating:
1920 case CK_FixedPointCast:
1921 case CK_FixedPointToIntegral:
1922 case CK_IntegralToFixedPoint:
1924 case CK_HLSLVectorTruncation:
1926 goto CheckNoBasePath;
1929 case CK_LValueToRValue:
1931 case CK_AtomicToNonAtomic:
1932 case CK_NonAtomicToAtomic:
1933 case CK_PointerToBoolean:
1934 case CK_IntegralToBoolean:
1935 case CK_FloatingToBoolean:
1936 case CK_MemberPointerToBoolean:
1937 case CK_FloatingComplexToBoolean:
1938 case CK_IntegralComplexToBoolean:
1939 case CK_LValueBitCast:
1940 case CK_LValueToRValueBitCast:
1941 case CK_UserDefinedConversion:
1942 case CK_BuiltinFnToFnPtr:
1943 case CK_FixedPointToBoolean:
1944 case CK_HLSLArrayRValue:
1946 assert(
path_empty() &&
"Cast kind should not have a base path!");
1954#define CAST_OPERATION(Name) case CK_##Name: return #Name;
1955#include "clang/AST/OperationKinds.def"
1957 llvm_unreachable(
"Unhandled cast kind!");
1963static Expr *ignoreImplicitSemaNodes(
Expr *
E) {
1964 if (
auto *Materialize = dyn_cast<MaterializeTemporaryExpr>(
E))
1965 return Materialize->getSubExpr();
1967 if (
auto *Binder = dyn_cast<CXXBindTemporaryExpr>(
E))
1968 return Binder->getSubExpr();
1970 if (
auto *Full = dyn_cast<FullExpr>(
E))
1971 return Full->getSubExpr();
1973 if (
auto *CPLIE = dyn_cast<CXXParenListInitExpr>(
E);
1974 CPLIE && CPLIE->getInitExprs().size() == 1)
1975 return CPLIE->getInitExprs()[0];
1982 const Expr *SubExpr =
nullptr;
1984 for (
const CastExpr *
E =
this;
E;
E = dyn_cast<ImplicitCastExpr>(SubExpr)) {
1989 if (
E->getCastKind() == CK_ConstructorConversion) {
1991 ignoreImplicitSemaNodes);
1992 }
else if (
E->getCastKind() == CK_UserDefinedConversion) {
1993 assert((isa<CXXMemberCallExpr>(SubExpr) || isa<BlockExpr>(SubExpr)) &&
1994 "Unexpected SubExpr for CK_UserDefinedConversion.");
1995 if (
auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr))
1996 SubExpr = MCE->getImplicitObjectArgument();
2000 return const_cast<Expr *
>(SubExpr);
2004 const Expr *SubExpr =
nullptr;
2006 for (
const CastExpr *
E =
this;
E;
E = dyn_cast<ImplicitCastExpr>(SubExpr)) {
2009 if (
E->getCastKind() == CK_ConstructorConversion)
2010 return cast<CXXConstructExpr>(SubExpr)->getConstructor();
2012 if (
E->getCastKind() == CK_UserDefinedConversion) {
2013 if (
auto *MCE = dyn_cast<CXXMemberCallExpr>(SubExpr))
2014 return MCE->getMethodDecl();
2023#define ABSTRACT_STMT(x)
2024#define CASTEXPR(Type, Base) \
2025 case Stmt::Type##Class: \
2026 return static_cast<Type *>(this)->getTrailingObjects<CXXBaseSpecifier *>();
2027#define STMT(Type, Base)
2028#include "clang/AST/StmtNodes.inc"
2030 llvm_unreachable(
"non-cast expressions not possible here");
2045 Field != FieldEnd; ++Field) {
2047 !Field->isUnnamedBitField()) {
2057 case ImplicitCastExprClass:
2059 ->getTrailingObjects<FPOptionsOverride>();
2060 case CStyleCastExprClass:
2062 ->getTrailingObjects<FPOptionsOverride>();
2063 case CXXFunctionalCastExprClass:
2065 ->getTrailingObjects<FPOptionsOverride>();
2066 case CXXStaticCastExprClass:
2068 ->getTrailingObjects<FPOptionsOverride>();
2070 llvm_unreachable(
"Cast does not have FPFeatures");
2079 unsigned PathSize = (BasePath ? BasePath->size() : 0);
2081 C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
2085 assert((Kind != CK_LValueToRValue ||
2087 "invalid type for lvalue-to-rvalue conversion");
2091 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
2098 bool HasFPFeatures) {
2100 C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
2101 PathSize, HasFPFeatures));
2111 unsigned PathSize = (BasePath ? BasePath->size() : 0);
2113 C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
2116 new (Buffer)
CStyleCastExpr(
T, VK, K, Op, PathSize, FPO, WrittenTy, L, R);
2118 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
2125 bool HasFPFeatures) {
2127 C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
2128 PathSize, HasFPFeatures));
2136#define BINARY_OPERATION(Name, Spelling) case BO_##Name: return Spelling;
2137#include "clang/AST/OperationKinds.def"
2139 llvm_unreachable(
"Invalid OpCode!");
2145 default: llvm_unreachable(
"Not an overloadable binary operator");
2146 case OO_Plus:
return BO_Add;
2147 case OO_Minus:
return BO_Sub;
2148 case OO_Star:
return BO_Mul;
2149 case OO_Slash:
return BO_Div;
2150 case OO_Percent:
return BO_Rem;
2151 case OO_Caret:
return BO_Xor;
2152 case OO_Amp:
return BO_And;
2153 case OO_Pipe:
return BO_Or;
2154 case OO_Equal:
return BO_Assign;
2155 case OO_Spaceship:
return BO_Cmp;
2156 case OO_Less:
return BO_LT;
2157 case OO_Greater:
return BO_GT;
2158 case OO_PlusEqual:
return BO_AddAssign;
2159 case OO_MinusEqual:
return BO_SubAssign;
2160 case OO_StarEqual:
return BO_MulAssign;
2161 case OO_SlashEqual:
return BO_DivAssign;
2162 case OO_PercentEqual:
return BO_RemAssign;
2163 case OO_CaretEqual:
return BO_XorAssign;
2164 case OO_AmpEqual:
return BO_AndAssign;
2165 case OO_PipeEqual:
return BO_OrAssign;
2166 case OO_LessLess:
return BO_Shl;
2167 case OO_GreaterGreater:
return BO_Shr;
2168 case OO_LessLessEqual:
return BO_ShlAssign;
2169 case OO_GreaterGreaterEqual:
return BO_ShrAssign;
2170 case OO_EqualEqual:
return BO_EQ;
2171 case OO_ExclaimEqual:
return BO_NE;
2172 case OO_LessEqual:
return BO_LE;
2173 case OO_GreaterEqual:
return BO_GE;
2174 case OO_AmpAmp:
return BO_LAnd;
2175 case OO_PipePipe:
return BO_LOr;
2176 case OO_Comma:
return BO_Comma;
2177 case OO_ArrowStar:
return BO_PtrMemI;
2184 OO_Star, OO_Slash, OO_Percent,
2186 OO_LessLess, OO_GreaterGreater,
2188 OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual,
2189 OO_EqualEqual, OO_ExclaimEqual,
2195 OO_Equal, OO_StarEqual,
2196 OO_SlashEqual, OO_PercentEqual,
2197 OO_PlusEqual, OO_MinusEqual,
2198 OO_LessLessEqual, OO_GreaterGreaterEqual,
2199 OO_AmpEqual, OO_CaretEqual,
2203 return OverOps[Opc];
2245 BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext) {
2249 ? ExprDependence::Value
2250 : ExprDependence::None);
2256 return "__builtin_FILE";
2258 return "__builtin_FILE_NAME";
2260 return "__builtin_FUNCTION";
2262 return "__builtin_FUNCSIG";
2264 return "__builtin_LINE";
2266 return "__builtin_COLUMN";
2268 return "__builtin_source_location";
2270 llvm_unreachable(
"unexpected IdentKind!");
2274 const Expr *DefaultExpr)
const {
2278 if (
const auto *DIE = dyn_cast_if_present<CXXDefaultInitExpr>(DefaultExpr)) {
2279 Loc = DIE->getUsedLocation();
2280 Context = DIE->getUsedContext();
2281 }
else if (
const auto *DAE =
2282 dyn_cast_if_present<CXXDefaultArgExpr>(DefaultExpr)) {
2283 Loc = DAE->getUsedLocation();
2284 Context = DAE->getUsedContext();
2293 auto MakeStringLiteral = [&](StringRef Tmp) {
2297 LValuePathEntry
Path[1] = {LValuePathEntry::ArrayIndex(0)};
2308 return MakeStringLiteral(
FileName);
2314 return MakeStringLiteral(
Path);
2318 const auto *CurDecl = dyn_cast<Decl>(Context);
2322 return MakeStringLiteral(
2342 StringRef Name = F->getName();
2343 if (Name ==
"_M_file_name") {
2347 Value.getStructField(F->getFieldIndex()) = MakeStringLiteral(
Path);
2348 }
else if (Name ==
"_M_function_name") {
2351 const auto *CurDecl = dyn_cast<Decl>(Context);
2352 Value.getStructField(F->getFieldIndex()) = MakeStringLiteral(
2353 CurDecl && !isa<TranslationUnitDecl>(CurDecl)
2357 }
else if (Name ==
"_M_line") {
2359 Value.getStructField(F->getFieldIndex()) =
APValue(IntVal);
2360 }
else if (Name ==
"_M_column") {
2362 Value.getStructField(F->getFieldIndex()) =
APValue(IntVal);
2373 llvm_unreachable(
"unhandled case");
2378 unsigned NumOfElements)
2381 NumOfElements(NumOfElements) {
2390 InitExprs(
C, initExprs.size()), LBraceLoc(lbraceloc),
2391 RBraceLoc(rbraceloc), AltForm(nullptr,
true) {
2393 InitExprs.
insert(
C, InitExprs.
end(), initExprs.begin(), initExprs.end());
2399 if (NumInits > InitExprs.
size())
2404 InitExprs.
resize(
C, NumInits,
nullptr);
2421 ArrayFillerOrUnionFieldInit = filler;
2424 for (
unsigned i = 0, e =
getNumInits(); i != e; ++i)
2425 if (
inits[i] ==
nullptr)
2439 Init =
Init->IgnoreParenImpCasts();
2440 return isa<StringLiteral>(
Init) || isa<ObjCEncodeExpr>(
Init);
2444 assert(
isSemanticForm() &&
"syntactic form never semantically transparent");
2448 assert(
getNumInits() == 1 &&
"multiple inits in glvalue init list");
2467 assert(
isSyntacticForm() &&
"only test syntactic form as zero initializer");
2474 return Lit && Lit->
getValue() == 0;
2479 return SyntacticForm->getBeginLoc();
2484 E = InitExprs.
end();
2487 Beg = S->getBeginLoc();
2497 return SyntacticForm->getEndLoc();
2499 if (End.isInvalid()) {
2501 for (
Stmt *S : llvm::reverse(InitExprs)) {
2503 End = S->getEndLoc();
2515 return cast<BlockPointerType>(
getType())
2546 if (isa<DeclRefExpr>(
E))
2550 if (isa<ArraySubscriptExpr>(
E))
2554 if (isa<MemberExpr>(
E))
2558 if (
auto *UO = dyn_cast<UnaryOperator>(
E))
2559 if (UO->getOpcode() == UO_Deref)
2562 if (
auto *BO = dyn_cast<BinaryOperator>(
E)) {
2564 if (BO->isPtrMemOp())
2568 if (BO->getOpcode() == BO_Comma)
2569 return BO->getRHS()->isReadIfDiscardedInCPlusPlus11();
2574 if (
auto *CO = dyn_cast<ConditionalOperator>(
E))
2575 return CO->getTrueExpr()->isReadIfDiscardedInCPlusPlus11() &&
2576 CO->getFalseExpr()->isReadIfDiscardedInCPlusPlus11();
2579 dyn_cast<BinaryConditionalOperator>(
E)) {
2580 if (
auto *OVE = dyn_cast<OpaqueValueExpr>(BCO->getTrueExpr()))
2581 return OVE->getSourceExpr()->isReadIfDiscardedInCPlusPlus11() &&
2582 BCO->getFalseExpr()->isReadIfDiscardedInCPlusPlus11();
2586 if (isa<ObjCIvarRefExpr>(
E))
2588 if (
const auto *POE = dyn_cast<PseudoObjectExpr>(
E)) {
2589 if (isa<ObjCPropertyRefExpr, ObjCSubscriptRefExpr>(POE->getSyntacticForm()))
2616 case ParenExprClass:
2617 return cast<ParenExpr>(
this)->getSubExpr()->
2619 case GenericSelectionExprClass:
2620 return cast<GenericSelectionExpr>(
this)->getResultExpr()->
2622 case CoawaitExprClass:
2623 case CoyieldExprClass:
2624 return cast<CoroutineSuspendExpr>(
this)->getResumeExpr()->
2626 case ChooseExprClass:
2627 return cast<ChooseExpr>(
this)->getChosenSubExpr()->
2629 case UnaryOperatorClass: {
2663 case BinaryOperatorClass: {
2675 if (IE->getValue() == 0)
2694 case CompoundAssignOperatorClass:
2695 case VAArgExprClass:
2696 case AtomicExprClass:
2699 case ConditionalOperatorClass: {
2703 const auto *Exp = cast<ConditionalOperator>(
this);
2704 return Exp->getLHS()->isUnusedResultAWarning(WarnE,
Loc, R1, R2, Ctx) &&
2705 Exp->getRHS()->isUnusedResultAWarning(WarnE,
Loc, R1, R2, Ctx);
2707 case BinaryConditionalOperatorClass: {
2708 const auto *Exp = cast<BinaryConditionalOperator>(
this);
2709 return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE,
Loc, R1, R2, Ctx);
2712 case MemberExprClass:
2714 Loc = cast<MemberExpr>(
this)->getMemberLoc();
2716 R2 = cast<MemberExpr>(
this)->getBase()->getSourceRange();
2719 case ArraySubscriptExprClass:
2721 Loc = cast<ArraySubscriptExpr>(
this)->getRBracketLoc();
2722 R1 = cast<ArraySubscriptExpr>(
this)->getLHS()->getSourceRange();
2723 R2 = cast<ArraySubscriptExpr>(
this)->getRHS()->getSourceRange();
2726 case CXXOperatorCallExprClass: {
2738 case OO_ExclaimEqual:
2741 case OO_GreaterEqual:
2756 case CXXMemberCallExprClass:
2757 case UserDefinedLiteralClass: {
2759 const CallExpr *CE = cast<CallExpr>(
this);
2767 FD->hasAttr<PureAttr>() || FD->hasAttr<ConstAttr>()) {
2782 case UnresolvedLookupExprClass:
2783 case CXXUnresolvedConstructExprClass:
2784 case RecoveryExprClass:
2787 case CXXTemporaryObjectExprClass:
2788 case CXXConstructExprClass: {
2790 const auto *WarnURAttr =
Type->getAttr<WarnUnusedResultAttr>();
2792 (WarnURAttr && WarnURAttr->IsCXX11NoDiscard())) {
2800 const auto *CE = cast<CXXConstructExpr>(
this);
2802 const auto *WarnURAttr = Ctor->getAttr<WarnUnusedResultAttr>();
2803 if (WarnURAttr && WarnURAttr->IsCXX11NoDiscard()) {
2808 if (
unsigned NumArgs = CE->getNumArgs())
2810 CE->getArg(NumArgs - 1)->getEndLoc());
2818 case ObjCMessageExprClass: {
2831 if (MD->hasAttr<WarnUnusedResultAttr>()) {
2840 case ObjCPropertyRefExprClass:
2841 case ObjCSubscriptRefExprClass:
2847 case PseudoObjectExprClass: {
2848 const auto *POE = cast<PseudoObjectExpr>(
this);
2851 if (isa<ObjCPropertyRefExpr, ObjCSubscriptRefExpr>(
2852 POE->getSyntacticForm())) {
2860 if (
auto *BO = dyn_cast<BinaryOperator>(POE->getSyntacticForm()))
2861 if (BO->isAssignmentOp())
2863 if (
auto *UO = dyn_cast<UnaryOperator>(POE->getSyntacticForm()))
2864 if (UO->isIncrementDecrementOp())
2869 return Result &&
Result->isUnusedResultAWarning(WarnE,
Loc, R1, R2, Ctx);
2872 case StmtExprClass: {
2878 const CompoundStmt *CS = cast<StmtExpr>(
this)->getSubStmt();
2883 if (
const Expr *
E = dyn_cast<Expr>(
Label->getSubStmt()))
2890 Loc = cast<StmtExpr>(
this)->getLParenLoc();
2894 case CXXFunctionalCastExprClass:
2895 case CStyleCastExprClass: {
2902 const CastExpr *CE = cast<CastExpr>(
this);
2909 if (
auto *DRE = dyn_cast<DeclRefExpr>(SubE))
2910 if (
auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
2911 if (!VD->isExternallyVisible())
2927 if (CE->
getCastKind() == CK_ConstructorConversion)
2934 dyn_cast<CXXFunctionalCastExpr>(
this)) {
2935 Loc = CXXCE->getBeginLoc();
2936 R1 = CXXCE->getSubExpr()->getSourceRange();
2944 case ImplicitCastExprClass: {
2945 const CastExpr *ICE = cast<ImplicitCastExpr>(
this);
2954 case CXXDefaultArgExprClass:
2955 return (cast<CXXDefaultArgExpr>(
this)
2957 case CXXDefaultInitExprClass:
2958 return (cast<CXXDefaultInitExpr>(
this)
2961 case CXXNewExprClass:
2964 case CXXDeleteExprClass:
2966 case MaterializeTemporaryExprClass:
2967 return cast<MaterializeTemporaryExpr>(
this)
2969 ->isUnusedResultAWarning(WarnE,
Loc, R1, R2, Ctx);
2970 case CXXBindTemporaryExprClass:
2971 return cast<CXXBindTemporaryExpr>(
this)->getSubExpr()
2972 ->isUnusedResultAWarning(WarnE,
Loc, R1, R2, Ctx);
2973 case ExprWithCleanupsClass:
2974 return cast<ExprWithCleanups>(
this)->getSubExpr()
2975 ->isUnusedResultAWarning(WarnE,
Loc, R1, R2, Ctx);
2986 case ObjCIvarRefExprClass:
2988 case Expr::UnaryOperatorClass:
2989 return cast<UnaryOperator>(
E)->getSubExpr()->isOBJCGCCandidate(Ctx);
2990 case ImplicitCastExprClass:
2991 return cast<ImplicitCastExpr>(
E)->getSubExpr()->isOBJCGCCandidate(Ctx);
2992 case MaterializeTemporaryExprClass:
2993 return cast<MaterializeTemporaryExpr>(
E)->getSubExpr()->isOBJCGCCandidate(
2995 case CStyleCastExprClass:
2996 return cast<CStyleCastExpr>(
E)->getSubExpr()->isOBJCGCCandidate(Ctx);
2997 case DeclRefExprClass: {
2998 const Decl *
D = cast<DeclRefExpr>(
E)->getDecl();
3000 if (
const VarDecl *VD = dyn_cast<VarDecl>(
D)) {
3001 if (VD->hasGlobalStorage())
3011 case MemberExprClass: {
3015 case ArraySubscriptExprClass:
3016 return cast<ArraySubscriptExpr>(
E)->getBase()->isOBJCGCCandidate(Ctx);
3027 assert(
expr->hasPlaceholderType(BuiltinType::BoundMember));
3035 assert(isa<CXXMethodDecl>(mem->getMemberDecl()));
3036 return mem->getMemberDecl()->getType();
3042 assert(
type->isFunctionType());
3046 assert(isa<UnresolvedMemberExpr>(
expr) || isa<CXXPseudoDestructorExpr>(
expr));
3080 if (
auto *MCE = dyn_cast<CXXMemberCallExpr>(
this)) {
3081 if (isa_and_nonnull<CXXConversionDecl>(MCE->getMethodDecl()))
3082 return MCE->getImplicitObjectArgument();
3098 auto IgnoreNoopCastsSingleStep = [&Ctx](
Expr *
E) {
3099 if (
auto *CE = dyn_cast<CastExpr>(
E)) {
3102 Expr *SubExpr = CE->getSubExpr();
3103 bool IsIdentityCast =
3112 if (IsIdentityCast || IsSameWidthCast)
3114 }
else if (
auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(
E))
3115 return NTTP->getReplacement();
3120 IgnoreNoopCastsSingleStep);
3125 if (
auto *Cast = dyn_cast<CXXFunctionalCastExpr>(
E)) {
3126 auto *SE = Cast->getSubExpr();
3131 if (
auto *
C = dyn_cast<CXXConstructExpr>(
E)) {
3132 auto NumArgs =
C->getNumArgs();
3134 (NumArgs > 1 && isa<CXXDefaultArgExpr>(
C->getArg(1)))) {
3135 Expr *A =
C->getArg(0);
3142 auto IgnoreImplicitMemberCallSingleStep = [](
Expr *
E) {
3143 if (
auto *
C = dyn_cast<CXXMemberCallExpr>(
E)) {
3144 Expr *ExprNode =
C->getImplicitObjectArgument();
3148 if (
auto *PE = dyn_cast<ParenExpr>(ExprNode)) {
3149 if (PE->getSourceRange() ==
C->getSourceRange()) {
3150 return cast<Expr>(PE);
3162 IgnoreImplicitMemberCallSingleStep);
3166 const Expr *
E =
this;
3168 E = M->getSubExpr();
3171 E = ICE->getSubExprAsWritten();
3173 return isa<CXXDefaultArgExpr>(
E);
3180 E = M->getSubExpr();
3183 if (ICE->getCastKind() == CK_NoOp)
3184 E = ICE->getSubExpr();
3190 E = BE->getSubExpr();
3193 if (ICE->getCastKind() == CK_NoOp)
3194 E = ICE->getSubExpr();
3205 if (!
C.hasSameUnqualifiedType(
getType(),
C.getTypeDeclType(TempTy)))
3213 if (!isa<ObjCPropertyRefExpr>(
E))
3221 if (isa<ImplicitCastExpr>(
E)) {
3222 switch (cast<ImplicitCastExpr>(
E)->getCastKind()) {
3223 case CK_DerivedToBase:
3224 case CK_UncheckedDerivedToBase:
3232 if (isa<MemberExpr>(
E))
3236 if (BO->isPtrMemOp())
3240 if (isa<OpaqueValueExpr>(
E))
3247 const Expr *
E =
this;
3257 if (ICE->getCastKind() == CK_NoOp ||
3258 ICE->getCastKind() == CK_LValueToRValue ||
3259 ICE->getCastKind() == CK_DerivedToBase ||
3260 ICE->getCastKind() == CK_UncheckedDerivedToBase) {
3261 E = ICE->getSubExpr();
3267 if (UnOp->getOpcode() == UO_Extension) {
3268 E = UnOp->getSubExpr();
3274 = dyn_cast<MaterializeTemporaryExpr>(
E)) {
3275 E = M->getSubExpr();
3282 if (
const CXXThisExpr *This = dyn_cast<CXXThisExpr>(
E))
3283 return This->isImplicit();
3291 for (
unsigned I = 0; I < Exprs.size(); ++I)
3299 const Expr **Culprit)
const {
3301 "Expression evaluator can't be called on a dependent expression.");
3313 if (
auto *EWC = dyn_cast<ExprWithCleanups>(
this))
3314 return EWC->getSubExpr()->isConstantInitializer(Ctx,
true, Culprit);
3315 if (
auto *MTE = dyn_cast<MaterializeTemporaryExpr>(
this))
3316 return MTE->getSubExpr()->isConstantInitializer(Ctx,
false, Culprit);
3327 case Stmt::ExprWithCleanupsClass:
3329 Ctx, IsForRef, Culprit);
3330 case StringLiteralClass:
3331 case ObjCEncodeExprClass:
3333 case CXXTemporaryObjectExprClass:
3334 case CXXConstructExprClass: {
3343 assert(CE->
getNumArgs() == 1 &&
"trivial ctor with > 1 argument");
3349 case ConstantExprClass: {
3352 const Expr *Exp = cast<ConstantExpr>(
this)->getSubExpr();
3355 case CompoundLiteralExprClass: {
3359 const Expr *Exp = cast<CompoundLiteralExpr>(
this)->getInitializer();
3362 case DesignatedInitUpdateExprClass: {
3367 case InitListExprClass: {
3375 assert(ILE->
isSemanticForm() &&
"InitListExpr must be in semantic form");
3378 for (
unsigned i = 0; i < numInits; i++) {
3386 unsigned ElementNo = 0;
3391 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
3392 for (
unsigned i = 0, e = CXXRD->getNumBases(); i < e; i++) {
3393 if (ElementNo < ILE->getNumInits()) {
3401 for (
const auto *Field : RD->
fields()) {
3407 if (Field->isUnnamedBitField())
3410 if (ElementNo < ILE->getNumInits()) {
3412 if (Field->isBitField()) {
3421 bool RefType = Field->getType()->isReferenceType();
3432 case ImplicitValueInitExprClass:
3433 case NoInitExprClass:
3435 case ParenExprClass:
3436 return cast<ParenExpr>(
this)->getSubExpr()
3437 ->isConstantInitializer(Ctx, IsForRef, Culprit);
3438 case GenericSelectionExprClass:
3439 return cast<GenericSelectionExpr>(
this)->getResultExpr()
3440 ->isConstantInitializer(Ctx, IsForRef, Culprit);
3441 case ChooseExprClass:
3442 if (cast<ChooseExpr>(
this)->isConditionDependent()) {
3447 return cast<ChooseExpr>(
this)->getChosenSubExpr()
3449 case UnaryOperatorClass: {
3455 case PackIndexingExprClass: {
3456 return cast<PackIndexingExpr>(
this)
3458 ->isConstantInitializer(Ctx,
false, Culprit);
3460 case CXXFunctionalCastExprClass:
3461 case CXXStaticCastExprClass:
3462 case ImplicitCastExprClass:
3463 case CStyleCastExprClass:
3464 case ObjCBridgedCastExprClass:
3465 case CXXDynamicCastExprClass:
3466 case CXXReinterpretCastExprClass:
3467 case CXXAddrspaceCastExprClass:
3468 case CXXConstCastExprClass: {
3469 const CastExpr *CE = cast<CastExpr>(
this);
3484 case MaterializeTemporaryExprClass:
3485 return cast<MaterializeTemporaryExpr>(
this)
3487 ->isConstantInitializer(Ctx,
false, Culprit);
3489 case SubstNonTypeTemplateParmExprClass:
3490 return cast<SubstNonTypeTemplateParmExpr>(
this)->getReplacement()
3491 ->isConstantInitializer(Ctx,
false, Culprit);
3492 case CXXDefaultArgExprClass:
3493 return cast<CXXDefaultArgExpr>(
this)->getExpr()
3494 ->isConstantInitializer(Ctx,
false, Culprit);
3495 case CXXDefaultInitExprClass:
3496 return cast<CXXDefaultInitExpr>(
this)->getExpr()
3497 ->isConstantInitializer(Ctx,
false, Culprit);
3511 if (BuiltinID != Builtin::BI__assume &&
3512 BuiltinID != Builtin::BI__builtin_assume)
3529 const bool IncludePossibleEffects;
3530 bool HasSideEffects;
3533 explicit SideEffectFinder(
const ASTContext &Context,
bool IncludePossible)
3534 : Inherited(Context),
3535 IncludePossibleEffects(IncludePossible), HasSideEffects(
false) { }
3537 bool hasSideEffects()
const {
return HasSideEffects; }
3539 void VisitDecl(
const Decl *
D) {
3545 if (
auto *VD = dyn_cast<VarDecl>(
D)) {
3547 if (IncludePossibleEffects && VD->isThisDeclarationADefinition() &&
3548 VD->needsDestruction(Context))
3549 HasSideEffects =
true;
3553 void VisitDeclStmt(
const DeclStmt *DS) {
3554 for (
auto *
D : DS->
decls())
3556 Inherited::VisitDeclStmt(DS);
3559 void VisitExpr(
const Expr *
E) {
3560 if (!HasSideEffects &&
3562 HasSideEffects =
true;
3568 bool IncludePossibleEffects)
const {
3572 if (!IncludePossibleEffects &&
getExprLoc().isMacroID())
3577 #define ABSTRACT_STMT(Type)
3578 #define STMT(Type, Base) case Type##Class:
3579 #define EXPR(Type, Base)
3580 #include "clang/AST/StmtNodes.inc"
3581 llvm_unreachable(
"unexpected Expr kind");
3583 case DependentScopeDeclRefExprClass:
3584 case CXXUnresolvedConstructExprClass:
3585 case CXXDependentScopeMemberExprClass:
3586 case UnresolvedLookupExprClass:
3587 case UnresolvedMemberExprClass:
3588 case PackExpansionExprClass:
3589 case SubstNonTypeTemplateParmPackExprClass:
3590 case FunctionParmPackExprClass:
3592 case RecoveryExprClass:
3593 case CXXFoldExprClass:
3595 return IncludePossibleEffects;
3597 case DeclRefExprClass:
3598 case ObjCIvarRefExprClass:
3599 case PredefinedExprClass:
3600 case IntegerLiteralClass:
3601 case FixedPointLiteralClass:
3602 case FloatingLiteralClass:
3603 case ImaginaryLiteralClass:
3604 case StringLiteralClass:
3605 case CharacterLiteralClass:
3606 case OffsetOfExprClass:
3607 case ImplicitValueInitExprClass:
3608 case UnaryExprOrTypeTraitExprClass:
3609 case AddrLabelExprClass:
3610 case GNUNullExprClass:
3611 case ArrayInitIndexExprClass:
3612 case NoInitExprClass:
3613 case CXXBoolLiteralExprClass:
3614 case CXXNullPtrLiteralExprClass:
3615 case CXXThisExprClass:
3616 case CXXScalarValueInitExprClass:
3617 case TypeTraitExprClass:
3618 case ArrayTypeTraitExprClass:
3619 case ExpressionTraitExprClass:
3620 case CXXNoexceptExprClass:
3621 case SizeOfPackExprClass:
3622 case ObjCStringLiteralClass:
3623 case ObjCEncodeExprClass:
3624 case ObjCBoolLiteralExprClass:
3625 case ObjCAvailabilityCheckExprClass:
3626 case CXXUuidofExprClass:
3627 case OpaqueValueExprClass:
3628 case SourceLocExprClass:
3629 case EmbedExprClass:
3630 case ConceptSpecializationExprClass:
3631 case RequiresExprClass:
3632 case SYCLUniqueStableNameExprClass:
3633 case PackIndexingExprClass:
3637 case ConstantExprClass:
3639 return cast<ConstantExpr>(
this)->getSubExpr()->HasSideEffects(
3640 Ctx, IncludePossibleEffects);
3643 case CXXOperatorCallExprClass:
3644 case CXXMemberCallExprClass:
3645 case CUDAKernelCallExprClass:
3646 case UserDefinedLiteralClass: {
3650 const Decl *FD = cast<CallExpr>(
this)->getCalleeDecl();
3651 bool IsPure = FD && (FD->
hasAttr<ConstAttr>() || FD->
hasAttr<PureAttr>());
3652 if (IsPure || !IncludePossibleEffects)
3657 case BlockExprClass:
3658 case CXXBindTemporaryExprClass:
3659 if (!IncludePossibleEffects)
3663 case MSPropertyRefExprClass:
3664 case MSPropertySubscriptExprClass:
3665 case CompoundAssignOperatorClass:
3666 case VAArgExprClass:
3667 case AtomicExprClass:
3668 case CXXThrowExprClass:
3669 case CXXNewExprClass:
3670 case CXXDeleteExprClass:
3671 case CoawaitExprClass:
3672 case DependentCoawaitExprClass:
3673 case CoyieldExprClass:
3677 case StmtExprClass: {
3679 SideEffectFinder Finder(Ctx, IncludePossibleEffects);
3680 Finder.Visit(cast<StmtExpr>(
this)->getSubStmt());
3681 return Finder.hasSideEffects();
3684 case ExprWithCleanupsClass:
3685 if (IncludePossibleEffects)
3686 if (cast<ExprWithCleanups>(
this)->cleanupsHaveSideEffects())
3690 case ParenExprClass:
3691 case ArraySubscriptExprClass:
3692 case MatrixSubscriptExprClass:
3693 case ArraySectionExprClass:
3694 case OMPArrayShapingExprClass:
3695 case OMPIteratorExprClass:
3696 case MemberExprClass:
3697 case ConditionalOperatorClass:
3698 case BinaryConditionalOperatorClass:
3699 case CompoundLiteralExprClass:
3700 case ExtVectorElementExprClass:
3701 case DesignatedInitExprClass:
3702 case DesignatedInitUpdateExprClass:
3703 case ArrayInitLoopExprClass:
3704 case ParenListExprClass:
3705 case CXXPseudoDestructorExprClass:
3706 case CXXRewrittenBinaryOperatorClass:
3707 case CXXStdInitializerListExprClass:
3708 case SubstNonTypeTemplateParmExprClass:
3709 case MaterializeTemporaryExprClass:
3710 case ShuffleVectorExprClass:
3711 case ConvertVectorExprClass:
3712 case AsTypeExprClass:
3713 case CXXParenListInitExprClass:
3717 case UnaryOperatorClass:
3718 if (cast<UnaryOperator>(
this)->isIncrementDecrementOp())
3722 case BinaryOperatorClass:
3723 if (cast<BinaryOperator>(
this)->isAssignmentOp())
3727 case InitListExprClass:
3729 if (
const Expr *
E = cast<InitListExpr>(
this)->getArrayFiller())
3734 case GenericSelectionExprClass:
3735 return cast<GenericSelectionExpr>(
this)->getResultExpr()->
3738 case ChooseExprClass:
3739 return cast<ChooseExpr>(
this)->getChosenSubExpr()->HasSideEffects(
3740 Ctx, IncludePossibleEffects);
3742 case CXXDefaultArgExprClass:
3743 return cast<CXXDefaultArgExpr>(
this)->getExpr()->HasSideEffects(
3744 Ctx, IncludePossibleEffects);
3746 case CXXDefaultInitExprClass: {
3747 const FieldDecl *FD = cast<CXXDefaultInitExpr>(
this)->getField();
3754 case CXXDynamicCastExprClass: {
3762 case ImplicitCastExprClass:
3763 case CStyleCastExprClass:
3764 case CXXStaticCastExprClass:
3765 case CXXReinterpretCastExprClass:
3766 case CXXConstCastExprClass:
3767 case CXXAddrspaceCastExprClass:
3768 case CXXFunctionalCastExprClass:
3769 case BuiltinBitCastExprClass: {
3774 if (!IncludePossibleEffects)
3777 const CastExpr *CE = cast<CastExpr>(
this);
3784 case CXXTypeidExprClass: {
3785 const auto *TE = cast<CXXTypeidExpr>(
this);
3786 if (!TE->isPotentiallyEvaluated())
3791 if (IncludePossibleEffects && TE->hasNullCheck())
3797 case CXXConstructExprClass:
3798 case CXXTemporaryObjectExprClass: {
3807 case CXXInheritedCtorInitExprClass: {
3808 const auto *ICIE = cast<CXXInheritedCtorInitExpr>(
this);
3809 if (!ICIE->getConstructor()->isTrivial() && IncludePossibleEffects)
3814 case LambdaExprClass: {
3815 const LambdaExpr *LE = cast<LambdaExpr>(
this);
3816 for (
Expr *
E : LE->capture_inits())
3822 case PseudoObjectExprClass: {
3829 const Expr *Subexpr = *I;
3831 Subexpr = OVE->getSourceExpr();
3838 case ObjCBoxedExprClass:
3839 case ObjCArrayLiteralClass:
3840 case ObjCDictionaryLiteralClass:
3841 case ObjCSelectorExprClass:
3842 case ObjCProtocolExprClass:
3843 case ObjCIsaExprClass:
3844 case ObjCIndirectCopyRestoreExprClass:
3845 case ObjCSubscriptRefExprClass:
3846 case ObjCBridgedCastExprClass:
3847 case ObjCMessageExprClass:
3848 case ObjCPropertyRefExprClass:
3850 if (IncludePossibleEffects)
3858 cast<Expr>(SubStmt)->
HasSideEffects(Ctx, IncludePossibleEffects))
3865 if (
auto Call = dyn_cast<CallExpr>(
this))
3866 return Call->getFPFeaturesInEffect(LO);
3867 if (
auto UO = dyn_cast<UnaryOperator>(
this))
3868 return UO->getFPFeaturesInEffect(LO);
3869 if (
auto BO = dyn_cast<BinaryOperator>(
this))
3870 return BO->getFPFeaturesInEffect(LO);
3871 if (
auto Cast = dyn_cast<CastExpr>(
this))
3872 return Cast->getFPFeaturesInEffect(LO);
3885 explicit NonTrivialCallFinder(
const ASTContext &Context)
3886 : Inherited(Context), NonTrivial(
false) { }
3888 bool hasNonTrivialCall()
const {
return NonTrivial; }
3892 = dyn_cast_or_null<const CXXMethodDecl>(
E->getCalleeDecl())) {
3893 if (Method->isTrivial()) {
3895 Inherited::VisitStmt(
E);
3904 if (
E->getConstructor()->isTrivial()) {
3906 Inherited::VisitStmt(
E);
3917 E->getTemporary()->getDestructor()) {
3918 if (DtorDecl->isTrivial()) {
3919 Inherited::VisitStmt(
E);
3930 NonTrivialCallFinder Finder(Ctx);
3932 return Finder.hasNonTrivialCall();
3950 llvm_unreachable(
"Unexpected value dependent expression!");
3978 CE->getSubExpr()->getType()->isIntegerType())
3979 return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
3982 }
else if (
const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(
this)) {
3984 return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
3985 }
else if (
const ParenExpr *PE = dyn_cast<ParenExpr>(
this)) {
3988 return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
3990 dyn_cast<GenericSelectionExpr>(
this)) {
3991 if (GE->isResultDependent())
3993 return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC);
3994 }
else if (
const ChooseExpr *CE = dyn_cast<ChooseExpr>(
this)) {
3995 if (CE->isConditionDependent())
3997 return CE->getChosenSubExpr()->isNullPointerConstant(Ctx, NPC);
3999 = dyn_cast<CXXDefaultArgExpr>(
this)) {
4001 return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC);
4003 = dyn_cast<CXXDefaultInitExpr>(
this)) {
4005 return DefaultInit->getExpr()->isNullPointerConstant(Ctx, NPC);
4006 }
else if (isa<GNUNullExpr>(
this)) {
4010 = dyn_cast<MaterializeTemporaryExpr>(
this)) {
4011 return M->getSubExpr()->isNullPointerConstant(Ctx, NPC);
4012 }
else if (
const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(
this)) {
4013 if (
const Expr *Source = OVE->getSourceExpr())
4014 return Source->isNullPointerConstant(Ctx, NPC);
4023 if (
getType()->isNullPtrType())
4028 UT && UT->getDecl()->hasAttr<TransparentUnionAttr>())
4030 const Expr *InitExpr = CLE->getInitializer();
4031 if (
const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr))
4035 if (!
getType()->isIntegerType() ||
4058 if (isa<IntegerLiteral>(
this))
4066 const Expr *
E =
this;
4069 "expression is not a property reference");
4072 if (BO->getOpcode() == BO_Comma) {
4081 return cast<ObjCPropertyRefExpr>(
E);
4106 if (ICE->getCastKind() == CK_LValueToRValue ||
4107 (ICE->isGLValue() && ICE->getCastKind() == CK_NoOp))
4114 if (
FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl()))
4115 if (Field->isBitField())
4125 if (
FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl()))
4126 if (Field->isBitField())
4129 if (
BindingDecl *BD = dyn_cast<BindingDecl>(DeclRef->getDecl()))
4130 if (
Expr *
E = BD->getBinding())
4135 if (BinOp->isAssignmentOp() && BinOp->getLHS())
4136 return BinOp->getLHS()->getSourceBitField();
4138 if (BinOp->getOpcode() == BO_Comma && BinOp->getRHS())
4139 return BinOp->getRHS()->getSourceBitField();
4143 if (UnOp->isPrefix() && UnOp->isIncrementDecrementOp())
4144 return UnOp->getSubExpr()->getSourceBitField();
4151 if (
auto *DRE = dyn_cast<DeclRefExpr>(
E))
4152 return dyn_cast<EnumConstantDecl>(DRE->getDecl());
4161 if (ICE->isGLValue() && ICE->getCastKind() == CK_NoOp)
4170 if (isa<ExtVectorElementExpr>(
E))
4173 if (
auto *DRE = dyn_cast<DeclRefExpr>(
E))
4174 if (
auto *BD = dyn_cast<BindingDecl>(DRE->getDecl()))
4175 if (
auto *
E = BD->getBinding())
4185 if (
const auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
4187 VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())
4203 case CXXThisExprClass:
4205 case DeclRefExprClass: {
4208 const auto *DRE1 = cast<DeclRefExpr>(E1);
4209 const auto *DRE2 = cast<DeclRefExpr>(E2);
4210 return DRE1->isPRValue() && DRE2->isPRValue() &&
4211 DRE1->getDecl() == DRE2->getDecl();
4213 case ImplicitCastExprClass: {
4216 const auto *ICE1 = dyn_cast<ImplicitCastExpr>(E1);
4217 const auto *ICE2 = dyn_cast<ImplicitCastExpr>(E2);
4220 if (ICE1->getCastKind() != ICE2->getCastKind())
4225 if (ICE1->getCastKind() == CK_LValueToRValue ||
4226 ICE1->getCastKind() == CK_ArrayToPointerDecay ||
4227 ICE1->getCastKind() == CK_FunctionToPointerDecay) {
4232 const auto *DRE1 = dyn_cast<DeclRefExpr>(E1);
4233 const auto *DRE2 = dyn_cast<DeclRefExpr>(E2);
4237 const auto *Ivar1 = dyn_cast<ObjCIvarRefExpr>(E1);
4238 const auto *Ivar2 = dyn_cast<ObjCIvarRefExpr>(E2);
4239 if (Ivar1 && Ivar2) {
4240 return Ivar1->isFreeIvar() && Ivar2->isFreeIvar() &&
4244 const auto *Array1 = dyn_cast<ArraySubscriptExpr>(E1);
4245 const auto *Array2 = dyn_cast<ArraySubscriptExpr>(E2);
4246 if (Array1 && Array2) {
4250 auto Idx1 = Array1->getIdx();
4251 auto Idx2 = Array2->getIdx();
4252 const auto Integer1 = dyn_cast<IntegerLiteral>(Idx1);
4253 const auto Integer2 = dyn_cast<IntegerLiteral>(Idx2);
4254 if (Integer1 && Integer2) {
4255 if (!llvm::APInt::isSameValue(Integer1->getValue(),
4256 Integer2->getValue()))
4267 while (isa<MemberExpr>(E1) && isa<MemberExpr>(E2)) {
4268 const auto *ME1 = cast<MemberExpr>(E1);
4269 const auto *ME2 = cast<MemberExpr>(E2);
4272 if (
const auto *
D = dyn_cast<VarDecl>(ME1->getMemberDecl()))
4273 if (
D->isStaticDataMember())
4279 if (isa<CXXThisExpr>(E1) && isa<CXXThisExpr>(E2))
4285 if (
const auto *DRE = dyn_cast<DeclRefExpr>(
E))
4286 return DRE->getDecl();
4287 if (
const auto *ME = dyn_cast<MemberExpr>(
E))
4288 return ME->getMemberDecl();
4307 return VT->getNumElements();
4315 StringRef Comp = Accessor->
getName();
4318 if (Comp ==
"hi" || Comp ==
"lo" || Comp ==
"even" || Comp ==
"odd")
4322 if (Comp[0] ==
's' || Comp[0] ==
'S')
4323 Comp = Comp.substr(1);
4325 for (
unsigned i = 0, e = Comp.size(); i != e; ++i)
4326 if (Comp.substr(i + 1).contains(Comp[i]))
4335 StringRef Comp = Accessor->
getName();
4336 bool isNumericAccessor =
false;
4337 if (Comp[0] ==
's' || Comp[0] ==
'S') {
4338 Comp = Comp.substr(1);
4339 isNumericAccessor =
true;
4342 bool isHi = Comp ==
"hi";
4343 bool isLo = Comp ==
"lo";
4344 bool isEven = Comp ==
"even";
4345 bool isOdd = Comp ==
"odd";
4361 Elts.push_back(Index);
4369 BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) {
4370 SubExprs =
new (
C)
Stmt*[args.size()];
4371 for (
unsigned i = 0; i != args.size(); i++)
4372 SubExprs[i] = args[i];
4378 if (SubExprs)
C.Deallocate(SubExprs);
4380 this->NumExprs = Exprs.size();
4381 SubExprs =
new (
C)
Stmt*[NumExprs];
4382 memcpy(SubExprs, Exprs.data(),
sizeof(
Expr *) * Exprs.size());
4385GenericSelectionExpr::GenericSelectionExpr(
4389 bool ContainsUnexpandedParameterPack,
unsigned ResultIndex)
4390 :
Expr(GenericSelectionExprClass, AssocExprs[ResultIndex]->getType(),
4391 AssocExprs[ResultIndex]->getValueKind(),
4392 AssocExprs[ResultIndex]->getObjectKind()),
4393 NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex),
4394 IsExprPredicate(
true), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4395 assert(AssocTypes.size() == AssocExprs.size() &&
4396 "Must have the same number of association expressions"
4397 " and TypeSourceInfo!");
4398 assert(ResultIndex < NumAssocs &&
"ResultIndex is out-of-bounds!");
4401 getTrailingObjects<Stmt *>()[getIndexOfControllingExpression()] =
4403 std::copy(AssocExprs.begin(), AssocExprs.end(),
4404 getTrailingObjects<Stmt *>() + getIndexOfStartOfAssociatedExprs());
4405 std::copy(AssocTypes.begin(), AssocTypes.end(),
4406 getTrailingObjects<TypeSourceInfo *>() +
4407 getIndexOfStartOfAssociatedTypes());
4412GenericSelectionExpr::GenericSelectionExpr(
4417 unsigned ResultIndex)
4418 :
Expr(GenericSelectionExprClass, AssocExprs[ResultIndex]->getType(),
4419 AssocExprs[ResultIndex]->getValueKind(),
4420 AssocExprs[ResultIndex]->getObjectKind()),
4421 NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex),
4422 IsExprPredicate(
false), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4423 assert(AssocTypes.size() == AssocExprs.size() &&
4424 "Must have the same number of association expressions"
4425 " and TypeSourceInfo!");
4426 assert(ResultIndex < NumAssocs &&
"ResultIndex is out-of-bounds!");
4429 getTrailingObjects<TypeSourceInfo *>()[getIndexOfControllingType()] =
4431 std::copy(AssocExprs.begin(), AssocExprs.end(),
4432 getTrailingObjects<Stmt *>() + getIndexOfStartOfAssociatedExprs());
4433 std::copy(AssocTypes.begin(), AssocTypes.end(),
4434 getTrailingObjects<TypeSourceInfo *>() +
4435 getIndexOfStartOfAssociatedTypes());
4440GenericSelectionExpr::GenericSelectionExpr(
4444 bool ContainsUnexpandedParameterPack)
4445 :
Expr(GenericSelectionExprClass, Context.DependentTy,
VK_PRValue,
4447 NumAssocs(AssocExprs.size()), ResultIndex(ResultDependentIndex),
4448 IsExprPredicate(
true), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4449 assert(AssocTypes.size() == AssocExprs.size() &&
4450 "Must have the same number of association expressions"
4451 " and TypeSourceInfo!");
4454 getTrailingObjects<Stmt *>()[getIndexOfControllingExpression()] =
4456 std::copy(AssocExprs.begin(), AssocExprs.end(),
4457 getTrailingObjects<Stmt *>() + getIndexOfStartOfAssociatedExprs());
4458 std::copy(AssocTypes.begin(), AssocTypes.end(),
4459 getTrailingObjects<TypeSourceInfo *>() +
4460 getIndexOfStartOfAssociatedTypes());
4465GenericSelectionExpr::GenericSelectionExpr(
4470 :
Expr(GenericSelectionExprClass, Context.DependentTy,
VK_PRValue,
4472 NumAssocs(AssocExprs.size()), ResultIndex(ResultDependentIndex),
4473 IsExprPredicate(
false), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4474 assert(AssocTypes.size() == AssocExprs.size() &&
4475 "Must have the same number of association expressions"
4476 " and TypeSourceInfo!");
4479 getTrailingObjects<TypeSourceInfo *>()[getIndexOfControllingType()] =
4481 std::copy(AssocExprs.begin(), AssocExprs.end(),
4482 getTrailingObjects<Stmt *>() + getIndexOfStartOfAssociatedExprs());
4483 std::copy(AssocTypes.begin(), AssocTypes.end(),
4484 getTrailingObjects<TypeSourceInfo *>() +
4485 getIndexOfStartOfAssociatedTypes());
4490GenericSelectionExpr::GenericSelectionExpr(EmptyShell
Empty,
unsigned NumAssocs)
4491 :
Expr(GenericSelectionExprClass,
Empty), NumAssocs(NumAssocs) {}
4497 bool ContainsUnexpandedParameterPack,
unsigned ResultIndex) {
4498 unsigned NumAssocs = AssocExprs.size();
4500 totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4503 Context, GenericLoc, ControllingExpr, AssocTypes, AssocExprs, DefaultLoc,
4504 RParenLoc, ContainsUnexpandedParameterPack, ResultIndex);
4511 bool ContainsUnexpandedParameterPack) {
4512 unsigned NumAssocs = AssocExprs.size();
4514 totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4517 Context, GenericLoc, ControllingExpr, AssocTypes, AssocExprs, DefaultLoc,
4518 RParenLoc, ContainsUnexpandedParameterPack);
4526 unsigned ResultIndex) {
4527 unsigned NumAssocs = AssocExprs.size();
4529 totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4532 Context, GenericLoc, ControllingType, AssocTypes, AssocExprs, DefaultLoc,
4533 RParenLoc, ContainsUnexpandedParameterPack, ResultIndex);
4540 SourceLocation RParenLoc,
bool ContainsUnexpandedParameterPack) {
4541 unsigned NumAssocs = AssocExprs.size();
4543 totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4546 Context, GenericLoc, ControllingType, AssocTypes, AssocExprs, DefaultLoc,
4547 RParenLoc, ContainsUnexpandedParameterPack);
4552 unsigned NumAssocs) {
4554 totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4577 EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax),
4578 NumDesignators(Designators.
size()), NumSubExprs(IndexExprs.
size() + 1) {
4579 this->Designators =
new (
C)
Designator[NumDesignators];
4587 unsigned IndexIdx = 0;
4588 for (
unsigned I = 0; I != NumDesignators; ++I) {
4589 this->Designators[I] = Designators[I];
4592 *Child++ = IndexExprs[IndexIdx++];
4595 *Child++ = IndexExprs[IndexIdx++];
4596 *Child++ = IndexExprs[IndexIdx++];
4600 assert(IndexIdx == IndexExprs.size() &&
"Wrong number of index expressions");
4609 bool UsesColonSyntax,
Expr *
Init) {
4610 void *Mem =
C.Allocate(totalSizeToAlloc<Stmt *>(IndexExprs.size() + 1),
4613 ColonOrEqualLoc, UsesColonSyntax,
4618 unsigned NumIndexExprs) {
4619 void *Mem =
C.Allocate(totalSizeToAlloc<Stmt *>(NumIndexExprs + 1),
4626 unsigned NumDesigs) {
4628 NumDesignators = NumDesigs;
4629 for (
unsigned I = 0; I != NumDesigs; ++I)
4630 Designators[I] = Desigs[I];
4644 if (
First.isFieldDesignator()) {
4647 for (
unsigned int i = 0; i < DIE->size(); i++) {
4655 return First.getLBracketLoc();
4663 assert(
D.isArrayDesignator() &&
"Requires array designator");
4668 assert(
D.isArrayRangeDesignator() &&
"Requires array range designator");
4673 assert(
D.isArrayRangeDesignator() &&
"Requires array range designator");
4682 unsigned NumNewDesignators =
Last -
First;
4683 if (NumNewDesignators == 0) {
4684 std::copy_backward(Designators + Idx + 1,
4685 Designators + NumDesignators,
4687 --NumNewDesignators;
4690 if (NumNewDesignators == 1) {
4691 Designators[Idx] = *
First;
4696 =
new (
C)
Designator[NumDesignators - 1 + NumNewDesignators];
4697 std::copy(Designators, Designators + Idx, NewDesignators);
4698 std::copy(
First,
Last, NewDesignators + Idx);
4699 std::copy(Designators + Idx + 1, Designators + NumDesignators,
4700 NewDesignators + Idx + NumNewDesignators);
4701 Designators = NewDesignators;
4702 NumDesignators = NumDesignators - 1 + NumNewDesignators;
4711 BaseAndUpdaterExprs[0] = baseExpr;
4716 BaseAndUpdaterExprs[1] = ILE;
4733 LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
4736 for (
unsigned I = 0, N = Exprs.size(); I != N; ++I)
4737 getTrailingObjects<Stmt *>()[I] = Exprs[I];
4741ParenListExpr::ParenListExpr(EmptyShell
Empty,
unsigned NumExprs)
4750 void *Mem = Ctx.
Allocate(totalSizeToAlloc<Stmt *>(Exprs.size()),
4752 return new (Mem)
ParenListExpr(LParenLoc, Exprs, RParenLoc);
4756 unsigned NumExprs) {
4766 :
Expr(BinaryOperatorClass, ResTy, VK, OK) {
4769 "Use CompoundAssignOperator for compound assignments");
4771 SubExprs[LHS] = lhs;
4772 SubExprs[RHS] = rhs;
4783 :
Expr(CompoundAssignOperatorClass, ResTy, VK, OK) {
4786 "Use CompoundAssignOperator for compound assignments");
4788 SubExprs[LHS] = lhs;
4789 SubExprs[RHS] = rhs;
4797 bool HasFPFeatures) {
4837 CompLHSType, CompResultType);
4841 bool hasFPFeatures) {
4842 void *Mem =
C.Allocate(totalSizeToAlloc<FPOptionsOverride>(hasFPFeatures),
4851 :
Expr(UnaryOperatorClass,
type, VK, OK), Val(input) {
4867 unsigned Size = totalSizeToAlloc<FPOptionsOverride>(HasFPFeatures);
4875 e = ewc->getSubExpr();
4877 e = m->getSubExpr();
4878 e = cast<CXXConstructExpr>(e)->getArg(0);
4880 e = ice->getSubExpr();
4881 return cast<OpaqueValueExpr>(e);
4886 unsigned numSemanticExprs) {