clang: lib/AST/Expr.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
35#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/Format.h"
37#include "llvm/Support/raw_ostream.h"
38#include
39#include
40#include
41using namespace clang;
42
45 while (true) {
47
48
49 if (auto *BO = dyn_cast(E)) {
50 if (BO->getOpcode() == BO_Comma) {
51 E = BO->getRHS();
52 continue;
53 }
54 }
55
56
57 if (auto *MTE = dyn_cast(E)) {
58 E = MTE->getSubExpr();
59 continue;
60 }
61
62 break;
63 }
64
65 return E;
66}
67
73
75 return nullptr;
76
79 return cast(D);
80}
81
86 while (true) {
88
89 if (const auto *CE = dyn_cast(E)) {
90 if ((CE->getCastKind() == CK_DerivedToBase ||
91 CE->getCastKind() == CK_UncheckedDerivedToBase) &&
93 E = CE->getSubExpr();
94 const auto *Derived =
97 continue;
98 }
99
100 if (CE->getCastKind() == CK_NoOp) {
101 E = CE->getSubExpr();
102 continue;
103 }
104 } else if (const auto *ME = dyn_cast(E)) {
105 if (!ME->isArrow()) {
106 assert(ME->getBase()->getType()->getAsRecordDecl());
107 if (const auto *Field = dyn_cast(ME->getMemberDecl())) {
108 if (!Field->isBitField() && !Field->getType()->isReferenceType()) {
109 E = ME->getBase();
111 continue;
112 }
113 }
114 }
115 } else if (const auto *BO = dyn_cast(E)) {
116 if (BO->getOpcode() == BO_PtrMemD) {
117 assert(BO->getRHS()->isPRValue());
118 E = BO->getLHS();
121 continue;
122 }
123 if (BO->getOpcode() == BO_Comma) {
124 CommaLHSs.push_back(BO->getLHS());
125 E = BO->getRHS();
126 continue;
127 }
128 }
129
130
131 break;
132 }
133 return E;
134}
135
138
139
141
143
144 if (const UnaryOperator *UO = dyn_cast(E)) {
145 switch (UO->getOpcode()) {
146 case UO_Plus:
147 return UO->getSubExpr()->isKnownToHaveBooleanValue(Semantic);
148 case UO_LNot:
149 return true;
150 default:
151 return false;
152 }
153 }
154
155
156
157
159 return CE->getSubExpr()->isKnownToHaveBooleanValue(Semantic);
160
161 if (const BinaryOperator *BO = dyn_cast(E)) {
162 switch (BO->getOpcode()) {
163 default: return false;
164 case BO_LT:
165 case BO_GT:
166 case BO_LE:
167 case BO_GE:
168 case BO_EQ:
169 case BO_NE:
170 case BO_LAnd:
171 case BO_LOr:
172 return true;
173
174 case BO_And:
175 case BO_Xor:
176 case BO_Or:
177
178 return BO->getLHS()->isKnownToHaveBooleanValue(Semantic) &&
179 BO->getRHS()->isKnownToHaveBooleanValue(Semantic);
180
181 case BO_Comma:
182 case BO_Assign:
183 return BO->getRHS()->isKnownToHaveBooleanValue(Semantic);
184 }
185 }
186
188 return CO->getTrueExpr()->isKnownToHaveBooleanValue(Semantic) &&
189 CO->getFalseExpr()->isKnownToHaveBooleanValue(Semantic);
190
191 if (isa(E))
192 return true;
193
194 if (const auto *OVE = dyn_cast(E))
195 return OVE->getSourceExpr()->isKnownToHaveBooleanValue(Semantic);
196
198 if (!Semantic && FD->getType()->isUnsignedIntegerType() &&
199 !FD->getBitWidth()->isValueDependent() && FD->getBitWidthValue() == 1)
200 return true;
201
202 return false;
203}
204
208 bool IgnoreTemplateOrMacroSubstitution) const {
211
212 if (const auto *ME = dyn_cast(E))
213 D = ME->getMemberDecl();
214 else if (const auto *DRE = dyn_cast(E))
215 D = DRE->getDecl();
216 else if (const auto *IRE = dyn_cast(E))
217 D = IRE->getDecl();
218
220 StrictFlexArraysLevel,
221 IgnoreTemplateOrMacroSubstitution);
222}
223
227
230
231 if (Value.isMemberPointer())
232 return Value.getMemberPointerDecl();
233
234 if (Value.isLValue() && Value.getLValueOffset().isZero())
235 return Value.getLValueBase().dyn_cast<const ValueDecl *>();
236 }
237
238 return nullptr;
239}
240
241
242
243
244
245namespace {
246
247
248 template <class E, class T>
251 return static_cast<const E*>(expr)->getExprLoc();
252 }
253
254
255
256
257
258 template
261 return static_cast<const E *>(expr)->getBeginLoc();
262 }
263}
264
266 if (isa(getType()))
269 const auto *ED = cast(ECD->getDeclContext());
270 if (ED->isCompleteDefinition())
272 }
274}
275
278 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
279#define ABSTRACT_STMT(type)
280#define STMT(type, base) \
281 case Stmt::type##Class: break;
282#define EXPR(type, base) \
283 case Stmt::type##Class: return getExprLocImpl(this, &type::getExprLoc);
284#include "clang/AST/StmtNodes.inc"
285 }
286 llvm_unreachable("unknown expression kind");
287}
288
289
290
291
292
297 "Invalid StorageKind Value");
298 (void)Kind;
299}
300
307 if (.getInt().needsCleanup())
309 [[fallthrough]];
310 default:
312 }
313}
314
320}
321
323 bool IsImmediateInvocation)
324 : FullExpr(ConstantExprClass, SubExpr) {
325 ConstantExprBits.ResultKind = llvm::to_underlying(StorageKind);
330 ConstantExprBits.IsImmediateInvocation = IsImmediateInvocation;
331
333 ::new (getTrailingObjects()) APValue();
334}
335
338 bool IsImmediateInvocation) {
339 assert(!isa(E));
341
342 unsigned Size = totalSizeToAlloc<APValue, uint64_t>(
346 return new (Mem) ConstantExpr(E, StorageKind, IsImmediateInvocation);
347}
348
355}
356
357ConstantExpr::ConstantExpr(EmptyShell Empty,
360 ConstantExprBits.ResultKind = llvm::to_underlying(StorageKind);
361
363 ::new (getTrailingObjects()) APValue();
364}
365
369
370 unsigned Size = totalSizeToAlloc<APValue, uint64_t>(
375}
376
379 "Invalid storage for this value kind");
383 return;
385 Int64Result() = *Value.getInt().getRawData();
388 return;
393 }
394 APValueResult() = std::move(Value);
395 return;
396 }
397 llvm_unreachable("Invalid ResultKind Bits");
398}
399
403 return APValueResult().getInt();
405 return llvm::APSInt(llvm::APInt(ConstantExprBits.BitWidth, Int64Result()),
407 default:
408 llvm_unreachable("invalid Accessor");
409 }
410}
411
413
416 return APValueResult();
419 llvm::APSInt(llvm::APInt(ConstantExprBits.BitWidth, Int64Result()),
425 }
426 llvm_unreachable("invalid ResultKind");
427}
428
430 bool RefersToEnclosingVariableOrCapture, QualType T,
440 RefersToEnclosingVariableOrCapture;
441 DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter = false;
446}
447
448DeclRefExpr::DeclRefExpr(const ASTContext &Ctx,
451 bool RefersToEnclosingVariableOrCapture,
456 DNLoc(NameInfo.getInfo()) {
459 if (QualifierLoc)
460 new (getTrailingObjects())
463 if (FoundD)
464 *getTrailingObjects<NamedDecl *>() = FoundD;
466 = (TemplateArgs || TemplateKWLoc.isValid()) ? 1 : 0;
468 RefersToEnclosingVariableOrCapture;
469 DeclRefExprBits.CapturedByCopyInLambdaWithExplicitObjectParameter = false;
471 if (TemplateArgs) {
472 auto Deps = TemplateArgumentDependence::None;
473 getTrailingObjects()->initializeFrom(
474 TemplateKWLoc, *TemplateArgs, getTrailingObjects(),
475 Deps);
476 assert(!(Deps & TemplateArgumentDependence::Dependent) &&
477 "built a DeclRefExpr with dependent template args");
478 } else if (TemplateKWLoc.isValid()) {
479 getTrailingObjects()->initializeFrom(
480 TemplateKWLoc);
481 }
485}
486
490 bool RefersToEnclosingVariableOrCapture,
495 return Create(Context, QualifierLoc, TemplateKWLoc, D,
496 RefersToEnclosingVariableOrCapture,
498 T, VK, FoundD, TemplateArgs, NOUR);
499}
500
504 bool RefersToEnclosingVariableOrCapture,
510
511 if (D == FoundD)
512 FoundD = nullptr;
513
514 bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
515 std::size_t Size =
518 QualifierLoc ? 1 : 0, FoundD ? 1 : 0,
519 HasTemplateKWAndArgsInfo ? 1 : 0,
520 TemplateArgs ? TemplateArgs->size() : 0);
521
523 return new (Mem) DeclRefExpr(Context, QualifierLoc, TemplateKWLoc, D,
524 RefersToEnclosingVariableOrCapture, NameInfo,
525 FoundD, TemplateArgs, T, VK, NOUR);
526}
527
529 bool HasQualifier,
530 bool HasFoundDecl,
531 bool HasTemplateKWAndArgsInfo,
532 unsigned NumTemplateArgs) {
533 assert(NumTemplateArgs == 0 || HasTemplateKWAndArgsInfo);
534 std::size_t Size =
537 HasQualifier ? 1 : 0, HasFoundDecl ? 1 : 0, HasTemplateKWAndArgsInfo,
538 NumTemplateArgs);
541}
542
544 D = NewD;
545 if (getType()->isUndeducedType())
548}
549
554}
559}
560
561SYCLUniqueStableNameExpr::SYCLUniqueStableNameExpr(SourceLocation OpLoc,
567 OpLoc(OpLoc), LParen(LParen), RParen(RParen) {
568 setTypeSourceInfo(TSI);
570}
571
572SYCLUniqueStableNameExpr::SYCLUniqueStableNameExpr(EmptyShell Empty,
575
581 return new (Ctx)
583}
584
589}
590
594}
595
598 auto MangleCallback = [](ASTContext &Ctx,
599 const NamedDecl *ND) -> std::optional {
600 if (const auto *RD = dyn_cast(ND))
601 return RD->getDeviceLambdaManglingNumber();
602 return std::nullopt;
603 };
604
607
608 std::string Buffer;
609 Buffer.reserve(128);
610 llvm::raw_string_ostream Out(Buffer);
611 Ctx->mangleCanonicalTypeName(Ty, Out);
612
613 return Buffer;
614}
615
621 assert((getIdentKind() == IK) &&
622 "IdentKind do not fit in PredefinedExprBitfields!");
623 bool HasFunctionName = SL != nullptr;
627 if (HasFunctionName)
628 setFunctionName(SL);
630}
631
632PredefinedExpr::PredefinedExpr(EmptyShell Empty, bool HasFunctionName)
633 : Expr(PredefinedExprClass, Empty) {
635}
636
640 bool HasFunctionName = SL != nullptr;
641 void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName),
643 return new (Mem) PredefinedExpr(L, FNTy, IK, IsTransparent, SL);
644}
645
647 bool HasFunctionName) {
648 void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(HasFunctionName),
651}
652
654 switch (IK) {
656 return "__func__";
658 return "__FUNCTION__";
660 return "__FUNCDNAME__";
662 return "L__FUNCTION__";
664 return "__PRETTY_FUNCTION__";
666 return "__FUNCSIG__";
668 return "L__FUNCSIG__";
670 break;
671 }
672 llvm_unreachable("Unknown ident kind for PredefinedExpr");
673}
674
675
676
678 const Decl *CurrentDecl,
679 bool ForceElaboratedPrinting) {
681
683 if (const NamedDecl *ND = dyn_cast(CurrentDecl)) {
684 std::unique_ptr MC;
686
687 if (MC->shouldMangleDeclName(ND)) {
689 llvm::raw_svector_ostream Out(Buffer);
693 else if (const CXXDestructorDecl *DD = dyn_cast(ND))
695 else if (ND->hasAttr())
696 GD = GlobalDecl(cast(ND));
697 else
699 MC->mangleName(GD, Out);
700
701 if (!Buffer.empty() && Buffer.front() == '\01')
702 return std::string(Buffer.substr(1));
703 return std::string(Buffer);
704 }
705 return std::string(ND->getIdentifier()->getName());
706 }
707 return "";
708 }
709 if (isa(CurrentDecl)) {
710
711
712
714 if (DC->isFileContext())
715 return "";
716
718 llvm::raw_svector_ostream Out(Buffer);
719 if (auto *DCBlock = dyn_cast(DC))
720
722 else if (auto *DCDecl = dyn_cast(DC))
723 Out << ComputeName(IK, DCDecl) << "_block_invoke";
724 return std::string(Out.str());
725 }
726 if (const FunctionDecl *FD = dyn_cast(CurrentDecl)) {
728 bool IsFuncOrFunctionInNonMSVCCompatEnv =
730 IK == PredefinedIdentKind ::Function) &&
731 !LO.MSVCCompat);
732 bool IsLFunctionInMSVCCommpatEnv =
734 bool IsFuncOrFunctionOrLFunctionOrFuncDName =
739 if ((ForceElaboratedPrinting &&
740 (IsFuncOrFunctionInNonMSVCCompatEnv || IsLFunctionInMSVCCommpatEnv)) ||
741 (!ForceElaboratedPrinting && IsFuncOrFunctionOrLFunctionOrFuncDName))
742 return FD->getNameAsString();
743
745 llvm::raw_svector_ostream Out(Name);
746
747 if (const CXXMethodDecl *MD = dyn_cast(FD)) {
749 Out << "virtual ";
750 if (MD->isStatic())
751 Out << "static ";
752 }
753
755 public:
756 PrettyCallbacks(const LangOptions &LO) : LO(LO) {}
757 std::string remapPath(StringRef Path) const override {
760 return std::string(p);
761 }
762
763 private:
765 };
767 PrettyCallbacks PrettyCB(Context.getLangOpts());
771 std::string Proto;
772 llvm::raw_string_ostream POut(Proto);
773
776 Decl = Pattern;
777
778
779
780
781 const Type *Ty = Decl->getType().getTypePtrOrNull();
782 if (!Ty)
783 return "";
784
787 if (FD->hasWrittenPrototype())
788 FT = dyn_cast(AFT);
789
793 case CC_C: POut << "__cdecl "; break;
799
800 default: break;
801 }
802 }
803
804 FD->printQualifiedName(POut, Policy);
805
807 Out << Proto;
808 return std::string(Name);
809 }
810
811 POut << "(";
812 if (FT) {
813 for (unsigned i = 0, e = Decl->getNumParams(); i != e; ++i) {
814 if (i) POut << ", ";
815 POut << Decl->getParamDecl(i)->getType().stream(Policy);
816 }
817
818 if (FT->isVariadic()) {
819 if (FD->getNumParams()) POut << ", ";
820 POut << "...";
824 ->getNumParams()) {
825 POut << "void";
826 }
827 }
828 POut << ")";
829
830 if (const CXXMethodDecl *MD = dyn_cast(FD)) {
831 assert(FT && "We must have a written prototype in this case.");
832 if (FT->isConst())
833 POut << " const";
834 if (FT->isVolatile())
835 POut << " volatile";
838 POut << " &";
840 POut << " &&";
841 }
842
844 SpecsTy Specs;
845 const DeclContext *Ctx = FD->getDeclContext();
846 while (isa_and_nonnull(Ctx)) {
848 = dyn_cast(Ctx);
850 Specs.push_back(Spec);
852 }
853
854 std::string TemplateParams;
855 llvm::raw_string_ostream TOut(TemplateParams);
858 D->getSpecializedTemplate()->getTemplateParameters();
860 assert(Params->size() == Args.size());
861 for (unsigned i = 0, numParams = Params->size(); i != numParams; ++i) {
863 if (Param.empty()) continue;
864 TOut << Param << " = ";
865 Args.get(i).print(Policy, TOut,
867 Policy, Params, i));
868 TOut << ", ";
869 }
870 }
871
873 = FD->getTemplateSpecializationInfo();
878 assert(Params->size() == Args->size());
879 for (unsigned i = 0, e = Params->size(); i != e; ++i) {
881 if (Param.empty()) continue;
882 TOut << Param << " = ";
883 Args->get(i).print(Policy, TOut, true);
884 TOut << ", ";
885 }
886 }
887
888 if (!TemplateParams.empty()) {
889
890 TemplateParams.resize(TemplateParams.size() - 2);
891 POut << " [" << TemplateParams << "]";
892 }
893
894
895
896
897
898 if (isa(FD) &&
899 cast(FD)->getParent()->isLambda())
900 Proto = "auto " + Proto;
901 else if (FT && FT->getReturnType()->getAs<DecltypeType>())
902 FT->getReturnType()
906 else if (!isa(FD) && !isa(FD))
908
909 Out << Proto;
910
911 return std::string(Name);
912 }
913 if (const CapturedDecl *CD = dyn_cast(CurrentDecl)) {
915
916
917 if (DC->isFunctionOrMethod() && (DC->getDeclKind() != Decl::Captured)) {
920 }
921 llvm_unreachable("CapturedDecl not inside a function or method");
922 }
923 if (const ObjCMethodDecl *MD = dyn_cast(CurrentDecl)) {
925 llvm::raw_svector_ostream Out(Name);
926 Out << (MD->isInstanceMethod() ? '-' : '+');
927 Out << '[';
928
929
930
932 Out << *ID;
933
935 dyn_cast(MD->getDeclContext()))
936 Out << '(' << *CID << ')';
937
938 Out << ' ';
939 MD->getSelector().print(Out);
940 Out << ']';
941
942 return std::string(Name);
943 }
944 if (isa(CurrentDecl) &&
946
947 return "top level";
948 }
949 return "";
950}
951
953 const llvm::APInt &Val) {
954 if (hasAllocation())
956
957 BitWidth = Val.getBitWidth();
958 unsigned NumWords = Val.getNumWords();
959 const uint64_t* Words = Val.getRawData();
960 if (NumWords > 1) {
961 pVal = new (C) uint64_t[NumWords];
962 std::copy(Words, Words + NumWords, pVal);
963 } else if (NumWords == 1)
964 VAL = Words[0];
965 else
967}
968
969IntegerLiteral::IntegerLiteral(const ASTContext &C, const llvm::APInt &V,
972 assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
973 assert(V.getBitWidth() == C.getIntWidth(type) &&
974 "Integer type is not the correct size for constant.");
977}
978
983}
984
988}
989
990FixedPointLiteral::FixedPointLiteral(const ASTContext &C, const llvm::APInt &V,
992 unsigned Scale)
994 Scale(Scale) {
995 assert(type->isFixedPointType() && "Illegal type in FixedPointLiteral");
996 assert(V.getBitWidth() == C.getTypeInfo(type).Width &&
997 "Fixed point type is not the correct size for constant.");
1000}
1001
1003 const llvm::APInt &V,
1006 unsigned Scale) {
1008}
1009
1013}
1014
1016
1017
1018
1021 S, llvm::APSInt::getUnsigned(getValue().getZExtValue()), Scale);
1022 return std::string(S);
1023}
1024
1026 raw_ostream &OS) {
1027 switch (Kind) {
1029 break;
1031 OS << 'L';
1032 break;
1034 OS << "u8";
1035 break;
1037 OS << 'u';
1038 break;
1040 OS << 'U';
1041 break;
1042 }
1043
1044 StringRef Escaped = escapeCStyleEscapeChar::Single(Val);
1045 if (!Escaped.empty()) {
1046 OS << "'" << Escaped << "'";
1047 } else {
1048
1049
1050
1051
1053 Val &= 0xFFu;
1054 if (Val < 256 && isPrintable((unsigned char)Val))
1055 OS << "'" << (char)Val << "'";
1056 else if (Val < 256)
1057 OS << "'\\x" << llvm::format("%02x", Val) << "'";
1058 else if (Val <= 0xFFFF)
1059 OS << "'\\u" << llvm::format("%04x", Val) << "'";
1060 else
1061 OS << "'\\U" << llvm::format("%08x", Val) << "'";
1062 }
1063}
1064
1065FloatingLiteral::FloatingLiteral(const ASTContext &C, const llvm::APFloat &V,
1068 setSemantics(V.getSemantics());
1072}
1073
1074FloatingLiteral::FloatingLiteral(const ASTContext &C, EmptyShell Empty)
1075 : Expr(FloatingLiteralClass, Empty) {
1076 setRawSemantics(llvm::APFloatBase::S_IEEEhalf);
1078}
1079
1084}
1085
1089}
1090
1091
1092
1093
1096 bool ignored;
1097 V.convert(llvm::APFloat::IEEEdouble(), llvm::APFloat::rmNearestTiesToEven,
1098 &ignored);
1099 return V.convertToDouble();
1100}
1101
1102unsigned StringLiteral::mapCharByteWidth(TargetInfo const &Target,
1104 unsigned CharByteWidth = 0;
1105 switch (SK) {
1108 CharByteWidth = Target.getCharWidth();
1109 break;
1111 CharByteWidth = Target.getWCharWidth();
1112 break;
1114 CharByteWidth = Target.getChar16Width();
1115 break;
1117 CharByteWidth = Target.getChar32Width();
1118 break;
1120 return sizeof(char);
1121 }
1122 assert((CharByteWidth & 7) == 0 && "Assumes character size is byte multiple");
1123 CharByteWidth /= 8;
1124 assert((CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) &&
1125 "The only supported character byte widths are 1,2 and 4!");
1126 return CharByteWidth;
1127}
1128
1129StringLiteral::StringLiteral(const ASTContext &Ctx, StringRef Str,
1132 unsigned NumConcatenated)
1134
1135 unsigned Length = Str.size();
1136
1139
1142 "StringLiteral must be of constant array type!");
1143 unsigned CharByteWidth = mapCharByteWidth(Ctx.getTargetInfo(), Kind);
1144 unsigned ByteLength = Str.size();
1145 assert((ByteLength % CharByteWidth == 0) &&
1146 "The size of the data must be a multiple of CharByteWidth!");
1147
1148
1149
1150
1151 switch (CharByteWidth) {
1152 case 1:
1153 Length = ByteLength;
1154 break;
1155 case 2:
1156 Length = ByteLength / 2;
1157 break;
1158 case 4:
1159 Length = ByteLength / 4;
1160 break;
1161 default:
1162 llvm_unreachable("Unsupported character width!");
1163 }
1164
1167 } else {
1168 assert(!Pascal && "Can't make an unevaluated Pascal string");
1171 }
1172
1173 *getTrailingObjects() = Length;
1174
1175
1176
1177 std::memcpy(getTrailingObjects(), Loc,
1179
1180
1181 std::memcpy(getTrailingObjects(), Str.data(), Str.size());
1182
1184}
1185
1186StringLiteral::StringLiteral(EmptyShell Empty, unsigned NumConcatenated,
1187 unsigned Length, unsigned CharByteWidth)
1188 : Expr(StringLiteralClass, Empty) {
1191 *getTrailingObjects() = Length;
1192}
1193
1197 unsigned NumConcatenated) {
1198 void *Mem = Ctx.Allocate(totalSizeToAlloc<unsigned, SourceLocation, char>(
1199 1, NumConcatenated, Str.size()),
1201 return new (Mem)
1202 StringLiteral(Ctx, Str, Kind, Pascal, Ty, Loc, NumConcatenated);
1203}
1204
1206 unsigned NumConcatenated,
1207 unsigned Length,
1208 unsigned CharByteWidth) {
1209 void *Mem = Ctx.Allocate(totalSizeToAlloc<unsigned, SourceLocation, char>(
1210 1, NumConcatenated, Length * CharByteWidth),
1212 return new (Mem)
1214}
1215
1220 break;
1222 OS << 'L';
1223 break;
1225 OS << "u8";
1226 break;
1228 OS << 'u';
1229 break;
1231 OS << 'U';
1232 break;
1233 }
1234 OS << '"';
1235 static const char Hex[] = "0123456789ABCDEF";
1236
1237 unsigned LastSlashX = getLength();
1238 for (unsigned I = 0, N = getLength(); I != N; ++I) {
1240 StringRef Escaped = escapeCStyleEscapeChar::Double(Char);
1241 if (Escaped.empty()) {
1242
1243
1244
1245
1247 Char >= 0xd800 && Char <= 0xdbff) {
1249 if (Trail >= 0xdc00 && Trail <= 0xdfff) {
1250 Char = 0x10000 + ((Char - 0xd800) << 10) + (Trail - 0xdc00);
1251 ++I;
1252 }
1253 }
1254
1255 if (Char > 0xff) {
1256
1257
1258
1260 (Char >= 0xd800 && Char <= 0xdfff) || Char >= 0x110000) {
1261
1262 OS << "\\x";
1263 int Shift = 28;
1264 while ((Char >> Shift) == 0)
1265 Shift -= 4;
1266 for (; Shift >= 0; Shift -= 4)
1267 OS << Hex[(Char >> Shift) & 15];
1268 LastSlashX = I;
1269 continue;
1270 }
1271
1272 if (Char > 0xffff)
1273 OS << "\\U00"
1274 << Hex[(Char >> 20) & 15]
1275 << Hex[(Char >> 16) & 15];
1276 else
1277 OS << "\\u";
1278 OS << Hex[(Char >> 12) & 15]
1279 << Hex[(Char >> 8) & 15]
1280 << Hex[(Char >> 4) & 15]
1281 << Hex[(Char >> 0) & 15];
1282 continue;
1283 }
1284
1285
1286
1287 if (LastSlashX + 1 == I) {
1288 switch (Char) {
1289 case '0': case '1': case '2': case '3': case '4':
1290 case '5': case '6': case '7': case '8': case '9':
1291 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
1292 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
1293 OS << "\"\"";
1294 }
1295 }
1296
1297 assert(Char <= 0xff &&
1298 "Characters above 0xff should already have been handled.");
1299
1301 OS << (char)Char;
1302 else
1303 OS << '\\'
1304 << (char)('0' + ((Char >> 6) & 7))
1305 << (char)('0' + ((Char >> 3) & 7))
1306 << (char)('0' + ((Char >> 0) & 7));
1307 } else {
1308
1309 OS << Escaped;
1310 }
1311 }
1312 OS << '"';
1313}
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1335 unsigned *StartTokenByteOffset) const {
1339 "Only narrow string literals are currently supported");
1340
1341
1342
1343 unsigned TokNo = 0;
1344 unsigned StringOffset = 0;
1345 if (StartToken)
1346 TokNo = *StartToken;
1347 if (StartTokenByteOffset) {
1348 StringOffset = *StartTokenByteOffset;
1349 ByteNo -= StringOffset;
1350 }
1351 while (true) {
1354
1355
1356
1357
1358 SourceLocation StrTokSpellingLoc = SM.getSpellingLoc(StrTokLoc);
1359
1360
1361 std::pair<FileID, unsigned> LocInfo =
1362 SM.getDecomposedLoc(StrTokSpellingLoc);
1364 StringRef Buffer = SM.getBufferData(LocInfo.first, &Invalid);
1366 if (StartTokenByteOffset != nullptr)
1367 *StartTokenByteOffset = StringOffset;
1368 if (StartToken != nullptr)
1369 *StartToken = TokNo;
1370 return StrTokSpellingLoc;
1371 }
1372
1373 const char *StrData = Buffer.data()+LocInfo.second;
1374
1375
1376 Lexer TheLexer(SM.getLocForStartOfFile(LocInfo.first), Features,
1377 Buffer.begin(), StrData, Buffer.end());
1380
1381
1384
1385
1386 if (ByteNo < TokNumBytes ||
1389
1390
1391
1392 if (StartTokenByteOffset != nullptr)
1393 *StartTokenByteOffset = StringOffset;
1394 if (StartToken != nullptr)
1395 *StartToken = TokNo;
1397 }
1398
1399
1400 StringOffset += TokNumBytes;
1401 ++TokNo;
1402 ByteNo -= TokNumBytes;
1403 }
1404}
1405
1406
1407
1409 switch (Op) {
1410#define UNARY_OPERATION(Name, Spelling) case UO_##Name: return Spelling;
1411#include "clang/AST/OperationKinds.def"
1412 }
1413 llvm_unreachable("Unknown unary operator");
1414}
1415
1418 switch (OO) {
1419 default: llvm_unreachable("No unary operator for overloaded function");
1420 case OO_PlusPlus: return Postfix ? UO_PostInc : UO_PreInc;
1421 case OO_MinusMinus: return Postfix ? UO_PostDec : UO_PreDec;
1422 case OO_Amp: return UO_AddrOf;
1423 case OO_Star: return UO_Deref;
1424 case OO_Plus: return UO_Plus;
1425 case OO_Minus: return UO_Minus;
1426 case OO_Tilde: return UO_Not;
1427 case OO_Exclaim: return UO_LNot;
1428 case OO_Coawait: return UO_Coawait;
1429 }
1430}
1431
1433 switch (Opc) {
1434 case UO_PostInc: case UO_PreInc: return OO_PlusPlus;
1435 case UO_PostDec: case UO_PreDec: return OO_MinusMinus;
1436 case UO_AddrOf: return OO_Amp;
1437 case UO_Deref: return OO_Star;
1438 case UO_Plus: return OO_Plus;
1439 case UO_Minus: return OO_Minus;
1440 case UO_Not: return OO_Tilde;
1441 case UO_LNot: return OO_Exclaim;
1442 case UO_Coawait: return OO_Coawait;
1443 default: return OO_None;
1444 }
1445}
1446
1447
1448
1449
1450
1451
1455 unsigned MinNumArgs, ADLCallKind UsesADL)
1457 NumArgs = std::max(Args.size(), MinNumArgs);
1458 unsigned NumPreArgs = PreArgs.size();
1460 assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!");
1461
1462 unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC);
1463 CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects;
1464 assert((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) &&
1465 "OffsetToTrailingObjects overflow!");
1466
1468
1470 for (unsigned I = 0; I != NumPreArgs; ++I)
1472 for (unsigned I = 0; I != Args.size(); ++I)
1474 for (unsigned I = Args.size(); I != NumArgs; ++I)
1476
1478
1483}
1484
1487 : Expr(SC, Empty), NumArgs(NumArgs) {
1489 assert((NumPreArgs == getNumPreArgs()) && "NumPreArgs overflow!");
1490
1491 unsigned OffsetToTrailingObjects = offsetToTrailingObjects(SC);
1492 CallExprBits.OffsetToTrailingObjects = OffsetToTrailingObjects;
1493 assert((CallExprBits.OffsetToTrailingObjects == OffsetToTrailingObjects) &&
1494 "OffsetToTrailingObjects overflow!");
1497}
1498
1504 unsigned NumArgs = std::max(Args.size(), MinNumArgs);
1507 void *Mem =
1509 return new (Mem) CallExpr(CallExprClass, Fn, {}, Args, Ty, VK,
1510 RParenLoc, FPFeatures, MinNumArgs, UsesADL);
1511}
1512
1516 assert(!(reinterpret_cast<uintptr_t>(Mem) % alignof(CallExpr)) &&
1517 "Misaligned memory in CallExpr::CreateTemporary!");
1518 return new (Mem) CallExpr(CallExprClass, Fn, {}, {}, Ty,
1520 0, UsesADL);
1521}
1522
1525 unsigned SizeOfTrailingObjects =
1527 void *Mem =
1529 return new (Mem)
1530 CallExpr(CallExprClass, 0, NumArgs, HasFPFeatures, Empty);
1531}
1532
1533unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) {
1534 switch (SC) {
1535 case CallExprClass:
1537 case CXXOperatorCallExprClass:
1539 case CXXMemberCallExprClass:
1541 case UserDefinedLiteralClass:
1543 case CUDAKernelCallExprClass:
1545 default:
1546 llvm_unreachable("unexpected class deriving from CallExpr!");
1547 }
1548}
1549
1552
1553 while (auto *NTTP = dyn_cast(CEE))
1555
1556
1557 while (true) {
1558 if (auto *BO = dyn_cast(CEE)) {
1559 if (BO->isPtrMemOp()) {
1561 continue;
1562 }
1563 } else if (auto *UO = dyn_cast(CEE)) {
1564 if (UO->getOpcode() == UO_Deref || UO->getOpcode() == UO_AddrOf ||
1565 UO->getOpcode() == UO_Plus) {
1567 continue;
1568 }
1569 }
1570 break;
1571 }
1572
1573 if (auto *DRE = dyn_cast(CEE))
1574 return DRE->getDecl();
1575 if (auto *ME = dyn_cast(CEE))
1576 return ME->getMemberDecl();
1577 if (auto *BE = dyn_cast(CEE))
1578 return BE->getBlockDecl();
1579
1580 return nullptr;
1581}
1582
1583
1586 return FDecl ? FDecl->getBuiltinID() : 0;
1587}
1588
1592 return false;
1593}
1594
1597 QualType CalleeType = Callee->getType();
1598 if (const auto *FnTypePtr = CalleeType->getAs<PointerType>()) {
1603 if (isa(Callee->IgnoreParens()))
1605
1606 if (isa(Callee->IgnoreParens()))
1608
1609
1611 assert(!CalleeType.isNull());
1613
1614
1619 }
1620
1623}
1624
1625std::pair<const NamedDecl *, const Attr *>
1627
1629 if (const auto *A = D->getAttr())
1630 return {nullptr, A};
1631
1632
1633
1635 if (const auto *A = TD->getAttr())
1636 return {TD, A};
1637
1638 for (const auto *TD = getCallReturnType(Ctx)->getAs(); TD;
1639 TD = TD->desugar()->getAs())
1640 if (const auto *A = TD->getDecl()->getAttr())
1641 return {TD->getDecl(), A};
1642 return {nullptr, nullptr};
1643}
1644
1646 if (const auto *OCE = dyn_cast(this))
1647 return OCE->getBeginLoc();
1648
1649 if (const auto *Method =
1650 dyn_cast_if_present(getCalleeDecl());
1651 Method && Method->isExplicitObjectMemberFunction()) {
1654 }
1655
1659 return begin;
1660}
1661
1663 if (const auto *OCE = dyn_cast(this))
1664 return OCE->getEndLoc();
1665
1669 return end;
1670}
1671
1678 void *Mem = C.Allocate(
1679 totalSizeToAlloc<OffsetOfNode, Expr *>(comps.size(), exprs.size()));
1680
1681 return new (Mem) OffsetOfExpr(C, type, OperatorLoc, tsi, comps, exprs,
1682 RParenLoc);
1683}
1684
1686 unsigned numComps, unsigned numExprs) {
1687 void *Mem =
1688 C.Allocate(totalSizeToAlloc<OffsetOfNode, Expr *>(numComps, numExprs));
1689 return new (Mem) OffsetOfExpr(numComps, numExprs);
1690}
1691
1697 OperatorLoc(OperatorLoc), RParenLoc(RParenLoc), TSInfo(tsi),
1698 NumComps(comps.size()), NumExprs(exprs.size()) {
1699 for (unsigned i = 0; i != comps.size(); ++i)
1701 for (unsigned i = 0; i != exprs.size(); ++i)
1703
1705}
1706
1711
1713}
1714
1719 OpLoc(op), RParenLoc(rp) {
1720 assert(ExprKind <= UETT_Last && "invalid enum value!");
1723 "UnaryExprOrTypeTraitExprBits.Kind overflow!");
1725 Argument.Ex = E;
1727}
1728
1737 : Expr(MemberExprClass, T, VK, OK), Base(Base), MemberDecl(MemberDecl),
1738 MemberDNLoc(NameInfo.getInfo()), MemberLoc(NameInfo.getLoc()) {
1739 assert(!NameInfo.getName() ||
1744 FoundDecl.getDecl() != MemberDecl ||
1747 TemplateArgs || TemplateKWLoc.isValid();
1751
1752 if (hasQualifier())
1753 new (getTrailingObjects())
1755 if (hasFoundDecl())
1756 *getTrailingObjects() = FoundDecl;
1757 if (TemplateArgs) {
1758 auto Deps = TemplateArgumentDependence::None;
1759 getTrailingObjects()->initializeFrom(
1760 TemplateKWLoc, *TemplateArgs, getTrailingObjects(),
1761 Deps);
1762 } else if (TemplateKWLoc.isValid()) {
1763 getTrailingObjects()->initializeFrom(
1764 TemplateKWLoc);
1765 }
1767}
1768
1775 bool HasQualifier = QualifierLoc.hasQualifier();
1776 bool HasFoundDecl = FoundDecl.getDecl() != MemberDecl ||
1778 bool HasTemplateKWAndArgsInfo = TemplateArgs || TemplateKWLoc.isValid();
1779 std::size_t Size =
1782 HasQualifier, HasFoundDecl, HasTemplateKWAndArgsInfo,
1783 TemplateArgs ? TemplateArgs->size() : 0);
1784
1785 void *Mem = C.Allocate(Size, alignof(MemberExpr));
1786 return new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, QualifierLoc,
1787 TemplateKWLoc, MemberDecl, FoundDecl, NameInfo,
1788 TemplateArgs, T, VK, OK, NOUR);
1789}
1790
1792 bool HasQualifier, bool HasFoundDecl,
1793 bool HasTemplateKWAndArgsInfo,
1794 unsigned NumTemplateArgs) {
1795 assert((!NumTemplateArgs || HasTemplateKWAndArgsInfo) &&
1796 "template args but no template arg info?");
1797 std::size_t Size =
1800 HasQualifier, HasFoundDecl, HasTemplateKWAndArgsInfo,
1801 NumTemplateArgs);
1804}
1805
1807 MemberDecl = NewD;
1808 if (getType()->isUndeducedType())
1811}
1812
1817 return MemberLoc;
1818 }
1819
1820
1821
1823 if (BaseStartLoc.isValid())
1824 return BaseStartLoc;
1825 return MemberLoc;
1826}
1833 return EndLoc;
1834}
1835
1836bool CastExpr::CastConsistency() const {
1838 case CK_DerivedToBase:
1839 case CK_UncheckedDerivedToBase:
1840 case CK_DerivedToBaseMemberPointer:
1841 case CK_BaseToDerived:
1842 case CK_BaseToDerivedMemberPointer:
1843 assert(() && "Cast kind should have a base path!");
1844 break;
1845
1846 case CK_CPointerToObjCPointerCast:
1847 assert(getType()->isObjCObjectPointerType());
1849 goto CheckNoBasePath;
1850
1851 case CK_BlockPointerToObjCPointerCast:
1852 assert(getType()->isObjCObjectPointerType());
1854 goto CheckNoBasePath;
1855
1856 case CK_ReinterpretMemberPointer:
1857 assert(getType()->isMemberPointerType());
1859 goto CheckNoBasePath;
1860
1861 case CK_BitCast:
1862
1863
1864
1865 if (()->isPointerType()) {
1866 assert(getType()->isObjCObjectPointerType() ==
1868 assert(getType()->isBlockPointerType() ==
1870 }
1871 goto CheckNoBasePath;
1872
1873 case CK_AnyPointerToBlockPointerCast:
1874 assert(getType()->isBlockPointerType());
1877 goto CheckNoBasePath;
1878
1879 case CK_CopyAndAutoreleaseBlockObject:
1880 assert(getType()->isBlockPointerType());
1882 goto CheckNoBasePath;
1883
1884 case CK_FunctionToPointerDecay:
1885 assert(getType()->isPointerType());
1887 goto CheckNoBasePath;
1888
1889 case CK_AddressSpaceConversion: {
1896 }
1897 assert((Ty->isDependentType() || SETy->isDependentType()) ||
1898 (!Ty.isNull() && !SETy.isNull() &&
1900 goto CheckNoBasePath;
1901 }
1902
1903 case CK_Dynamic:
1904 case CK_ToUnion:
1905 case CK_ArrayToPointerDecay:
1906 case CK_NullToMemberPointer:
1907 case CK_NullToPointer:
1908 case CK_ConstructorConversion:
1909 case CK_IntegralToPointer:
1910 case CK_PointerToIntegral:
1911 case CK_ToVoid:
1912 case CK_VectorSplat:
1913 case CK_IntegralCast:
1914 case CK_BooleanToSignedIntegral:
1915 case CK_IntegralToFloating:
1916 case CK_FloatingToIntegral:
1917 case CK_FloatingCast:
1918 case CK_ObjCObjectLValueCast:
1919 case CK_FloatingRealToComplex:
1920 case CK_FloatingComplexToReal:
1921 case CK_FloatingComplexCast:
1922 case CK_FloatingComplexToIntegralComplex:
1923 case CK_IntegralRealToComplex:
1924 case CK_IntegralComplexToReal:
1925 case CK_IntegralComplexCast:
1926 case CK_IntegralComplexToFloatingComplex:
1927 case CK_ARCProduceObject:
1928 case CK_ARCConsumeObject:
1929 case CK_ARCReclaimReturnedObject:
1930 case CK_ARCExtendBlockObject:
1931 case CK_ZeroToOCLOpaqueType:
1932 case CK_IntToOCLSampler:
1933 case CK_FloatingToFixedPoint:
1934 case CK_FixedPointToFloating:
1935 case CK_FixedPointCast:
1936 case CK_FixedPointToIntegral:
1937 case CK_IntegralToFixedPoint:
1938 case CK_MatrixCast:
1940 goto CheckNoBasePath;
1941
1942 case CK_Dependent:
1943 case CK_LValueToRValue:
1944 case CK_NoOp:
1945 case CK_AtomicToNonAtomic:
1946 case CK_NonAtomicToAtomic:
1947 case CK_PointerToBoolean:
1948 case CK_IntegralToBoolean:
1949 case CK_FloatingToBoolean:
1950 case CK_MemberPointerToBoolean:
1951 case CK_FloatingComplexToBoolean:
1952 case CK_IntegralComplexToBoolean:
1953 case CK_LValueBitCast:
1954 case CK_LValueToRValueBitCast:
1955 case CK_UserDefinedConversion:
1956 case CK_BuiltinFnToFnPtr:
1957 case CK_FixedPointToBoolean:
1958 case CK_HLSLArrayRValue:
1959 case CK_HLSLVectorTruncation:
1960 CheckNoBasePath:
1961 assert(path_empty() && "Cast kind should not have a base path!");
1962 break;
1963 }
1964 return true;
1965}
1966
1968 switch (CK) {
1969#define CAST_OPERATION(Name) case CK_##Name: return #Name;
1970#include "clang/AST/OperationKinds.def"
1971 }
1972 llvm_unreachable("Unhandled cast kind!");
1973}
1974
1975namespace {
1976
1977
1978static Expr *ignoreImplicitSemaNodes(Expr *E) {
1979 if (auto *Materialize = dyn_cast(E))
1980 return Materialize->getSubExpr();
1981
1982 if (auto *Binder = dyn_cast(E))
1983 return Binder->getSubExpr();
1984
1985 if (auto *Full = dyn_cast(E))
1986 return Full->getSubExpr();
1987
1988 if (auto *CPLIE = dyn_cast(E);
1989 CPLIE && CPLIE->getInitExprs().size() == 1)
1990 return CPLIE->getInitExprs()[0];
1991
1992 return E;
1993}
1994}
1995
1997 const Expr *SubExpr = nullptr;
1998
1999 for (const CastExpr *E = this; E; E = dyn_cast(SubExpr)) {
2000 SubExpr = IgnoreExprNodes(E->getSubExpr(), ignoreImplicitSemaNodes);
2001
2002
2003
2004 if (E->getCastKind() == CK_ConstructorConversion) {
2005 SubExpr = IgnoreExprNodes(cast(SubExpr)->getArg(0),
2006 ignoreImplicitSemaNodes);
2007 } else if (E->getCastKind() == CK_UserDefinedConversion) {
2008 assert((isa<CallExpr, BlockExpr>(SubExpr)) &&
2009 "Unexpected SubExpr for CK_UserDefinedConversion.");
2010 if (auto *MCE = dyn_cast(SubExpr))
2011 SubExpr = MCE->getImplicitObjectArgument();
2012 }
2013 }
2014
2015 return const_cast<Expr *>(SubExpr);
2016}
2017
2019 const Expr *SubExpr = nullptr;
2020
2021 for (const CastExpr *E = this; E; E = dyn_cast(SubExpr)) {
2022 SubExpr = IgnoreExprNodes(E->getSubExpr(), ignoreImplicitSemaNodes);
2023
2024 if (E->getCastKind() == CK_ConstructorConversion)
2025 return cast(SubExpr)->getConstructor();
2026
2027 if (E->getCastKind() == CK_UserDefinedConversion) {
2028 if (auto *MCE = dyn_cast(SubExpr))
2029 return MCE->getMethodDecl();
2030 }
2031 }
2032
2033 return nullptr;
2034}
2035
2038#define ABSTRACT_STMT(x)
2039#define CASTEXPR(Type, Base) \
2040 case Stmt::Type##Class: \
2041 return static_cast<Type *>(this)->getTrailingObjects<CXXBaseSpecifier *>();
2042#define STMT(Type, Base)
2043#include "clang/AST/StmtNodes.inc"
2044 default:
2045 llvm_unreachable("non-cast expressions not possible here");
2046 }
2047}
2048
2053}
2054
2060 Field != FieldEnd; ++Field) {
2062 !Field->isUnnamedBitField()) {
2063 return *Field;
2064 }
2065 }
2066 return nullptr;
2067}
2068
2072 case ImplicitCastExprClass:
2074 ->getTrailingObjects();
2075 case CStyleCastExprClass:
2077 ->getTrailingObjects();
2078 case CXXFunctionalCastExprClass:
2080 ->getTrailingObjects();
2081 case CXXStaticCastExprClass:
2083 ->getTrailingObjects();
2084 default:
2085 llvm_unreachable("Cast does not have FPFeatures");
2086 }
2087}
2088
2094 unsigned PathSize = (BasePath ? BasePath->size() : 0);
2095 void *Buffer =
2096 C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
2098
2099
2100 assert((Kind != CK_LValueToRValue ||
2102 "invalid type for lvalue-to-rvalue conversion");
2104 new (Buffer) ImplicitCastExpr(T, Kind, Operand, PathSize, FPO, VK);
2105 if (PathSize)
2106 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
2108 return E;
2109}
2110
2112 unsigned PathSize,
2113 bool HasFPFeatures) {
2114 void *Buffer =
2115 C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
2116 PathSize, HasFPFeatures));
2118}
2119
2126 unsigned PathSize = (BasePath ? BasePath->size() : 0);
2127 void *Buffer =
2128 C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
2131 new (Buffer) CStyleCastExpr(T, VK, K, Op, PathSize, FPO, WrittenTy, L, R);
2132 if (PathSize)
2133 std::uninitialized_copy_n(BasePath->data(), BasePath->size(),
2135 return E;
2136}
2137
2139 unsigned PathSize,
2140 bool HasFPFeatures) {
2141 void *Buffer =
2142 C.Allocate(totalSizeToAlloc<CXXBaseSpecifier *, FPOptionsOverride>(
2143 PathSize, HasFPFeatures));
2145}
2146
2147
2148
2150 switch (Op) {
2151#define BINARY_OPERATION(Name, Spelling) case BO_##Name: return Spelling;
2152#include "clang/AST/OperationKinds.def"
2153 }
2154 llvm_unreachable("Invalid OpCode!");
2155}
2156
2159 switch (OO) {
2160 default: llvm_unreachable("Not an overloadable binary operator");
2161 case OO_Plus: return BO_Add;
2162 case OO_Minus: return BO_Sub;
2163 case OO_Star: return BO_Mul;
2164 case OO_Slash: return BO_Div;
2165 case OO_Percent: return BO_Rem;
2166 case OO_Caret: return BO_Xor;
2167 case OO_Amp: return BO_And;
2168 case OO_Pipe: return BO_Or;
2169 case OO_Equal: return BO_Assign;
2170 case OO_Spaceship: return BO_Cmp;
2171 case OO_Less: return BO_LT;
2172 case OO_Greater: return BO_GT;
2173 case OO_PlusEqual: return BO_AddAssign;
2174 case OO_MinusEqual: return BO_SubAssign;
2175 case OO_StarEqual: return BO_MulAssign;
2176 case OO_SlashEqual: return BO_DivAssign;
2177 case OO_PercentEqual: return BO_RemAssign;
2178 case OO_CaretEqual: return BO_XorAssign;
2179 case OO_AmpEqual: return BO_AndAssign;
2180 case OO_PipeEqual: return BO_OrAssign;
2181 case OO_LessLess: return BO_Shl;
2182 case OO_GreaterGreater: return BO_Shr;
2183 case OO_LessLessEqual: return BO_ShlAssign;
2184 case OO_GreaterGreaterEqual: return BO_ShrAssign;
2185 case OO_EqualEqual: return BO_EQ;
2186 case OO_ExclaimEqual: return BO_NE;
2187 case OO_LessEqual: return BO_LE;
2188 case OO_GreaterEqual: return BO_GE;
2189 case OO_AmpAmp: return BO_LAnd;
2190 case OO_PipePipe: return BO_LOr;
2191 case OO_Comma: return BO_Comma;
2192 case OO_ArrowStar: return BO_PtrMemI;
2193 }
2194}
2195
2198 OO_None, OO_ArrowStar,
2199 OO_Star, OO_Slash, OO_Percent,
2200 OO_Plus, OO_Minus,
2201 OO_LessLess, OO_GreaterGreater,
2202 OO_Spaceship,
2203 OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual,
2204 OO_EqualEqual, OO_ExclaimEqual,
2205 OO_Amp,
2206 OO_Caret,
2207 OO_Pipe,
2208 OO_AmpAmp,
2209 OO_PipePipe,
2210 OO_Equal, OO_StarEqual,
2211 OO_SlashEqual, OO_PercentEqual,
2212 OO_PlusEqual, OO_MinusEqual,
2213 OO_LessLessEqual, OO_GreaterGreaterEqual,
2214 OO_AmpEqual, OO_CaretEqual,
2215 OO_PipeEqual,
2216 OO_Comma
2217 };
2218 return OverOps[Opc];
2219}
2220
2223 const Expr *LHS,
2224 const Expr *RHS) {
2225 if (Opc != BO_Add)
2226 return false;
2227
2228
2229 const Expr *PExp;
2232 return false;
2233 PExp = LHS;
2236 return false;
2237 PExp = RHS;
2238 } else {
2239 return false;
2240 }
2241
2242
2245 return false;
2246
2247
2250 return false;
2251
2252 return true;
2253}
2254
2260 BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext) {
2262
2264 ? ExprDependence::Value
2265 : ExprDependence::None);
2266}
2267
2271 return "__builtin_FILE";
2273 return "__builtin_FILE_NAME";
2275 return "__builtin_FUNCTION";
2277 return "__builtin_FUNCSIG";
2279 return "__builtin_LINE";
2281 return "__builtin_COLUMN";
2283 return "__builtin_source_location";
2284 }
2285 llvm_unreachable("unexpected IdentKind!");
2286}
2287
2289 const Expr *DefaultExpr) const {
2292
2293 if (const auto *DIE = dyn_cast_if_present(DefaultExpr)) {
2294 Loc = DIE->getUsedLocation();
2295 Context = DIE->getUsedContext();
2296 } else if (const auto *DAE =
2297 dyn_cast_if_present(DefaultExpr)) {
2298 Loc = DAE->getUsedLocation();
2299 Context = DAE->getUsedContext();
2300 } else {
2303 }
2304
2305
2306
2307
2308
2309
2310 if (const auto *D = dyn_cast(Context);
2312 Context = D->getParent()->getParent();
2313
2316
2317 auto MakeStringLiteral = [&](StringRef Tmp) {
2320
2321 LValuePathEntry Path[1] = {LValuePathEntry::ArrayIndex(0)};
2323 };
2324
2327
2328
2332 return MakeStringLiteral(FileName);
2333 }
2338 return MakeStringLiteral(Path);
2339 }
2342 const auto *CurDecl = dyn_cast(Context);
2346 return MakeStringLiteral(
2348 }
2354
2355
2356
2358 assert(ImplDecl);
2359
2360
2361
2362
2363
2366 StringRef Name = F->getName();
2367 if (Name == "_M_file_name") {
2371 Value.getStructField(F->getFieldIndex()) = MakeStringLiteral(Path);
2372 } else if (Name == "_M_function_name") {
2373
2374
2375 const auto *CurDecl = dyn_cast(Context);
2376 Value.getStructField(F->getFieldIndex()) = MakeStringLiteral(
2377 CurDecl && !isa(CurDecl)
2380 : "");
2381 } else if (Name == "_M_line") {
2383 Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
2384 } else if (Name == "_M_column") {
2386 Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
2387 }
2388 }
2389
2392
2394 false);
2395 }
2396 }
2397 llvm_unreachable("unhandled case");
2398}
2399
2402 unsigned NumOfElements)
2405 NumOfElements(NumOfElements) {
2409}
2410
2414 InitExprs(C, initExprs.size()), LBraceLoc(lbraceloc),
2415 RBraceLoc(rbraceloc), AltForm(nullptr, true) {
2417 InitExprs.insert(C, InitExprs.end(), initExprs.begin(), initExprs.end());
2418
2420}
2421
2423 if (NumInits > InitExprs.size())
2424 InitExprs.reserve(C, NumInits);
2425}
2426
2428 InitExprs.resize(C, NumInits, nullptr);
2429}
2430
2432 if (Init >= InitExprs.size()) {
2433 InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, nullptr);
2435 return nullptr;
2436 }
2437
2441}
2442
2445 ArrayFillerOrUnionFieldInit = filler;
2446
2448 for (unsigned i = 0, e = getNumInits(); i != e; ++i)
2449 if (inits[i] == nullptr)
2450 inits[i] = filler;
2451}
2452
2455 return false;
2458 return false;
2459
2462 return false;
2463 Init = Init->IgnoreParenImpCasts();
2464 return isa(Init) || isa(Init);
2465}
2466
2468 assert(isSemanticForm() && "syntactic form never semantically transparent");
2469
2470
2472 assert(getNumInits() == 1 && "multiple inits in glvalue init list");
2473 return true;
2474 }
2475
2476
2477
2479 return false;
2480
2481
2482
2484 return false;
2485
2488}
2489
2491 assert(isSyntacticForm() && "only test syntactic form as zero initializer");
2492
2494 return false;
2495 }
2496
2498 return Lit && Lit->getValue() == 0;
2499}
2500
2503 return SyntacticForm->getBeginLoc();
2506
2509 I != E; ++I) {
2510 if (Stmt *S = *I) {
2511 Beg = S->getBeginLoc();
2512 break;
2513 }
2514 }
2515 }
2516 return Beg;
2517}
2518
2521 return SyntacticForm->getEndLoc();
2523 if (End.isInvalid()) {
2524
2525 for (Stmt *S : llvm::reverse(InitExprs)) {
2526 if (S) {
2527 End = S->getEndLoc();
2528 break;
2529 }
2530 }
2531 }
2532 return End;
2533}
2534
2535
2536
2538
2539 return cast(getType())
2541}
2542
2545}
2548}
2551}
2552
2553
2554
2555
2556
2557
2559
2560
2561
2562
2563
2565 return false;
2566
2568
2569
2570 if (isa(E))
2571 return true;
2572
2573
2574 if (isa(E))
2575 return true;
2576
2577
2578 if (isa(E))
2579 return true;
2580
2581
2582 if (auto *UO = dyn_cast(E))
2583 if (UO->getOpcode() == UO_Deref)
2584 return true;
2585
2586 if (auto *BO = dyn_cast(E)) {
2587
2588 if (BO->isPtrMemOp())
2589 return true;
2590
2591
2592 if (BO->getOpcode() == BO_Comma)
2593 return BO->getRHS()->isReadIfDiscardedInCPlusPlus11();
2594 }
2595
2596
2597
2598 if (auto *CO = dyn_cast(E))
2599 return CO->getTrueExpr()->isReadIfDiscardedInCPlusPlus11() &&
2600 CO->getFalseExpr()->isReadIfDiscardedInCPlusPlus11();
2601
2602 if (auto *BCO =
2603 dyn_cast(E)) {
2604 if (auto *OVE = dyn_cast(BCO->getTrueExpr()))
2605 return OVE->getSourceExpr()->isReadIfDiscardedInCPlusPlus11() &&
2606 BCO->getFalseExpr()->isReadIfDiscardedInCPlusPlus11();
2607 }
2608
2609
2610 if (isa(E))
2611 return true;
2612 if (const auto *POE = dyn_cast(E)) {
2613 if (isa<ObjCPropertyRefExpr, ObjCSubscriptRefExpr>(POE->getSyntacticForm()))
2614 return true;
2615 }
2616
2617 return false;
2618}
2619
2620
2621
2622
2623
2627
2628
2630 return false;
2631
2633 default:
2634 if (getType()->isVoidType())
2635 return false;
2636 WarnE = this;
2639 return true;
2640 case ParenExprClass:
2641 return cast(this)->getSubExpr()->
2643 case GenericSelectionExprClass:
2644 return cast(this)->getResultExpr()->
2646 case CoawaitExprClass:
2647 case CoyieldExprClass:
2648 return cast(this)->getResumeExpr()->
2650 case ChooseExprClass:
2651 return cast(this)->getChosenSubExpr()->
2653 case UnaryOperatorClass: {
2654 const UnaryOperator *UO = cast(this);
2655
2657 case UO_Plus:
2658 case UO_Minus:
2659 case UO_AddrOf:
2660 case UO_Not:
2661 case UO_LNot:
2662 case UO_Deref:
2663 break;
2664 case UO_Coawait:
2665
2666
2667 case UO_PostInc:
2668 case UO_PostDec:
2669 case UO_PreInc:
2670 case UO_PreDec:
2671 return false;
2672 case UO_Real:
2673 case UO_Imag:
2674
2677 return false;
2678 break;
2679 case UO_Extension:
2681 }
2682 WarnE = this;
2685 return true;
2686 }
2687 case BinaryOperatorClass: {
2688 const BinaryOperator *BO = cast(this);
2690 default:
2691 break;
2692
2693
2694 case BO_Comma:
2695
2696
2699 if (IE->getValue() == 0)
2700 return false;
2702
2703 case BO_LAnd:
2704 case BO_LOr:
2707 return false;
2708 break;
2709 }
2711 return false;
2712 WarnE = this;
2716 return true;
2717 }
2718 case CompoundAssignOperatorClass:
2719 case VAArgExprClass:
2720 case AtomicExprClass:
2721 return false;
2722
2723 case ConditionalOperatorClass: {
2724
2725
2726
2727 const auto *Exp = cast(this);
2728 return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) &&
2729 Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2730 }
2731 case BinaryConditionalOperatorClass: {
2732 const auto *Exp = cast(this);
2733 return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2734 }
2735
2736 case MemberExprClass:
2737 WarnE = this;
2738 Loc = cast(this)->getMemberLoc();
2740 R2 = cast(this)->getBase()->getSourceRange();
2741 return true;
2742
2743 case ArraySubscriptExprClass:
2744 WarnE = this;
2745 Loc = cast(this)->getRBracketLoc();
2746 R1 = cast(this)->getLHS()->getSourceRange();
2747 R2 = cast(this)->getRHS()->getSourceRange();
2748 return true;
2749
2750 case CXXOperatorCallExprClass: {
2751
2752
2753
2754
2755
2756
2759 default:
2760 break;
2761 case OO_EqualEqual:
2762 case OO_ExclaimEqual:
2763 case OO_Less:
2764 case OO_Greater:
2765 case OO_GreaterEqual:
2766 case OO_LessEqual:
2769 break;
2770 WarnE = this;
2773 return true;
2774 }
2775
2776
2777 [[fallthrough]];
2778 }
2779 case CallExprClass:
2780 case CXXMemberCallExprClass:
2781 case UserDefinedLiteralClass: {
2782
2783 const CallExpr *CE = cast(this);
2785
2786
2787
2788
2789
2791 FD->hasAttr() || FD->hasAttr()) {
2792 WarnE = this;
2795
2796 if (unsigned NumArgs = CE->getNumArgs())
2799 return true;
2800 }
2801 }
2802 return false;
2803 }
2804
2805
2806 case UnresolvedLookupExprClass:
2807 case CXXUnresolvedConstructExprClass:
2808 case RecoveryExprClass:
2809 return false;
2810
2811 case CXXTemporaryObjectExprClass:
2812 case CXXConstructExprClass: {
2814 const auto *WarnURAttr = Type->getAttr();
2816 (WarnURAttr && WarnURAttr->IsCXX11NoDiscard())) {
2817 WarnE = this;
2820 return true;
2821 }
2822 }
2823
2824 const auto *CE = cast(this);
2826 const auto *WarnURAttr = Ctor->getAttr();
2827 if (WarnURAttr && WarnURAttr->IsCXX11NoDiscard()) {
2828 WarnE = this;
2831
2832 if (unsigned NumArgs = CE->getNumArgs())
2833 R2 = SourceRange(CE->getArg(0)->getBeginLoc(),
2834 CE->getArg(NumArgs - 1)->getEndLoc());
2835 return true;
2836 }
2837 }
2838
2839 return false;
2840 }
2841
2842 case ObjCMessageExprClass: {
2843 const ObjCMessageExpr *ME = cast(this);
2844 if (Ctx.getLangOpts().ObjCAutoRefCount &&
2848 WarnE = this;
2851 return true;
2852 }
2853
2855 if (MD->hasAttr()) {
2856 WarnE = this;
2858 return true;
2859 }
2860
2861 return false;
2862 }
2863
2864 case ObjCPropertyRefExprClass:
2865 case ObjCSubscriptRefExprClass:
2866 WarnE = this;
2869 return true;
2870
2871 case PseudoObjectExprClass: {
2872 const auto *POE = cast(this);
2873
2874
2875 if (isa<ObjCPropertyRefExpr, ObjCSubscriptRefExpr>(
2876 POE->getSyntacticForm())) {
2877 WarnE = this;
2880 return true;
2881 }
2882
2883
2884 if (auto *BO = dyn_cast(POE->getSyntacticForm()))
2885 if (BO->isAssignmentOp())
2886 return false;
2887 if (auto *UO = dyn_cast(POE->getSyntacticForm()))
2888 if (UO->isIncrementDecrementOp())
2889 return false;
2890
2891
2892 const Expr *Result = POE->getResultExpr();
2893 return Result && Result->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2894 }
2895
2896 case StmtExprClass: {
2897
2898
2899
2900
2901
2902 const CompoundStmt *CS = cast(this)->getSubStmt();
2904 if (const Expr *E = dyn_cast(CS->body_back()))
2907 if (const Expr *E = dyn_cast(Label->getSubStmt()))
2909 }
2910
2911 if (getType()->isVoidType())
2912 return false;
2913 WarnE = this;
2914 Loc = cast(this)->getLParenLoc();
2916 return true;
2917 }
2918 case CXXFunctionalCastExprClass:
2919 case CStyleCastExprClass: {
2920
2921
2922
2923
2924
2925
2926 const CastExpr *CE = cast(this);
2931
2932
2933 if (auto *DRE = dyn_cast(SubE))
2934 if (auto *VD = dyn_cast(DRE->getDecl()))
2935 if (!VD->isExternallyVisible())
2936 return false;
2937
2938
2939
2940
2942 return false;
2943
2945 }
2946 return false;
2947 }
2948
2949
2950
2951 if (CE->getCastKind() == CK_ConstructorConversion)
2954 return false;
2955
2956 WarnE = this;
2958 dyn_cast(this)) {
2959 Loc = CXXCE->getBeginLoc();
2960 R1 = CXXCE->getSubExpr()->getSourceRange();
2961 } else {
2962 const CStyleCastExpr *CStyleCE = cast(this);
2965 }
2966 return true;
2967 }
2968 case ImplicitCastExprClass: {
2969 const CastExpr *ICE = cast(this);
2970
2971
2972 if (ICE->getCastKind() == CK_LValueToRValue &&
2974 return false;
2975
2977 }
2978 case CXXDefaultArgExprClass:
2979 return (cast(this)
2981 case CXXDefaultInitExprClass:
2982 return (cast(this)
2984
2985 case CXXNewExprClass:
2986
2987
2988 case CXXDeleteExprClass:
2989 return false;
2990 case MaterializeTemporaryExprClass:
2991 return cast(this)
2992 ->getSubExpr()
2993 ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2994 case CXXBindTemporaryExprClass:
2995 return cast(this)->getSubExpr()
2996 ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
2997 case ExprWithCleanupsClass:
2998 return cast(this)->getSubExpr()
2999 ->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
3000 case OpaqueValueExprClass:
3001 return cast(this)->getSourceExpr()->isUnusedResultAWarning(
3002 WarnE, Loc, R1, R2, Ctx);
3003 }
3004}
3005
3006
3007
3011 default:
3012 return false;
3013 case ObjCIvarRefExprClass:
3014 return true;
3015 case Expr::UnaryOperatorClass:
3016 return cast(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
3017 case ImplicitCastExprClass:
3018 return cast(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
3019 case MaterializeTemporaryExprClass:
3020 return cast(E)->getSubExpr()->isOBJCGCCandidate(
3021 Ctx);
3022 case CStyleCastExprClass:
3023 return cast(E)->getSubExpr()->isOBJCGCCandidate(Ctx);
3024 case DeclRefExprClass: {
3025 const Decl *D = cast(E)->getDecl();
3026
3027 if (const VarDecl *VD = dyn_cast(D)) {
3028 if (VD->hasGlobalStorage())
3029 return true;
3031
3032
3035 }
3036 return false;
3037 }
3038 case MemberExprClass: {
3039 const MemberExpr *M = cast(E);
3041 }
3042 case ArraySubscriptExprClass:
3043 return cast(E)->getBase()->isOBJCGCCandidate(Ctx);
3044 }
3045}
3046
3049 return false;
3051}
3052
3054 assert(expr->hasPlaceholderType(BuiltinType::BoundMember));
3055
3056
3057
3058
3059
3060 expr = expr->IgnoreParens();
3061 if (const MemberExpr *mem = dyn_cast(expr)) {
3062 assert(isa(mem->getMemberDecl()));
3063 return mem->getMemberDecl()->getType();
3064 }
3065
3069 assert(type->isFunctionType());
3070 return type;
3071 }
3072
3073 assert(isa(expr) || isa(expr));
3075}
3076
3079}
3080
3083}
3084
3087}
3088
3091}
3092
3095}
3096
3100}
3101
3104}
3105
3107 if (auto *MCE = dyn_cast(this)) {
3108 if (isa_and_nonnull(MCE->getMethodDecl()))
3109 return MCE->getImplicitObjectArgument();
3110 }
3111 return this;
3112}
3113
3117}
3118
3122}
3123
3125 auto IgnoreNoopCastsSingleStep = [&Ctx](Expr *E) {
3126 if (auto *CE = dyn_cast(E)) {
3127
3128
3129 Expr *SubExpr = CE->getSubExpr();
3130 bool IsIdentityCast =
3138
3139 if (IsIdentityCast || IsSameWidthCast)
3140 return SubExpr;
3141 } else if (auto *NTTP = dyn_cast(E))
3142 return NTTP->getReplacement();
3143
3144 return E;
3145 };
3147 IgnoreNoopCastsSingleStep);
3148}
3149
3152 if (auto *Cast = dyn_cast(E)) {
3153 auto *SE = Cast->getSubExpr();
3155 return SE;
3156 }
3157
3158 if (auto *C = dyn_cast(E)) {
3159 auto NumArgs = C->getNumArgs();
3160 if (NumArgs == 1 ||
3161 (NumArgs > 1 && isa(C->getArg(1)))) {
3164 return A;
3165 }
3166 }
3167 return E;
3168 };
3169 auto IgnoreImplicitMemberCallSingleStep = [](Expr *E) {
3170 if (auto *C = dyn_cast(E)) {
3171 Expr *ExprNode = C->getImplicitObjectArgument();
3173 return ExprNode;
3174 }
3175 if (auto *PE = dyn_cast(ExprNode)) {
3176 if (PE->getSourceRange() == C->getSourceRange()) {
3177 return cast(PE);
3178 }
3179 }
3182 return ExprNode;
3183 }
3184 return E;
3185 };
3189 IgnoreImplicitMemberCallSingleStep);
3190}
3191
3195 E = M->getSubExpr();
3196
3197 while (const ImplicitCastExpr *ICE = dyn_cast(E))
3198 E = ICE->getSubExprAsWritten();
3199
3200 return isa(E);
3201}
3202
3203
3204
3207 E = M->getSubExpr();
3208
3209 while (const ImplicitCastExpr *ICE = dyn_cast(E)) {
3210 if (ICE->getCastKind() == CK_NoOp)
3211 E = ICE->getSubExpr();
3212 else
3213 break;
3214 }
3215
3217 E = BE->getSubExpr();
3218
3219 while (const ImplicitCastExpr *ICE = dyn_cast(E)) {
3220 if (ICE->getCastKind() == CK_NoOp)
3221 E = ICE->getSubExpr();
3222 else
3223 break;
3224 }
3225
3227}
3228
3229
3230
3232 if (.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy)))
3233 return false;
3234
3236
3237
3239
3240 if (!isa(E))
3241 return false;
3242 }
3243
3244
3245
3246
3247
3248 if (isa(E)) {
3249 switch (cast(E)->getCastKind()) {
3250 case CK_DerivedToBase:
3251 case CK_UncheckedDerivedToBase:
3252 return false;
3253 default:
3254 break;
3255 }
3256 }
3257
3258
3259 if (isa(E))
3260 return false;
3261
3262 if (const BinaryOperator *BO = dyn_cast(E))
3263 if (BO->isPtrMemOp())
3264 return false;
3265
3266
3267 if (isa(E))
3268 return false;
3269
3270 return true;
3271}
3272
3275
3276
3277 while (true) {
3280 continue;
3281 }
3282
3283 if (const ImplicitCastExpr *ICE = dyn_cast(E)) {
3284 if (ICE->getCastKind() == CK_NoOp ||
3285 ICE->getCastKind() == CK_LValueToRValue ||
3286 ICE->getCastKind() == CK_DerivedToBase ||
3287 ICE->getCastKind() == CK_UncheckedDerivedToBase) {
3288 E = ICE->getSubExpr();
3289 continue;
3290 }
3291 }
3292
3293 if (const UnaryOperator* UnOp = dyn_cast(E)) {
3294 if (UnOp->getOpcode() == UO_Extension) {
3295 E = UnOp->getSubExpr();
3296 continue;
3297 }
3298 }
3299
3301 = dyn_cast(E)) {
3302 E = M->getSubExpr();
3303 continue;
3304 }
3305
3306 break;
3307 }
3308
3309 if (const CXXThisExpr *This = dyn_cast(E))
3310 return This->isImplicit();
3311
3312 return false;
3313}
3314
3315
3316
3318 for (unsigned I = 0; I < Exprs.size(); ++I)
3320 return true;
3321
3322 return false;
3323}
3324
3326 const Expr **Culprit) const {
3328 "Expression evaluator can't be called on a dependent expression.");
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339 if (IsForRef) {
3340 if (auto *EWC = dyn_cast(this))
3341 return EWC->getSubExpr()->isConstantInitializer(Ctx, true, Culprit);
3342 if (auto *MTE = dyn_cast(this))
3343 return MTE->getSubExpr()->isConstantInitializer(Ctx, false, Culprit);
3346 return true;
3347 if (Culprit)
3348 *Culprit = this;
3349 return false;
3350 }
3351
3353 default: break;
3354 case Stmt::ExprWithCleanupsClass:
3356 Ctx, IsForRef, Culprit);
3357 case StringLiteralClass:
3358 case ObjCEncodeExprClass:
3359 return true;
3360 case CXXTemporaryObjectExprClass:
3361 case CXXConstructExprClass: {
3363
3366
3368
3369
3370 assert(CE->getNumArgs() == 1 && "trivial ctor with > 1 argument");
3372 }
3373
3374 break;
3375 }
3376 case ConstantExprClass: {
3377
3378
3379 const Expr *Exp = cast(this)->getSubExpr();
3381 }
3382 case CompoundLiteralExprClass: {
3383
3384
3385
3386 const Expr *Exp = cast(this)->getInitializer();
3388 }
3389 case DesignatedInitUpdateExprClass: {
3393 }
3394 case InitListExprClass: {
3395
3396
3397
3398
3399
3400
3401 const InitListExpr *ILE = cast(this);
3402 assert(ILE->isSemanticForm() && "InitListExpr must be in semantic form");
3405 for (unsigned i = 0; i < numInits; i++) {
3407 return false;
3408 }
3409 return true;
3410 }
3411
3413 unsigned ElementNo = 0;
3415
3416
3417
3418 if (const auto *CXXRD = dyn_cast(RD)) {
3419 for (unsigned i = 0, e = CXXRD->getNumBases(); i < e; i++) {
3420 if (ElementNo < ILE->getNumInits()) {
3421 const Expr *Elt = ILE->getInit(ElementNo++);
3423 return false;
3424 }
3425 }
3426 }
3427
3428 for (const auto *Field : RD->fields()) {
3429
3431 continue;
3432
3433
3434 if (Field->isUnnamedBitField())
3435 continue;
3436
3437 if (ElementNo < ILE->getNumInits()) {
3438 const Expr *Elt = ILE->getInit(ElementNo++);
3439 if (Field->isBitField()) {
3440
3443 if (Culprit)
3444 *Culprit = Elt;
3445 return false;
3446 }
3447 } else {
3448 bool RefType = Field->getType()->isReferenceType();
3450 return false;
3451 }
3452 }
3453 }
3454 return true;
3455 }
3456
3457 break;
3458 }
3459 case ImplicitValueInitExprClass:
3460 case NoInitExprClass:
3461 return true;
3462 case ParenExprClass:
3463 return cast(this)->getSubExpr()
3464 ->isConstantInitializer(Ctx, IsForRef, Culprit);
3465 case GenericSelectionExprClass:
3466 return cast(this)->getResultExpr()
3467 ->isConstantInitializer(Ctx, IsForRef, Culprit);
3468 case ChooseExprClass:
3469 if (cast(this)->isConditionDependent()) {
3470 if (Culprit)
3471 *Culprit = this;
3472 return false;
3473 }
3474 return cast(this)->getChosenSubExpr()
3476 case UnaryOperatorClass: {
3477 const UnaryOperator* Exp = cast(this);
3478 if (Exp->getOpcode() == UO_Extension)
3480 break;
3481 }
3482 case PackIndexingExprClass: {
3483 return cast(this)
3484 ->getSelectedExpr()
3485 ->isConstantInitializer(Ctx, false, Culprit);
3486 }
3487 case CXXFunctionalCastExprClass:
3488 case CXXStaticCastExprClass:
3489 case ImplicitCastExprClass:
3490 case CStyleCastExprClass:
3491 case ObjCBridgedCastExprClass:
3492 case CXXDynamicCastExprClass:
3493 case CXXReinterpretCastExprClass:
3494 case CXXAddrspaceCastExprClass:
3495 case CXXConstCastExprClass: {
3496 const CastExpr *CE = cast(this);
3497
3498
3500 CE->getCastKind() == CK_LValueToRValue ||
3502 CE->getCastKind() == CK_ConstructorConversion ||
3503 CE->getCastKind() == CK_NonAtomicToAtomic ||
3504 CE->getCastKind() == CK_AtomicToNonAtomic ||
3505 CE->getCastKind() == CK_NullToPointer ||
3506 CE->getCastKind() == CK_IntToOCLSampler)
3508
3509 break;
3510 }
3511 case MaterializeTemporaryExprClass:
3512 return cast(this)
3513 ->getSubExpr()
3514 ->isConstantInitializer(Ctx, false, Culprit);
3515
3516 case SubstNonTypeTemplateParmExprClass:
3517 return cast(this)->getReplacement()
3518 ->isConstantInitializer(Ctx, false, Culprit);
3519 case CXXDefaultArgExprClass:
3520 return cast(this)->getExpr()
3521 ->isConstantInitializer(Ctx, false, Culprit);
3522 case CXXDefaultInitExprClass:
3523 return cast(this)->getExpr()
3524 ->isConstantInitializer(Ctx, false, Culprit);
3525 }
3526
3527
3528
3530 return true;
3531 if (Culprit)
3532 *Culprit = this;
3533 return false;
3534}
3535
3538 if (BuiltinID != Builtin::BI__assume &&
3539 BuiltinID != Builtin::BI__builtin_assume)
3540 return false;
3541
3543 bool ArgVal;
3546}
3547
3550}
3551
3552namespace {
3553
3556 const bool IncludePossibleEffects;
3557 bool HasSideEffects;
3558
3559 public:
3560 explicit SideEffectFinder(const ASTContext &Context, bool IncludePossible)
3561 : Inherited(Context),
3562 IncludePossibleEffects(IncludePossible), HasSideEffects(false) { }
3563
3564 bool hasSideEffects() const { return HasSideEffects; }
3565
3566 void VisitDecl(const Decl *D) {
3567 if ()
3568 return;
3569
3570
3571
3572 if (auto *VD = dyn_cast(D)) {
3573
3574 if (IncludePossibleEffects && VD->isThisDeclarationADefinition() &&
3575 VD->needsDestruction(Context))
3576 HasSideEffects = true;
3577 }
3578 }
3579
3580 void VisitDeclStmt(const DeclStmt *DS) {
3581 for (auto *D : DS->decls())
3582 VisitDecl(D);
3583 Inherited::VisitDeclStmt(DS);
3584 }
3585
3586 void VisitExpr(const Expr *E) {
3587 if (!HasSideEffects &&
3589 HasSideEffects = true;
3590 }
3591 };
3592}
3593
3595 bool IncludePossibleEffects) const {
3596
3597
3598
3599 if (!IncludePossibleEffects && getExprLoc().isMacroID())
3600 return false;
3601
3604 #define ABSTRACT_STMT(Type)
3605 #define STMT(Type, Base) case Type##Class:
3606 #define EXPR(Type, Base)
3607 #include "clang/AST/StmtNodes.inc"
3608 llvm_unreachable("unexpected Expr kind");
3609
3610 case DependentScopeDeclRefExprClass:
3611 case CXXUnresolvedConstructExprClass:
3612 case CXXDependentScopeMemberExprClass:
3613 case UnresolvedLookupExprClass:
3614 case UnresolvedMemberExprClass:
3615 case PackExpansionExprClass:
3616 case SubstNonTypeTemplateParmPackExprClass:
3617 case FunctionParmPackExprClass:
3618 case TypoExprClass:
3619 case RecoveryExprClass:
3620 case CXXFoldExprClass:
3621
3622 return IncludePossibleEffects;
3623
3624 case DeclRefExprClass:
3625 case ObjCIvarRefExprClass:
3626 case PredefinedExprClass:
3627 case IntegerLiteralClass:
3628 case FixedPointLiteralClass:
3629 case FloatingLiteralClass:
3630 case ImaginaryLiteralClass:
3631 case StringLiteralClass:
3632 case CharacterLiteralClass:
3633 case OffsetOfExprClass:
3634 case ImplicitValueInitExprClass:
3635 case UnaryExprOrTypeTraitExprClass:
3636 case AddrLabelExprClass:
3637 case GNUNullExprClass:
3638 case ArrayInitIndexExprClass:
3639 case NoInitExprClass:
3640 case CXXBoolLiteralExprClass:
3641 case CXXNullPtrLiteralExprClass:
3642 case CXXThisExprClass:
3643 case CXXScalarValueInitExprClass:
3644 case TypeTraitExprClass:
3645 case ArrayTypeTraitExprClass:
3646 case ExpressionTraitExprClass:
3647 case CXXNoexceptExprClass:
3648 case SizeOfPackExprClass:
3649 case ObjCStringLiteralClass:
3650 case ObjCEncodeExprClass:
3651 case ObjCBoolLiteralExprClass:
3652 case ObjCAvailabilityCheckExprClass:
3653 case CXXUuidofExprClass:
3654 case OpaqueValueExprClass:
3655 case SourceLocExprClass:
3656 case EmbedExprClass:
3657 case ConceptSpecializationExprClass:
3658 case RequiresExprClass:
3659 case SYCLUniqueStableNameExprClass:
3660 case PackIndexingExprClass:
3661 case HLSLOutArgExprClass:
3662 case OpenACCAsteriskSizeExprClass:
3663
3664 return false;
3665
3666 case ConstantExprClass:
3667
3668 return cast(this)->getSubExpr()->HasSideEffects(
3669 Ctx, IncludePossibleEffects);
3670
3671 case CallExprClass:
3672 case CXXOperatorCallExprClass:
3673 case CXXMemberCallExprClass:
3674 case CUDAKernelCallExprClass:
3675 case UserDefinedLiteralClass: {
3676
3677
3678
3679 const Decl *FD = cast(this)->getCalleeDecl();
3680 bool IsPure = FD && (FD->hasAttr() || FD->hasAttr());
3681 if (IsPure || !IncludePossibleEffects)
3682 break;
3683 return true;
3684 }
3685
3686 case BlockExprClass:
3687 case CXXBindTemporaryExprClass:
3688 if (!IncludePossibleEffects)
3689 break;
3690 return true;
3691
3692 case MSPropertyRefExprClass:
3693 case MSPropertySubscriptExprClass:
3694 case CompoundAssignOperatorClass:
3695 case VAArgExprClass:
3696 case AtomicExprClass:
3697 case CXXThrowExprClass:
3698 case CXXNewExprClass:
3699 case CXXDeleteExprClass:
3700 case CoawaitExprClass:
3701 case DependentCoawaitExprClass:
3702 case CoyieldExprClass:
3703
3704 return true;
3705
3706 case StmtExprClass: {
3707
3708 SideEffectFinder Finder(Ctx, IncludePossibleEffects);
3709 Finder.Visit(cast(this)->getSubStmt());
3710 return Finder.hasSideEffects();
3711 }
3712
3713 case ExprWithCleanupsClass:
3714 if (IncludePossibleEffects)
3715 if (cast(this)->cleanupsHaveSideEffects())
3716 return true;
3717 break;
3718
3719 case ParenExprClass:
3720 case ArraySubscriptExprClass:
3721 case MatrixSubscriptExprClass:
3722 case ArraySectionExprClass:
3723 case OMPArrayShapingExprClass:
3724 case OMPIteratorExprClass:
3725 case MemberExprClass:
3726 case ConditionalOperatorClass:
3727 case BinaryConditionalOperatorClass:
3728 case CompoundLiteralExprClass:
3729 case ExtVectorElementExprClass:
3730 case DesignatedInitExprClass:
3731 case DesignatedInitUpdateExprClass:
3732 case ArrayInitLoopExprClass:
3733 case ParenListExprClass:
3734 case CXXPseudoDestructorExprClass:
3735 case CXXRewrittenBinaryOperatorClass:
3736 case CXXStdInitializerListExprClass:
3737 case SubstNonTypeTemplateParmExprClass:
3738 case MaterializeTemporaryExprClass:
3739 case ShuffleVectorExprClass:
3740 case ConvertVectorExprClass:
3741 case AsTypeExprClass:
3742 case CXXParenListInitExprClass:
3743
3744 break;
3745
3746 case UnaryOperatorClass:
3747 if (cast(this)->isIncrementDecrementOp())
3748 return true;
3749 break;
3750
3751 case BinaryOperatorClass:
3752 if (cast(this)->isAssignmentOp())
3753 return true;
3754 break;
3755
3756 case InitListExprClass:
3757
3758 if (const Expr *E = cast(this)->getArrayFiller())
3760 return true;
3761 break;
3762
3763 case GenericSelectionExprClass:
3764 return cast(this)->getResultExpr()->
3766
3767 case ChooseExprClass:
3768 return cast(this)->getChosenSubExpr()->HasSideEffects(
3769 Ctx, IncludePossibleEffects);
3770
3771 case CXXDefaultArgExprClass:
3772 return cast(this)->getExpr()->HasSideEffects(
3773 Ctx, IncludePossibleEffects);
3774
3775 case CXXDefaultInitExprClass: {
3776 const FieldDecl *FD = cast(this)->getField();
3779
3780 return true;
3781 }
3782
3783 case CXXDynamicCastExprClass: {
3784
3788 return true;
3789 }
3790 [[fallthrough]];
3791 case ImplicitCastExprClass:
3792 case CStyleCastExprClass:
3793 case CXXStaticCastExprClass:
3794 case CXXReinterpretCastExprClass:
3795 case CXXConstCastExprClass:
3796 case CXXAddrspaceCastExprClass:
3797 case CXXFunctionalCastExprClass:
3798 case BuiltinBitCastExprClass: {
3799
3800
3801
3802
3803 if (!IncludePossibleEffects)
3804 break;
3805
3806 const CastExpr *CE = cast(this);
3807 if (CE->getCastKind() == CK_LValueToRValue &&
3809 return true;
3810 break;
3811 }
3812
3813 case CXXTypeidExprClass: {
3814 const auto *TE = cast(this);
3815 if (!TE->isPotentiallyEvaluated())
3816 return false;
3817
3818
3819
3820 if (IncludePossibleEffects && TE->hasNullCheck())
3821 return true;
3822
3823 break;
3824 }
3825
3826 case CXXConstructExprClass:
3827 case CXXTemporaryObjectExprClass: {
3830 return true;
3831
3832
3833 break;
3834 }
3835
3836 case CXXInheritedCtorInitExprClass: {
3837 const auto *ICIE = cast(this);
3838 if (!ICIE->getConstructor()->isTrivial() && IncludePossibleEffects)
3839 return true;
3840 break;
3841 }
3842
3843 case LambdaExprClass: {
3844 const LambdaExpr *LE = cast(this);
3845 for (Expr *E : LE->capture_inits())
3847 return true;
3848 return false;
3849 }
3850
3851 case PseudoObjectExprClass: {
3852
3853
3857 I != E; ++I) {
3858 const Expr *Subexpr = *I;
3859 if (const OpaqueValueExpr *OVE = dyn_cast(Subexpr))
3860 Subexpr = OVE->getSourceExpr();
3861 if (Subexpr->HasSideEffects(Ctx, IncludePossibleEffects))
3862 return true;
3863 }
3864 return false;
3865 }
3866
3867 case ObjCBoxedExprClass:
3868 case ObjCArrayLiteralClass:
3869 case ObjCDictionaryLiteralClass:
3870 case ObjCSelectorExprClass:
3871 case ObjCProtocolExprClass:
3872 case ObjCIsaExprClass:
3873 case ObjCIndirectCopyRestoreExprClass:
3874 case ObjCSubscriptRefExprClass:
3875 case ObjCBridgedCastExprClass:
3876 case ObjCMessageExprClass:
3877 case ObjCPropertyRefExprClass:
3878
3879 if (IncludePossibleEffects)
3880 return true;
3881 break;
3882 }
3883
3884
3886 if (SubStmt &&
3887 cast(SubStmt)->HasSideEffects(Ctx, IncludePossibleEffects))
3888 return true;
3889
3890 return false;
3891}
3892
3894 if (auto Call = dyn_cast(this))
3895 return Call->getFPFeaturesInEffect(LO);
3896 if (auto UO = dyn_cast(this))
3897 return UO->getFPFeaturesInEffect(LO);
3898 if (auto BO = dyn_cast(this))
3899 return BO->getFPFeaturesInEffect(LO);
3900 if (auto Cast = dyn_cast(this))
3901 return Cast->getFPFeaturesInEffect(LO);
3903}
3904
3905namespace {
3906
3908 {
3910
3911 bool NonTrivial;
3912
3913 public:
3914 explicit NonTrivialCallFinder(const ASTContext &Context)
3915 : Inherited(Context), NonTrivial(false) { }
3916
3917 bool hasNonTrivialCall() const { return NonTrivial; }
3918
3919 void VisitCallExpr(const CallExpr *E) {
3921 = dyn_cast_or_null(E->getCalleeDecl())) {
3922 if (Method->isTrivial()) {
3923
3924 Inherited::VisitStmt(E);
3925 return;
3926 }
3927 }
3928
3929 NonTrivial = true;
3930 }
3931
3933 if (E->getConstructor()->isTrivial()) {
3934
3935 Inherited::VisitStmt(E);
3936 return;
3937 }
3938
3939 NonTrivial = true;
3940 }
3941
3943
3944
3946 E->getTemporary()->getDestructor()) {
3947 if (DtorDecl->isTrivial()) {
3948 Inherited::VisitStmt(E);
3949 return;
3950 }
3951 }
3952
3953 NonTrivial = true;
3954 }
3955 };
3956}
3957
3959 NonTrivialCallFinder Finder(Ctx);
3960 Finder.Visit(this);
3961 return Finder.hasNonTrivialCall();
3962}
3963
3964
3965
3966
3967
3968
3974
3977 switch (NPC) {
3979 llvm_unreachable("Unexpected value dependent expression!");
3983 else
3985
3988 }
3989 }
3990
3991
3992 if (const ExplicitCastExpr *CE = dyn_cast(this)) {
3994
3998
3999
4000
4001
4005
4007 CE->getSubExpr()->getType()->isIntegerType())
4008 return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
4009 }
4010 }
4011 } else if (const ImplicitCastExpr *ICE = dyn_cast(this)) {
4012
4013 return ICE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
4014 } else if (const ParenExpr *PE = dyn_cast(this)) {
4015
4016
4017 return PE->getSubExpr()->isNullPointerConstant(Ctx, NPC);
4019 dyn_cast(this)) {
4020 if (GE->isResultDependent())
4022 return GE->getResultExpr()->isNullPointerConstant(Ctx, NPC);
4023 } else if (const ChooseExpr *CE = dyn_cast(this)) {
4024 if (CE->isConditionDependent())
4026 return CE->getChosenSubExpr()->isNullPointerConstant(Ctx, NPC);
4028 = dyn_cast(this)) {
4029
4030 return DefaultArg->getExpr()->isNullPointerConstant(Ctx, NPC);
4032 = dyn_cast(this)) {
4033
4034 return DefaultInit->getExpr()->isNullPointerConstant(Ctx, NPC);
4035 } else if (isa(this)) {
4036
4039 = dyn_cast(this)) {
4040 return M->getSubExpr()->isNullPointerConstant(Ctx, NPC);
4041 } else if (const OpaqueValueExpr *OVE = dyn_cast(this)) {
4042 if (const Expr *Source = OVE->getSourceExpr())
4043 return Source->isNullPointerConstant(Ctx, NPC);
4044 }
4045
4046
4047
4050
4051
4052 if (getType()->isNullPtrType())
4054
4057 UT && UT->getDecl()->hasAttr())
4058 if (const CompoundLiteralExpr *CLE = dyn_cast(this)){
4059 const Expr *InitExpr = CLE->getInitializer();
4060 if (const InitListExpr *ILE = dyn_cast(InitExpr))
4062 }
4063
4064 if (()->isIntegerType() ||
4067
4069
4070
4071
4072 const IntegerLiteral *Lit = dyn_cast(this);
4073 if (Lit && !Lit->getValue())
4077 } else {
4078
4079
4082 }
4083
4086
4087 if (isa(this))
4090}
4091
4092
4093
4096 while (true) {
4098 "expression is not a property reference");
4100 if (const BinaryOperator *BO = dyn_cast(E)) {
4101 if (BO->getOpcode() == BO_Comma) {
4102 E = BO->getRHS();
4103 continue;
4104 }
4105 }
4106
4107 break;
4108 }
4109
4110 return cast(E);
4111}
4112
4115
4116 const DeclRefExpr *DRE = dyn_cast(E);
4117 if (!DRE)
4118 return false;
4119
4121 if (!Param)
4122 return false;
4123
4125 if (!M)
4126 return false;
4127
4129}
4130
4133
4135 if (ICE->getCastKind() == CK_LValueToRValue ||
4136 (ICE->isGLValue() && ICE->getCastKind() == CK_NoOp))
4138 else
4139 break;
4140 }
4141
4142 if (MemberExpr *MemRef = dyn_cast(E))
4143 if (FieldDecl *Field = dyn_cast(MemRef->getMemberDecl()))
4144 if (Field->isBitField())
4145 return Field;
4146
4147 if (ObjCIvarRefExpr *IvarRef = dyn_cast(E)) {
4148 FieldDecl *Ivar = IvarRef->getDecl();
4150 return Ivar;
4151 }
4152
4153 if (DeclRefExpr *DeclRef = dyn_cast(E)) {
4154 if (FieldDecl *Field = dyn_cast(DeclRef->getDecl()))
4155 if (Field->isBitField())
4156 return Field;
4157
4158 if (BindingDecl *BD = dyn_cast(DeclRef->getDecl()))
4159 if (Expr *E = BD->getBinding())
4161 }
4162
4163 if (BinaryOperator *BinOp = dyn_cast(E)) {
4164 if (BinOp->isAssignmentOp() && BinOp->getLHS())
4165 return BinOp->getLHS()->getSourceBitField();
4166
4167 if (BinOp->getOpcode() == BO_Comma && BinOp->getRHS())
4168 return BinOp->getRHS()->getSourceBitField();
4169 }
4170
4171 if (UnaryOperator *UnOp = dyn_cast(E))
4172 if (UnOp->isPrefix() && UnOp->isIncrementDecrementOp())
4173 return UnOp->getSubExpr()->getSourceBitField();
4174
4175 return nullptr;
4176}
4177
4180 if (auto *DRE = dyn_cast(E))
4181 return dyn_cast(DRE->getDecl());
4182 return nullptr;
4183}
4184
4186
4188
4189 while (const ImplicitCastExpr *ICE = dyn_cast(E)) {
4190 if (ICE->isGLValue() && ICE->getCastKind() == CK_NoOp)
4192 else
4193 break;
4194 }
4195
4198
4199 if (isa(E))
4200 return true;
4201
4202 if (auto *DRE = dyn_cast(E))
4203 if (auto *BD = dyn_cast(DRE->getDecl()))
4204 if (auto *E = BD->getBinding())
4206
4207 return false;
4208}
4209
4212
4213 if (const DeclRefExpr *DRE = dyn_cast(E))
4214 if (const auto *VD = dyn_cast(DRE->getDecl()))
4215 if (VD->getStorageClass() == SC_Register &&
4216 VD->hasAttr() && !VD->isLocalVarDecl())
4217 return true;
4218
4219 return false;
4220}
4221
4225
4227 return false;
4228
4230 default:
4231 return false;
4232 case CXXThisExprClass:
4233 return true;
4234 case DeclRefExprClass: {
4235
4236
4237 const auto *DRE1 = cast(E1);
4238 const auto *DRE2 = cast(E2);
4239 return DRE1->isPRValue() && DRE2->isPRValue() &&
4240 DRE1->getDecl() == DRE2->getDecl();
4241 }
4242 case ImplicitCastExprClass: {
4243
4244 while (true) {
4245 const auto *ICE1 = dyn_cast(E1);
4246 const auto *ICE2 = dyn_cast(E2);
4247 if (!ICE1 || !ICE2)
4248 return false;
4249 if (ICE1->getCastKind() != ICE2->getCastKind())
4250 return false;
4253
4254 if (ICE1->getCastKind() == CK_LValueToRValue ||
4255 ICE1->getCastKind() == CK_ArrayToPointerDecay ||
4256 ICE1->getCastKind() == CK_FunctionToPointerDecay) {
4257 break;
4258 }
4259 }
4260
4261 const auto *DRE1 = dyn_cast(E1);
4262 const auto *DRE2 = dyn_cast(E2);
4263 if (DRE1 && DRE2)
4265
4266 const auto *Ivar1 = dyn_cast(E1);
4267 const auto *Ivar2 = dyn_cast(E2);
4268 if (Ivar1 && Ivar2) {
4269 return Ivar1->isFreeIvar() && Ivar2->isFreeIvar() &&
4271 }
4272
4273 const auto *Array1 = dyn_cast(E1);
4274 const auto *Array2 = dyn_cast(E2);
4275 if (Array1 && Array2) {
4277 return false;
4278
4279 auto Idx1 = Array1->getIdx();
4280 auto Idx2 = Array2->getIdx();
4281 const auto Integer1 = dyn_cast(Idx1);
4282 const auto Integer2 = dyn_cast(Idx2);
4283 if (Integer1 && Integer2) {
4284 if (!llvm::APInt::isSameValue(Integer1->getValue(),
4285 Integer2->getValue()))
4286 return false;
4287 } else {
4289 return false;
4290 }
4291
4292 return true;
4293 }
4294
4295
4296 while (isa(E1) && isa(E2)) {
4297 const auto *ME1 = cast(E1);
4298 const auto *ME2 = cast(E2);
4299 if ((ME1->getMemberDecl(), ME2->getMemberDecl()))
4300 return false;
4301 if (const auto *D = dyn_cast(ME1->getMemberDecl()))
4302 if (D->isStaticDataMember())
4303 return true;
4306 }
4307
4308 if (isa(E1) && isa(E2))
4309 return true;
4310
4311
4312
4313 auto getAnyDecl = [](const Expr *E) -> const ValueDecl * {
4314 if (const auto *DRE = dyn_cast(E))
4315 return DRE->getDecl();
4316 if (const auto *ME = dyn_cast(E))
4317 return ME->getMemberDecl();
4318 return nullptr;
4319 };
4320
4321 const ValueDecl *VD1 = getAnyDecl(E1);
4322 const ValueDecl *VD2 = getAnyDecl(E2);
4324 }
4325 }
4326}
4327
4328
4329
4332}
4333
4336 return VT->getNumElements();
4337 return 1;
4338}
4339
4340
4342
4343
4344 StringRef Comp = Accessor->getName();
4345
4346
4347 if (Comp == "hi" || Comp == "lo" || Comp == "even" || Comp == "odd")
4348 return false;
4349
4350
4351 if (Comp[0] == 's' || Comp[0] == 'S')
4352 Comp = Comp.substr(1);
4353
4354 for (unsigned i = 0, e = Comp.size(); i != e; ++i)
4355 if (Comp.substr(i + 1).contains(Comp[i]))
4356 return true;
4357
4358 return false;
4359}
4360
4361
4364 StringRef Comp = Accessor->getName();
4365 bool isNumericAccessor = false;
4366 if (Comp[0] == 's' || Comp[0] == 'S') {
4367 Comp = Comp.substr(1);
4368 isNumericAccessor = true;
4369 }
4370
4371 bool isHi = Comp == "hi";
4372 bool isLo = Comp == "lo";
4373 bool isEven = Comp == "even";
4374 bool isOdd = Comp == "odd";
4375
4376 for (unsigned i = 0, e = getNumElements(); i != e; ++i) {
4377 uint64_t Index;
4378
4379 if (isHi)
4380 Index = e + i;
4381 else if (isLo)
4382 Index = i;
4383 else if (isEven)
4384 Index = 2 * i;
4385 else if (isOdd)
4386 Index = 2 * i + 1;
4387 else
4389
4390 Elts.push_back(Index);
4391 }
4392}
4393
4398 BuiltinLoc(BLoc), RParenLoc(RP), NumExprs(args.size()) {
4399 SubExprs = new (C) Stmt*[args.size()];
4400 for (unsigned i = 0; i != args.size(); i++)
4401 SubExprs[i] = args[i];
4402
4404}
4405
4407 if (SubExprs) C.Deallocate(SubExprs);
4408
4409 this->NumExprs = Exprs.size();
4410 SubExprs = new (C) Stmt*[NumExprs];
4411 memcpy(SubExprs, Exprs.data(), sizeof(Expr *) * Exprs.size());
4412}
4413
4414GenericSelectionExpr::GenericSelectionExpr(
4418 bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
4419 : Expr(GenericSelectionExprClass, AssocExprs[ResultIndex]->getType(),
4420 AssocExprs[ResultIndex]->getValueKind(),
4421 AssocExprs[ResultIndex]->getObjectKind()),
4422 NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex),
4423 IsExprPredicate(true), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4424 assert(AssocTypes.size() == AssocExprs.size() &&
4425 "Must have the same number of association expressions"
4426 " and TypeSourceInfo!");
4427 assert(ResultIndex < NumAssocs && "ResultIndex is out-of-bounds!");
4428
4430 getTrailingObjects<Stmt *>()[getIndexOfControllingExpression()] =
4431 ControllingExpr;
4432 std::copy(AssocExprs.begin(), AssocExprs.end(),
4433 getTrailingObjects<Stmt *>() + getIndexOfStartOfAssociatedExprs());
4434 std::copy(AssocTypes.begin(), AssocTypes.end(),
4435 getTrailingObjects<TypeSourceInfo *>() +
4436 getIndexOfStartOfAssociatedTypes());
4437
4439}
4440
4441GenericSelectionExpr::GenericSelectionExpr(
4445 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack,
4446 unsigned ResultIndex)
4447 : Expr(GenericSelectionExprClass, AssocExprs[ResultIndex]->getType(),
4448 AssocExprs[ResultIndex]->getValueKind(),
4449 AssocExprs[ResultIndex]->getObjectKind()),
4450 NumAssocs(AssocExprs.size()), ResultIndex(ResultIndex),
4451 IsExprPredicate(false), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4452 assert(AssocTypes.size() == AssocExprs.size() &&
4453 "Must have the same number of association expressions"
4454 " and TypeSourceInfo!");
4455 assert(ResultIndex < NumAssocs && "ResultIndex is out-of-bounds!");
4456
4458 getTrailingObjects<TypeSourceInfo *>()[getIndexOfControllingType()] =
4459 ControllingType;
4460 std::copy(AssocExprs.begin(), AssocExprs.end(),
4461 getTrailingObjects<Stmt *>() + getIndexOfStartOfAssociatedExprs());
4462 std::copy(AssocTypes.begin(), AssocTypes.end(),
4463 getTrailingObjects<TypeSourceInfo *>() +
4464 getIndexOfStartOfAssociatedTypes());
4465
4467}
4468
4469GenericSelectionExpr::GenericSelectionExpr(
4473 bool ContainsUnexpandedParameterPack)
4474 : Expr(GenericSelectionExprClass, Context.DependentTy, VK_PRValue,
4476 NumAssocs(AssocExprs.size()), ResultIndex(ResultDependentIndex),
4477 IsExprPredicate(true), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4478 assert(AssocTypes.size() == AssocExprs.size() &&
4479 "Must have the same number of association expressions"
4480 " and TypeSourceInfo!");
4481
4483 getTrailingObjects<Stmt *>()[getIndexOfControllingExpression()] =
4484 ControllingExpr;
4485 std::copy(AssocExprs.begin(), AssocExprs.end(),
4486 getTrailingObjects<Stmt *>() + getIndexOfStartOfAssociatedExprs());
4487 std::copy(AssocTypes.begin(), AssocTypes.end(),
4488 getTrailingObjects<TypeSourceInfo *>() +
4489 getIndexOfStartOfAssociatedTypes());
4490
4492}
4493
4494GenericSelectionExpr::GenericSelectionExpr(
4498 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack)
4499 : Expr(GenericSelectionExprClass, Context.DependentTy, VK_PRValue,
4501 NumAssocs(AssocExprs.size()), ResultIndex(ResultDependentIndex),
4502 IsExprPredicate(false), DefaultLoc(DefaultLoc), RParenLoc(RParenLoc) {
4503 assert(AssocTypes.size() == AssocExprs.size() &&
4504 "Must have the same number of association expressions"
4505 " and TypeSourceInfo!");
4506
4508 getTrailingObjects<TypeSourceInfo *>()[getIndexOfControllingType()] =
4509 ControllingType;
4510 std::copy(AssocExprs.begin(), AssocExprs.end(),
4511 getTrailingObjects<Stmt *>() + getIndexOfStartOfAssociatedExprs());
4512 std::copy(AssocTypes.begin(), AssocTypes.end(),
4513 getTrailingObjects<TypeSourceInfo *>() +
4514 getIndexOfStartOfAssociatedTypes());
4515
4517}
4518
4519GenericSelectionExpr::GenericSelectionExpr(EmptyShell Empty, unsigned NumAssocs)
4520 : Expr(GenericSelectionExprClass, Empty), NumAssocs(NumAssocs) {}
4521
4526 bool ContainsUnexpandedParameterPack, unsigned ResultIndex) {
4527 unsigned NumAssocs = AssocExprs.size();
4528 void *Mem = Context.Allocate(
4529 totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4532 Context, GenericLoc, ControllingExpr, AssocTypes, AssocExprs, DefaultLoc,
4533 RParenLoc, ContainsUnexpandedParameterPack, ResultIndex);
4534}
4535
4540 bool ContainsUnexpandedParameterPack) {
4541 unsigned NumAssocs = AssocExprs.size();
4542 void *Mem = Context.Allocate(
4543 totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4546 Context, GenericLoc, ControllingExpr, AssocTypes, AssocExprs, DefaultLoc,
4547 RParenLoc, ContainsUnexpandedParameterPack);
4548}
4549
4554 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack,
4555 unsigned ResultIndex) {
4556 unsigned NumAssocs = AssocExprs.size();
4557 void *Mem = Context.Allocate(
4558 totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4561 Context, GenericLoc, ControllingType, AssocTypes, AssocExprs, DefaultLoc,
4562 RParenLoc, ContainsUnexpandedParameterPack, ResultIndex);
4563}
4564
4569 SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack) {
4570 unsigned NumAssocs = AssocExprs.size();
4571 void *Mem = Context.Allocate(
4572 totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4575 Context, GenericLoc, ControllingType, AssocTypes, AssocExprs, DefaultLoc,
4576 RParenLoc, ContainsUnexpandedParameterPack);
4577}
4578
4581 unsigned NumAssocs) {
4582 void *Mem = Context.Allocate(
4583 totalSizeToAlloc<Stmt *, TypeSourceInfo *>(1 + NumAssocs, NumAssocs),
4586}
4587
4588
4589
4590
4591
4593 assert(isFieldDesignator() && "Only valid on a field designator");
4594 if (FieldInfo.NameOrField & 0x01)
4597}
4598
4602 bool GNUSyntax,
4606 EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax),
4607 NumDesignators(Designators.size()), NumSubExprs(IndexExprs.size() + 1) {
4608 this->Designators = new (C) Designator[NumDesignators];
4609
4610
4612 *Child++ = Init;
4613
4614
4615
4616 unsigned IndexIdx = 0;
4617 for (unsigned I = 0; I != NumDesignators; ++I) {
4618 this->Designators[I] = Designators[I];
4620
4621 *Child++ = IndexExprs[IndexIdx++];
4623
4624 *Child++ = IndexExprs[IndexIdx++];
4625 *Child++ = IndexExprs[IndexIdx++];
4626 }
4627 }
4628
4629 assert(IndexIdx == IndexExprs.size() && "Wrong number of index expressions");
4631}
4632
4638 bool UsesColonSyntax, Expr *Init) {
4639 void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(IndexExprs.size() + 1),
4642 ColonOrEqualLoc, UsesColonSyntax,
4643 IndexExprs, Init);
4644}
4645
4647 unsigned NumIndexExprs) {
4648 void *Mem = C.Allocate(totalSizeToAlloc<Stmt *>(NumIndexExprs + 1),
4651}
4652
4655 unsigned NumDesigs) {
4656 Designators = new (C) Designator[NumDesigs];
4657 NumDesignators = NumDesigs;
4658 for (unsigned I = 0; I != NumDesigs; ++I)
4659 Designators[I] = Desigs[I];
4660}
4661
4664 if (size() == 1)
4668}
4669
4673 if (First.isFieldDesignator()) {
4674
4675
4676 for (unsigned int i = 0; i < DIE->size(); i++) {
4677 Designator &Des = *DIE->getDesignator(i);
4680 continue;
4681 return retval;
4682 }
4683 }
4684 return First.getLBracketLoc();
4685}
4686
4689}
4690
4692 assert(D.isArrayDesignator() && "Requires array designator");
4693 return getSubExpr(D.getArrayIndex() + 1);
4694}
4695
4697 assert(D.isArrayRangeDesignator() && "Requires array range designator");
4698 return getSubExpr(D.getArrayIndex() + 1);
4699}
4700
4702 assert(D.isArrayRangeDesignator() && "Requires array range designator");
4703 return getSubExpr(D.getArrayIndex() + 2);
4704}
4705
4706
4707
4711 unsigned NumNewDesignators = Last - First;
4712 if (NumNewDesignators == 0) {
4713 std::copy_backward(Designators + Idx + 1,
4714 Designators + NumDesignators,
4715 Designators + Idx);
4716 --NumNewDesignators;
4717 return;
4718 }
4719 if (NumNewDesignators == 1) {
4720 Designators[Idx] = *First;
4721 return;
4722 }
4723
4725 = new (C) Designator[NumDesignators - 1 + NumNewDesignators];
4726 std::copy(Designators, Designators + Idx, NewDesignators);
4727 std::copy(First, Last, NewDesignators + Idx);
4728 std::copy(Designators + Idx + 1, Designators + NumDesignators,
4729 NewDesignators + Idx + NumNewDesignators);
4730 Designators = NewDesignators;
4731 NumDesignators = NumDesignators - 1 + NumNewDesignators;
4732}
4733
4736 Expr *baseExpr,
4740 BaseAndUpdaterExprs[0] = baseExpr;
4741
4744 BaseAndUpdaterExprs[1] = ILE;
4745
4746
4748}
4749
4752}
4753
4756}
4757
4761 LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
4763
4764 for (unsigned I = 0, N = Exprs.size(); I != N; ++I)
4765 getTrailingObjects<Stmt *>()[I] = Exprs[I];
4767}
4768
4769ParenListExpr::ParenListExpr(EmptyShell Empty, unsigned NumExprs)
4770 : Expr(ParenListExprClass, Empty) {
4772}
4773
4778 void *Mem = Ctx.Allocate(totalSizeToAlloc<Stmt *>(Exprs.size()),
4780 return new (Mem) ParenListExpr(LParenLoc, Exprs, RParenLoc);
4781}
4782
4784 unsigned NumExprs) {
4785 void *Mem =
4788}
4789
4790
4791
4792
4793
4794static std::optional<BinaryOperator *>
4797 if (E->getOpcode() == BO_LT) {
4799 ComparedTo = E->getRHS();
4800 } else if (E->getOpcode() == BO_GT) {
4802 ComparedTo = E->getLHS();
4803 } else {
4804 return {};
4805 }
4806
4807 const Expr *AddLHS = nullptr, *AddRHS = nullptr;
4809
4810 if (BO && BO->getOpcode() == clang::BO_Add) {
4811
4812 AddLHS = BO->getLHS();
4813 AddRHS = BO->getRHS();
4814 }
4815
4816 if (!AddLHS || !AddRHS)
4817 return {};
4818
4819 const Decl *LHSDecl, *RHSDecl, *OtherDecl;
4820
4822 RHSDecl = AddRHS->IgnoreParenImpCasts()->getReferencedDeclOfCallee();
4824
4825 if (!OtherDecl)
4826 return {};
4827
4828 if (!LHSDecl && !RHSDecl)
4829 return {};
4830
4831 if ((LHSDecl && LHSDecl == OtherDecl && LHSDecl != RHSDecl) ||
4832 (RHSDecl && RHSDecl == OtherDecl && RHSDecl != LHSDecl))
4833 return BO;
4834 return {};
4835}
4836
4837
4838
4839
4840
4844 if (.has_value())
4845 return;
4846 QualType AdditionResultType = Result.value()->getType();
4847
4854 Result.value()->setExcludedOverflowPattern(true);
4855}
4856
4861 : Expr(BinaryOperatorClass, ResTy, VK, OK) {
4864 "Use CompoundAssignOperator for compound assignments");
4867 SubExprs[LHS] = lhs;
4868 SubExprs[RHS] = rhs;
4874}
4875
4880 : Expr(CompoundAssignOperatorClass, ResTy, VK, OK) {
4884 "Use CompoundAssignOperator for compound assignments");
4886 SubExprs[LHS] = lhs;
4887 SubExprs[RHS] = rhs;
4892}
4893
4895 bool HasFPFeatures) {
4897 void *Mem =
4900}
4901
4909 void *Mem =
4911 return new (Mem)
4912 BinaryOperator(C, lhs, rhs, opc, ResTy, VK, OK, opLoc, FPFeatures);
4913}
4914
4921}
4922
4933 return new (Mem)
4935 CompLHSType, CompResultType);
4936}
4937
4939 bool hasFPFeatures) {
4940 void *Mem = C.Allocate(totalSizeToAlloc(hasFPFeatures),
4943}
4944
4949 : Expr(UnaryOperatorClass, type, VK, OK), Val(input) {
4957}
4958
4965 unsigned Size = totalSizeToAlloc(HasFPFeatures);
4966 void *Mem = C.Allocate(Size, alignof(UnaryOperator));
4967 return new (Mem)
4968 UnaryOperator(C, input, opc, type, VK, OK, l, CanOverflow, FPFeatures);
4969}
4970
4972 if (const ExprWithCleanups *ewc = dyn_cast(e))
4973 e = ewc->getSubExpr();
4975 e = m->getSubExpr();
4976 e = cast(e)->getArg(0);
4977 while (const ImplicitCastExpr *ice = dyn_cast(e))
4978 e = ice->getSubExpr();
4979 return cast(e);
4980}
4981
4984 unsigned numSemanticExprs) {
4985 void *buffer =
4986 Context.Allocate(totalSizeToAlloc<Expr *>(1 + numSemanticExprs),
4989}
4990
4991PseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs)
4992 : Expr(PseudoObjectExprClass, shell) {
4994}
4995
4998 unsigned resultIndex) {
4999 assert(syntax && "no syntactic expression!");
5000 assert(semantics.size() && "no semantic expressions!");
5001
5004 if (resultIndex == NoResult) {
5007 } else {
5008 assert(resultIndex < semantics.size());
5010 VK = semantics[resultIndex]->getValueKind();
5012 }
5013
5014 void *buffer = C.Allocate(totalSizeToAlloc<Expr *>(semantics.size() + 1),
5017 resultIndex);
5018}
5019
5022 unsigned resultIndex)
5026
5027 for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) {
5029 getSubExprsBuffer()[i] = E;
5030
5031 if (isa(E))
5032 assert(cast(E)->getSourceExpr() != nullptr &&
5033 "opaque-value semantic expressions for pseudo-object "
5034 "operations must have sources");
5035 }
5036
5038}
5039
5040
5041
5042
5043
5044
5049}
5050
5052
5053
5054
5057 dyn_cast(getArgumentType().getTypePtr()))
5060 }
5062}
5063
5067 NumSubExprs(args.size()), BuiltinLoc(BLoc), RParenLoc(RP), Op(op) {
5068 assert(args.size() == getNumSubExprs(op) && "wrong number of subexpressions");
5069 for (unsigned i = 0; i != args.size(); i++)
5070 SubExprs[i] = args[i];
5072}
5073
5075 switch (Op) {
5076 case AO__c11_atomic_init:
5077 case AO__opencl_atomic_init:
5078 case AO__c11_atomic_load:
5079 case AO__atomic_load_n:
5080 return 2;
5081
5082 case AO__scoped_atomic_load_n:
5083 case AO__opencl_atomic_load:
5084 case AO__hip_atomic_load:
5085 case AO__c11_atomic_store:
5086 case AO__c11_atomic_exchange:
5087 case AO__atomic_load:
5088 case AO__atomic_store:
5089 case AO__atomic_store_n:
5090 case AO__atomic_exchange_n:
5091 case AO__c11_atomic_fetch_add:
5092 case AO__c11_atomic_fetch_sub:
5093 case AO__c11_atomic_fetch_and:
5094 case AO__c11_atomic_fetch_or:
5095 case AO__c11_atomic_fetch_xor:
5096 case AO__c11_atomic_fetch_nand:
5097 case AO__c11_atomic_fetch_max:
5098 case AO__c11_atomic_fetch_min:
5099 case AO__atomic_fetch_add:
5100 case AO__atomic_fetch_sub:
5101 case AO__atomic_fetch_and:
5102 case AO__atomic_fetch_or:
5103 case AO__atomic_fetch_xor:
5104 case AO__atomic_fetch_nand:
5105 case AO__atomic_add_fetch:
5106 case AO__atomic_sub_fetch:
5107 case AO__atomic_and_fetch:
5108 case AO__atomic_or_fetch:
5109 case AO__atomic_xor_fetch:
5110 case AO__atomic_nand_fetch:
5111 case AO__atomic_min_fetch:
5112 case AO__atomic_max_fetch:
5113 case AO__atomic_fetch_min:
5114 case AO__atomic_fetch_max:
5115 return 3;
5116
5117 case AO__scoped_atomic_load:
5118 case AO__scoped_atomic_store:
5119 case AO__scoped_atomic_store_n:
5120 case AO__scoped_atomic_fetch_add:
5121 case AO__scoped_atomic_fetch_sub:
5122 case AO__scoped_atomic_fetch_and:
5123 case AO__scoped_atomic_fetch_or:
5124 case AO__scoped_atomic_fetch_xor:
5125 case AO__scoped_atomic_fetch_nand:
5126 case AO__scoped_atomic_add_fetch:
5127 case AO__scoped_atomic_sub_fetch:
5128 case AO__scoped_atomic_and_fetch:
5129 case AO__scoped_atomic_or_fetch:
5130 case AO__scoped_atomic_xor_fetch:
5131 case AO__scoped_atomic_nand_fetch:
5132 case AO__scoped_atomic_min_fetch:
5133 case AO__scoped_atomic_max_fetch:
5134 case AO__scoped_atomic_fetch_min:
5135 case AO__scoped_atomic_fetch_max:
5136 case AO__scoped_atomic_exchange_n:
5137 case AO__hip_atomic_exchange:
5138 case AO__hip_atomic_fetch_add:
5139 case AO__hip_atomic_fetch_sub:
5140 case AO__hip_atomic_fetch_and:
5141 case AO__hip_atomic_fetch_or:
5142 case AO__hip_atomic_fetch_xor:
5143 case AO__hip_atomic_fetch_min:
5144 case AO__hip_atomic_fetch_max:
5145 case AO__opencl_atomic_store:
5146 case AO__hip_atomic_store:
5147 case AO__opencl_atomic_exchange:
5148 case AO__opencl_atomic_fetch_add:
5149 case AO__opencl_atomic_fetch_sub:
5150 case AO__opencl_atomic_fetch_and:
5151 case AO__opencl_atomic_fetch_or:
5152 case AO__opencl_atomic_fetch_xor:
5153 case AO__opencl_atomic_fetch_min:
5154 case AO__opencl_atomic_fetch_max:
5155 case AO__atomic_exchange:
5156 return 4;
5157
5158 case AO__scoped_atomic_exchange:
5159 case AO__c11_atomic_compare_exchange_strong:
5160 case AO__c11_atomic_compare_exchange_weak:
5161 return 5;
5162 case AO__hip_atomic_compare_exchange_strong:
5163 case AO__opencl_atomic_compare_exchange_strong:
5164 case AO__opencl_atomic_compare_exchange_weak:
5165 case AO__hip_atomic_compare_exchange_weak:
5166 case AO__atomic_compare_exchange:
5167 case AO__atomic_compare_exchange_n:
5168 return 6;
5169
5170 case AO__scoped_atomic_compare_exchange:
5171 case AO__scoped_atomic_compare_exchange_n:
5172 return 7;
5173 }
5174 llvm_unreachable("unknown atomic op");
5175}
5176
5180 return AT->getValueType();
5181 return T;
5182}
5183
5185 unsigned ArraySectionCount = 0;
5186 while (auto *OASE = dyn_cast(Base->IgnoreParens())) {
5187 Base = OASE->getBase();
5188 ++ArraySectionCount;
5189 }
5190 while (auto *ASE =
5191 dyn_cast(Base->IgnoreParenImpCasts())) {
5192 Base = ASE->getBase();
5193 ++ArraySectionCount;
5194 }
5195 Base = Base->IgnoreParenImpCasts();
5196 auto OriginalTy = Base->getType();
5197 if (auto *DRE = dyn_cast(Base))
5198 if (auto *PVD = dyn_cast(DRE->getDecl()))
5199 OriginalTy = PVD->getOriginalType().getNonReferenceType();
5200
5201 for (unsigned Cnt = 0; Cnt < ArraySectionCount; ++Cnt) {
5202 if (OriginalTy->isAnyPointerType())
5203 OriginalTy = OriginalTy->getPointeeType();
5204 else if (OriginalTy->isArrayType())
5205 OriginalTy = OriginalTy->castAsArrayTypeUnsafe()->getElementType();
5206 else
5207 return {};
5208 }
5209 return OriginalTy;
5210}
5211
5214 : Expr(RecoveryExprClass, T.getNonReferenceType(),
5215 T->isDependentType() ? VK_LValue : getValueKindForType(T),
5217 BeginLoc(BeginLoc), EndLoc(EndLoc), NumExprs(SubExprs.size()) {
5218 assert(.isNull());
5219 assert(!llvm::is_contained(SubExprs, nullptr));
5220
5221 llvm::copy(SubExprs, getTrailingObjects<Expr *>());
5223}
5224
5229 void *Mem = Ctx.Allocate(totalSizeToAlloc<Expr *>(SubExprs.size()),
5231 return new (Mem) RecoveryExpr(Ctx, T, BeginLoc, EndLoc, SubExprs);
5232}
5233
5235 void *Mem = Ctx.Allocate(totalSizeToAlloc<Expr *>(NumSubExprs),
5238}
5239
5240void OMPArrayShapingExpr::setDimensions(ArrayRef<Expr *> Dims) {
5241 assert(
5242 NumDims == Dims.size() &&
5243 "Preallocated number of dimensions is different from the provided one.");
5244 llvm::copy(Dims, getTrailingObjects<Expr *>());
5245}
5246
5248 assert(
5249 NumDims == BR.size() &&
5250 "Preallocated number of dimensions is different from the provided one.");
5251 llvm::copy(BR, getTrailingObjects());
5252}
5253
5254OMPArrayShapingExpr::OMPArrayShapingExpr(QualType ExprTy, Expr *Op,
5258 RPLoc(R), NumDims(Dims.size()) {
5259 setBase(Op);
5260 setDimensions(Dims);
5262}
5263
5269 assert(Dims.size() == BracketRanges.size() &&
5270 "Different number of dimensions and brackets ranges.");
5271 void *Mem = Context.Allocate(
5272 totalSizeToAlloc<Expr *, SourceRange>(Dims.size() + 1, Dims.size()),
5275 E->setBracketsRanges(BracketRanges);
5276 return E;
5277}
5278
5280 unsigned NumDims) {
5281 void *Mem = Context.Allocate(
5282 totalSizeToAlloc<Expr *, SourceRange>(NumDims + 1, NumDims),
5285}
5286
5287void OMPIteratorExpr::setIteratorDeclaration(unsigned I, Decl *D) {
5288 assert(I < NumIterators &&
5289 "Idx is greater or equal the number of iterators definitions.");
5290 getTrailingObjects<Decl *>()[I] = D;
5291}
5292
5293void OMPIteratorExpr::setAssignmentLoc(unsigned I, SourceLocation Loc) {
5294 assert(I < NumIterators &&
5295 "Idx is greater or equal the number of iterators definitions.");
5296 getTrailingObjects<
5297 SourceLocation>()[I * static_cast<int>(RangeLocOffset::Total) +
5298 static_cast<int>(RangeLocOffset::AssignLoc)] = Loc;
5299}
5300
5301void OMPIteratorExpr::setIteratorRange(unsigned I, Expr *Begin,
5304 Expr *Step) {
5305 assert(I < NumIterators &&
5306 "Idx is greater or equal the number of iterators definitions.");
5307 getTrailingObjects<Expr *>()[I * static_cast<int>(RangeExprOffset::Total) +
5308 static_cast<int>(RangeExprOffset::Begin)] =
5310 getTrailingObjects<Expr *>()[I * static_cast<int>(RangeExprOffset::Total) +
5311 static_cast<int>(RangeExprOffset::End)] = End;
5312 getTrailingObjects<Expr *>()[I * static_cast<int>(RangeExprOffset::Total) +
5313 static_cast<int>(RangeExprOffset::Step)] = Step;
5314 getTrailingObjects<
5315 SourceLocation>()[I * static_cast<int>(RangeLocOffset::Total) +
5316 static_cast<int>(RangeLocOffset::FirstColonLoc)] =
5317 ColonLoc;
5318 getTrailingObjects<
5319 SourceLocation>()[I * static_cast<int>(RangeLocOffset::Total) +
5320 static_cast<int>(RangeLocOffset::SecondColonLoc)] =
5321 SecondColonLoc;
5322}
5323
5325 return getTrailingObjects<Decl *>()[I];
5326}
5327
5331 getTrailingObjects<Expr *>()[I * static_cast<int>(
5332 RangeExprOffset::Total) +
5333 static_cast<int>(RangeExprOffset::Begin)];
5334 Res.End =
5335 getTrailingObjects<Expr *>()[I * static_cast<int>(
5336 RangeExprOffset::Total) +
5337 static_cast<int>(RangeExprOffset::End)];
5339 getTrailingObjects<Expr *>()[I * static_cast<int>(
5340 RangeExprOffset::Total) +
5341 static_cast<int>(RangeExprOffset::Step)];
5342 return Res;
5343}
5344
5346 return getTrailingObjects<
5347 SourceLocation>()[I * static_cast<int>(RangeLocOffset::Total) +
5348 static_cast<int>(RangeLocOffset::AssignLoc)];
5349}
5350
5352 return getTrailingObjects<
5353 SourceLocation>()[I * static_cast<int>(RangeLocOffset::Total) +
5354 static_cast<int>(RangeLocOffset::FirstColonLoc)];
5355}
5356
5358 return getTrailingObjects<
5359 SourceLocation>()[I * static_cast<int>(RangeLocOffset::Total) +
5360 static_cast<int>(RangeLocOffset::SecondColonLoc)];
5361}
5362
5364 getTrailingObjects()[I] = D;
5365}
5366
5368 return getTrailingObjects()[I];
5369}
5370
5372 return getTrailingObjects()[I];
5373}
5374
5375OMPIteratorExpr::OMPIteratorExpr(
5380 IteratorKwLoc(IteratorKwLoc), LPLoc(L), RPLoc(R),
5381 NumIterators(Data.size()) {
5382 for (unsigned I = 0, E = Data.size(); I < E; ++I) {
5383 const IteratorDefinition &D = Data[I];
5384 setIteratorDeclaration(I, D.IteratorDecl);
5385 setAssignmentLoc(I, D.AssignmentLoc);
5386 setIteratorRange(I, D.Range.Begin, D.ColonLoc, D.Range.End,
5387 D.SecondColonLoc, D.Range.Step);
5388 setHelper(I, Helpers[I]);
5389 }
5391}
5392
5399 assert(Data.size() == Helpers.size() &&
5400 "Data and helpers must have the same size.");
5401 void *Mem = Context.Allocate(
5402 totalSizeToAlloc<Decl *, Expr *, SourceLocation, OMPIteratorHelperData>(
5403 Data.size(), Data.size() * static_cast<int>(RangeExprOffset::Total),
5404 Data.size() * static_cast<int>(RangeLocOffset::Total),
5405 Helpers.size()),
5408}
5409
5411 unsigned NumIterators) {
5412 void *Mem = Context.Allocate(
5413 totalSizeToAlloc<Decl *, Expr *, SourceLocation, OMPIteratorHelperData>(
5414 NumIterators, NumIterators * static_cast<int>(RangeExprOffset::Total),
5415 NumIterators * static_cast<int>(RangeLocOffset::Total), NumIterators),
5418}
5419
5423 bool IsInOut) {
5425}
5426
5429}
5430
5434}
5435
5439}
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
static bool isBooleanType(QualType Ty)
static Expr * IgnoreImplicitConstructorSingleStep(Expr *E)
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
static const Expr * skipTemporaryBindingsNoOpCastsAndParens(const Expr *E)
Skip over any no-op casts and any temporary-binding expressions.
static void AssertResultStorageKind(ConstantResultStorageKind Kind)
static void computeOverflowPatternExclusion(const ASTContext &Ctx, const BinaryOperator *E)
Compute and set the OverflowPatternExclusion bit based on whether the BinaryOperator expression match...
static std::optional< BinaryOperator * > getOverflowPatternBinOp(const BinaryOperator *E)
Certain overflow-dependent code patterns can have their integer overflow sanitization disabled.
llvm::MachO::Target Target
Defines the clang::Preprocessor interface.
static QualType getUnderlyingType(const SubRegion *R)
static bool isRecordType(QualType T)
Defines the SourceManager interface.
static QualType getPointeeType(const MemRegion *R)
static const TypeInfo & getInfo(unsigned id)
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
void setValue(const ASTContext &C, const llvm::APInt &Val)
llvm::APInt getValue() const
uint64_t * pVal
Used to store the >64 bits integer value.
uint64_t VAL
Used to store the <= 64 bits integer value.
void setIntValue(const ASTContext &C, const llvm::APInt &Val)
A non-discriminated union of a base, field, or array index.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
static APValue IndeterminateValue()
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
@ None
There is no such object (it's outside its lifetime).
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
const ConstantArrayType * getAsConstantArrayType(QualType T) const
MangleContext * createMangleContext(const TargetInfo *T=nullptr)
If T is null pointer, assume the target in ASTContext.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Builtin::Context & BuiltinInfo
const LangOptions & getLangOpts() const
Qualifiers::GC getObjCGCAttrKind(QualType Ty) const
Return one of the GCNone, Weak or Strong Objective-C garbage collection attributes.
TypeInfo getTypeInfo(const Type *T) const
Get the size and alignment of the specified complete type in bits.
LangAS getDefaultOpenCLPointeeAddrSpace()
Returns default address space based on OpenCL version and enabled features.
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
void * Allocate(size_t Size, unsigned Align=8) const
CanQualType UnsignedIntTy
llvm::APSInt MakeIntValue(uint64_t Value, QualType Type) const
Make an APSInt of the appropriate width and signedness for the given Value and integer Type.
StringLiteral * getPredefinedStringLiteralFromCache(StringRef Key) const
Return a string representing the human readable name for the specified function declaration or file n...
DiagnosticsEngine & getDiagnostics() const
UnnamedGlobalConstantDecl * getUnnamedGlobalConstantDecl(QualType Ty, const APValue &Value) const
Return a declaration for a uniquified anonymous global constant corresponding to a given APValue.
const TargetInfo & getTargetInfo() const
void addDestruction(T *Ptr) const
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
void resize(const ASTContext &C, unsigned N, const T &NV)
iterator insert(const ASTContext &C, iterator I, const T &Elt)
void reserve(const ASTContext &C, unsigned N)
static QualType getBaseOriginalType(const Expr *Base)
Return original type of the base expression for array section.
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
QualType getValueType() const
AtomicExpr(SourceLocation BLoc, ArrayRef< Expr * > args, QualType t, AtomicOp op, SourceLocation RP)
unsigned getNumSubExprs() const
A builtin binary operation expression such as "x + y" or "x <= y".
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
StringRef getOpcodeStr() const
SourceLocation getOperatorLoc() const
bool hasStoredFPFeatures() const
bool isCompoundAssignmentOp() const
static unsigned sizeOfTrailingObjects(bool HasFPFeatures)
Return the size in bytes needed for the trailing objects.
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
static BinaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
static bool isAssignmentOp(Opcode Opc)
static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc, const Expr *LHS, const Expr *RHS)
Return true if a binary operator using the specified opcode and operands would match the 'p = (i8*)nu...
void setStoredFPFeatures(FPOptionsOverride F)
Set FPFeatures in trailing storage, used only by Serialization.
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Build a binary operator, assuming that appropriate storage has been allocated for the trailing object...
A binding in a decomposition declaration.
Stmt * getBody() const override
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
SourceLocation getCaretLocation() const
SourceLocation getCaretLocation() const
const Stmt * getBody() const
const FunctionProtoType * getFunctionType() const
getFunctionType - Return the underlying function type for this block.
bool isUnevaluated(unsigned ID) const
Returns true if this builtin does not perform the side-effects of its arguments.
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
static CStyleCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures)
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
SourceLocation getLParenLoc() const
Represents a call to a CUDA kernel function.
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
Represents a call to a C++ constructor.
Expr * getArg(unsigned Arg)
Return the specified argument.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Represents a C++ constructor within a class.
A default argument (C++ [dcl.fct.default]).
A use of a default initializer in a constructor or in aggregate initialization.
Represents a C++ destructor within a class.
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr....
Represents a call to a member function that may be written either with member call syntax (e....
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
A call to an overloaded operator written using operator syntax.
SourceLocation getOperatorLoc() const
Returns the location of the operator symbol in the expression.
OverloadedOperatorKind getOperator() const
Returns the kind of overloaded operator that this expression refers to.
SourceRange getSourceRange() const
Represents a C++ struct/union/class.
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
A C++ static_cast expression (C++ [expr.static.cast]).
Represents the this expression in C++.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
bool hasStoredFPFeatures() const
static unsigned sizeOfTrailingObjects(unsigned NumPreArgs, unsigned NumArgs, bool HasFPFeatures)
Return the size in bytes needed for the trailing objects.
void setArg(unsigned Arg, Expr *ArgExpr)
setArg - Set the specified argument.
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
std::pair< const NamedDecl *, const Attr * > getUnusedResultAttr(const ASTContext &Ctx) const
Returns the WarnUnusedResultAttr that is either declared on the called function, or its return type d...
SourceLocation getBeginLoc() const LLVM_READONLY
unsigned getBuiltinCallee() const
getBuiltinCallee - If this is a call to a builtin, return the builtin ID of the callee.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
static CallExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty)
Create an empty call expression, for deserialization.
bool isCallToStdMove() const
SourceLocation getEndLoc() const LLVM_READONLY
void setPreArg(unsigned I, Stmt *PreArg)
void computeDependence()
Compute and set dependence bits.
void setStoredFPFeatures(FPOptionsOverride F)
Set FPOptionsOverride in trailing storage. Used only by Serialization.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
CallExpr(StmtClass SC, Expr *Fn, ArrayRef< Expr * > PreArgs, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs, ADLCallKind UsesADL)
Build a call expression, assuming that appropriate storage has been allocated for the trailing object...
SourceLocation getRParenLoc() const
static constexpr ADLCallKind UsesADL
static CallExpr * CreateTemporary(void *Mem, Expr *Fn, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, ADLCallKind UsesADL=NotADL)
Create a temporary call expression with no arguments in the memory pointed to by Mem.
bool isBuiltinAssumeFalse(const ASTContext &Ctx) const
Return true if this is a call to __assume() or __builtin_assume() with a non-value-dependent constant...
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
bool isUnevaluatedBuiltinCall(const ASTContext &Ctx) const
Returns true if this is a call to a builtin which does not evaluate side-effects within its arguments...
unsigned getNumPreArgs() const
bool hasUnusedResultAttr(const ASTContext &Ctx) const
Returns true if this call expression should warn on unused results.
QualType withConst() const
Retrieves a version of this type with const applied.
bool isVolatileQualified() const
Represents the body of a CapturedStmt, and serves as its DeclContext.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
FPOptionsOverride * getTrailingFPFeatures()
Return a pointer to the trailing FPOptions.
NamedDecl * getConversionFunction() const
If this cast applies a user-defined conversion, retrieve the conversion function that it invokes.
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
CastKind getCastKind() const
bool hasStoredFPFeatures() const
static const FieldDecl * getTargetFieldForToUnionCast(QualType unionType, QualType opType)
const char * getCastKindName() const
SourceLocation getEnd() const
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
void setValue(unsigned Val)
static void print(unsigned val, CharacterLiteralKind Kind, raw_ostream &OS)
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Represents a class template specialization, which refers to a class template with a given set of temp...
bool isExplicitSpecialization() const
CompoundAssignOperator - For compound assignments (e.g.
static CompoundAssignOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
static CompoundAssignOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures, QualType CompLHSType=QualType(), QualType CompResultType=QualType())
CompoundLiteralExpr - [C99 6.5.2.5].
CompoundStmt - This represents a group of statements like { stmt stmt }.
ConditionalOperator - The ?: ternary operator.
ConstEvaluatedExprVisitor - This class visits 'const Expr *'s.
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
APValue getAPValueResult() const
static ConstantResultStorageKind getStorageKind(const APValue &Value)
void MoveIntoResult(APValue &Value, const ASTContext &Context)
llvm::APSInt getResultAsAPSInt() const
ConstantResultStorageKind getResultStorageKind() const
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
static ConstantExpr * CreateEmpty(const ASTContext &Context, ConstantResultStorageKind StorageKind)
A POD class for pairing a NamedDecl* with an access specifier.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
A reference to a declared variable, function, enum, etc.
bool hasExplicitTemplateArgs() const
Determines whether this declaration reference was followed by an explicit template argument list.
void setDecl(ValueDecl *NewD)
static DeclRefExpr * CreateEmpty(const ASTContext &Context, bool HasQualifier, bool HasFoundDecl, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
Construct an empty declaration reference expression.
SourceLocation getBeginLoc() const LLVM_READONLY
DeclarationNameInfo getNameInfo() const
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
bool hasQualifier() const
Determine whether this declaration reference was preceded by a C++ nested-name-specifier,...
NestedNameSpecifierLoc getQualifierLoc() const
If the name was qualified, retrieves the nested-name-specifier that precedes the name,...
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
static Decl * castFromDeclContext(const DeclContext *)
DeclContext * getDeclContext()
AccessSpecifier getAccess() const
static bool isFlexibleArrayMemberLike(ASTContext &Context, const Decl *D, QualType Ty, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, bool IgnoreTemplateOrMacroSubstitution)
Whether it resembles a flexible array member.
DeclarationNameLoc - Additional source/type location info for a declaration name.
Represents the type decltype(expr) (C++11).
Represents a single C99 designator.
SourceRange getSourceRange() const LLVM_READONLY
bool isFieldDesignator() const
SourceLocation getBeginLoc() const LLVM_READONLY
struct FieldDesignatorInfo FieldInfo
A field designator, e.g., ".x".
bool isArrayRangeDesignator() const
FieldDecl * getFieldDecl() const
bool isArrayDesignator() const
SourceLocation getFieldLoc() const
const IdentifierInfo * getFieldName() const
SourceLocation getDotLoc() const
Represents a C99 designated initializer expression.
static DesignatedInitExpr * CreateEmpty(const ASTContext &C, unsigned NumIndexExprs)
Expr * getArrayRangeEnd(const Designator &D) const
Expr * getSubExpr(unsigned Idx) const
SourceRange getDesignatorsSourceRange() const
Expr * getArrayRangeStart(const Designator &D) const
void ExpandDesignator(const ASTContext &C, unsigned Idx, const Designator *First, const Designator *Last)
Replaces the designator at index Idx with the series of designators in [First, Last).
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Expr * getArrayIndex(const Designator &D) const
Designator * getDesignator(unsigned Idx)
Expr * getInit() const
Retrieve the initializer value.
unsigned size() const
Returns the number of designators in this initializer.
SourceLocation getBeginLoc() const LLVM_READONLY
void setDesignators(const ASTContext &C, const Designator *Desigs, unsigned NumDesigs)
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
DesignatedInitUpdateExpr(const ASTContext &C, SourceLocation lBraceLoc, Expr *baseExprs, SourceLocation rBraceLoc)
SourceLocation getEndLoc() const LLVM_READONLY
InitListExpr * getUpdater() const
EmbedExpr(const ASTContext &Ctx, SourceLocation Loc, EmbedDataStorage *Data, unsigned Begin, unsigned NumOfElements)
An instance of this object exists for each enum constant that is defined.
ExplicitCastExpr - An explicit cast written in the source code.
QualType getTypeAsWritten() const
getTypeAsWritten - Returns the type that this expression is casting to, as written in the source code...
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
EnumConstantDecl * getEnumConstantDecl()
If this expression refers to an enum constant, retrieve its declaration.
bool isReadIfDiscardedInCPlusPlus11() const
Determine whether an lvalue-to-rvalue conversion should implicitly be applied to this expression if i...
Expr * IgnoreParenNoopCasts(const ASTContext &Ctx) LLVM_READONLY
Skip past any parentheses and casts which do not change the value (including ptr->int casts of the sa...
@ SE_AllowUndefinedBehavior
Allow UB that we can give a value, but not arbitrary unmodeled side effects.
static QualType findBoundMemberType(const Expr *expr)
Given an expression of bound-member type, find the type of the member.
bool isImplicitCXXThis() const
Whether this expression is an implicit reference to 'this' in C++.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
bool isUnusedResultAWarning(const Expr *&WarnExpr, SourceLocation &Loc, SourceRange &R1, SourceRange &R2, ASTContext &Ctx) const
isUnusedResultAWarning - Return true if this immediate expression should be warned about if the resul...
LValueClassification ClassifyLValue(ASTContext &Ctx) const
Reasons why an expression might not be an l-value.
bool isValueDependent() const
Determines whether the value of this expression depends on.
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
bool refersToVectorElement() const
Returns whether this expression refers to a vector element.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded integer.
Expr * IgnoreParenLValueCasts() LLVM_READONLY
Skip past any parentheses and lvalue casts which might surround this expression until reaching a fixe...
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Returns the set of floating point options that apply to this expression.
const CXXRecordDecl * getBestDynamicClassType() const
For an expression of class type or pointer to class type, return the most derived class decl the expr...
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
Expr * IgnoreImplicit() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Expr * IgnoreConversionOperatorSingleStep() LLVM_READONLY
Skip conversion operators.
bool containsErrors() const
Whether this expression contains subexpressions which had errors, e.g.
bool isObjCSelfExpr() const
Check if this expression is the ObjC 'self' implicit parameter.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
bool isEvaluatable(const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
isEvaluatable - Call EvaluateAsRValue to see if this expression can be constant folded without side-e...
Expr * IgnoreParenBaseCasts() LLVM_READONLY
Skip past any parentheses and derived-to-base casts until reaching a fixed point.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
static bool hasAnyTypeDependentArguments(ArrayRef< Expr * > Exprs)
hasAnyTypeDependentArguments - Determines if any of the expressions in Exprs is type-dependent.
FieldDecl * getSourceBitField()
If this expression refers to a bit-field, retrieve the declaration of that bit-field.
NullPointerConstantValueDependence
Enumeration used to describe how isNullPointerConstant() should cope with value-dependent expressions...
@ NPC_ValueDependentIsNull
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
@ NPC_NeverValueDependent
Specifies that the expression should never be value-dependent.
@ NPC_ValueDependentIsNotNull
Specifies that a value-dependent expression should be considered to never be a null pointer constant.
Expr * IgnoreUnlessSpelledInSource()
Skip past any invisible AST nodes which might surround this statement, such as ExprWithCleanups or Im...
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Expr * IgnoreCasts() LLVM_READONLY
Skip past any casts which might surround this expression until reaching a fixed point.
Decl * getReferencedDeclOfCallee()
Expr * IgnoreImplicitAsWritten() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
bool EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx, ConstantExprKind Kind=ConstantExprKind::Normal) const
Evaluate an expression that is required to be a constant expression.
const Expr * getBestDynamicClassTypeExpr() const
Get the inner expression that determines the best dynamic class.
bool isIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
NullPointerConstantKind
Enumeration used to describe the kind of Null pointer constant returned from isNullPointerConstant().
@ NPCK_ZeroExpression
Expression is a Null pointer constant built from a zero integer expression that is not a simple,...
@ NPCK_ZeroLiteral
Expression is a Null pointer constant built from a literal zero.
@ NPCK_CXX11_nullptr
Expression is a C++11 nullptr.
@ NPCK_GNUNull
Expression is a GNU-style __null constant.
@ NPCK_NotNull
Expression is not a Null pointer constant.
bool EvaluateAsBooleanCondition(bool &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsBooleanCondition - Return true if this is a constant which we can fold and convert to a boo...
bool isTemporaryObject(ASTContext &Ctx, const CXXRecordDecl *TempTy) const
Determine whether the result of this expression is a temporary object of the given class type.
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant.
QualType getEnumCoercedType(const ASTContext &Ctx) const
If this expression is an enumeration constant, return the enumeration type under which said constant ...
bool isBoundMemberFunction(ASTContext &Ctx) const
Returns true if this expression is a bound member function.
bool isConstantInitializer(ASTContext &Ctx, bool ForRef, const Expr **Culprit=nullptr) const
isConstantInitializer - Returns true if this expression can be emitted to IR as a constant,...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
static bool isSameComparisonOperand(const Expr *E1, const Expr *E2)
Checks that the two Expr's will refer to the same value as a comparison operand.
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
bool isFlexibleArrayMemberLike(ASTContext &Context, LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel, bool IgnoreTemplateOrMacroSubstitution=false) const
Check whether this array fits the idiom of a flexible array member, depending on the value of -fstric...
Classification Classify(ASTContext &Ctx) const
Classify - Classify this expression according to the C++11 expression taxonomy.
bool hasNonTrivialCall(const ASTContext &Ctx) const
Determine whether this expression involves a call to any function that is not trivial.
bool refersToGlobalRegisterVar() const
Returns whether this expression refers to a global register variable.
bool isCXX98IntegralConstantExpr(const ASTContext &Ctx) const
isCXX98IntegralConstantExpr - Return true if this expression is an integral constant expression in C+...
const ValueDecl * getAsBuiltinConstantDeclRef(const ASTContext &Context) const
If this expression is an unambiguous reference to a single declaration, in the style of __builtin_fun...
bool isOBJCGCCandidate(ASTContext &Ctx) const
isOBJCGCCandidate - Return true if this expression may be used in a read/ write barrier.
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
const Expr * skipRValueSubobjectAdjustments() const
bool isKnownToHaveBooleanValue(bool Semantic=true) const
isKnownToHaveBooleanValue - Return true if this is an integer expression that is known to return 0 or...
void setDependence(ExprDependence Deps)
Each concrete expr subclass is expected to compute its dependence and call this in the constructor.
const ObjCPropertyRefExpr * getObjCProperty() const
If this expression is an l-value for an Objective C property, find the underlying property reference ...
bool containsDuplicateElements() const
containsDuplicateElements - Return true if any element access is repeated.
bool isArrow() const
isArrow - Return true if the base expression is a pointer to vector, return false if the base express...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
const Expr * getBase() const
unsigned getNumElements() const
getNumElements - Get the number of components being selected.
static int getAccessorIdx(char c, bool isNumericAccessor)
Represents difference between two FPOptions values.
bool requiresTrailingStorage() const
static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO)
Return the default value of FPOptions that's used when trailing storage isn't required.
Represents a member of a struct/union/class.
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
bool isBitField() const
Determines whether this field is a bitfield.
static FixedPointLiteral * Create(const ASTContext &C, EmptyShell Empty)
Returns an empty fixed-point literal.
std::string getValueAsString(unsigned Radix) const
static FixedPointLiteral * CreateFromRawInt(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l, unsigned Scale)
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
double getValueAsApproximateDouble() const
getValueAsApproximateDouble - This returns the value as an inaccurate double.
llvm::APFloat getValue() const
FullExpr - Represents a "full-expression" node.
Represents a function declaration or definition.
FunctionDecl * getTemplateInstantiationPattern(bool ForDefinition=true) const
Retrieve the function declaration from which this function could be instantiated, if it is an instant...
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Represents a prototype with parameter type info, e.g.
Provides information about a function template specialization, which is a FunctionDecl that has been ...
bool isExplicitSpecialization() const
TemplateArgumentList * TemplateArguments
The template arguments used to produce the function template specialization from the function templat...
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
FunctionType - C99 6.7.5.3 - Function Declarators.
CallingConv getCallConv() const
QualType getReturnType() const
Represents a C11 generic selection.
static GenericSelectionExpr * Create(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > AssocTypes, ArrayRef< Expr * > AssocExprs, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
Create a non-result-dependent generic selection expression accepting an expression predicate.
static GenericSelectionExpr * CreateEmpty(const ASTContext &Context, unsigned NumAssocs)
Create an empty generic selection expression for deserialization.
GlobalDecl - represents a global declaration.
This class represents temporary values used to represent inout and out arguments in HLSL.
static HLSLOutArgExpr * CreateEmpty(const ASTContext &Ctx)
static HLSLOutArgExpr * Create(const ASTContext &C, QualType Ty, OpaqueValueExpr *Base, OpaqueValueExpr *OpV, Expr *WB, bool IsInOut)
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
static ImplicitCastExpr * CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures)
Describes an C or C++ initializer list.
bool hasArrayFiller() const
Return true if this is an array initializer and its array "filler" has been set.
InitListExpr(const ASTContext &C, SourceLocation lbraceloc, ArrayRef< Expr * > initExprs, SourceLocation rbraceloc)
bool isTransparent() const
Is this a transparent initializer list (that is, an InitListExpr that is purely syntactic,...
void resizeInits(const ASTContext &Context, unsigned NumInits)
Specify the number of initializers.
bool isStringLiteralInit() const
Is this an initializer for an array of characters, initialized by a string literal or an @encode?
FieldDecl * getInitializedFieldInUnion()
If this initializes a union, specifies which field in the union to initialize.
unsigned getNumInits() const
SourceLocation getBeginLoc() const LLVM_READONLY
bool isSemanticForm() const
void setInit(unsigned Init, Expr *expr)
Expr * updateInit(const ASTContext &C, unsigned Init, Expr *expr)
Updates the initializer at index Init with the new expression expr, and returns the old expression at...
void setArrayFiller(Expr *filler)
InitListExpr * getSyntacticForm() const
const Expr * getInit(unsigned Init) const
bool isIdiomaticZeroInitializer(const LangOptions &LangOpts) const
Is this the zero initializer {0} in a language which considers it idiomatic?
SourceLocation getEndLoc() const LLVM_READONLY
bool isSyntacticForm() const
ArrayRef< Expr * > inits()
void sawArrayRangeDesignator(bool ARD=true)
Expr ** getInits()
Retrieve the set of initializers.
void reserveInits(const ASTContext &C, unsigned NumInits)
Reserve space for some number of initializers.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
static ItaniumMangleContext * create(ASTContext &Context, DiagnosticsEngine &Diags, bool IsAux=false)
LabelStmt - Represents a label, which has a substatement.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
StrictFlexArraysLevelKind
@ AddUnsignedOverflowTest
if (a + b < a)
@ AddSignedOverflowTest
if (a + b < a)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool isOverflowPatternExcluded(OverflowPatternExclusionKind Kind) const
void remapPathPrefix(SmallVectorImpl< char > &Path) const
Remap path prefix according to -fmacro-prefix-path option.
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
bool LexFromRawLexer(Token &Result)
LexFromRawLexer - Lex a token from a designated raw lexer (one with no associated preprocessor object...
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
static MemberExpr * CreateEmpty(const ASTContext &Context, bool HasQualifier, bool HasFoundDecl, bool HasTemplateKWAndArgsInfo, unsigned NumTemplateArgs)
void setMemberDecl(ValueDecl *D)
NestedNameSpecifierLoc getQualifierLoc() const
If the member name was qualified, retrieves the nested-name-specifier that precedes the member name,...
bool hasExplicitTemplateArgs() const
Determines whether the member name was followed by an explicit template argument list.
bool hasQualifier() const
Determines whether this member expression actually had a C++ nested-name-specifier prior to the name ...
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
bool isImplicitAccess() const
Determine whether the base of this explicit is implicit.
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
SourceLocation getEndLoc() const LLVM_READONLY
SourceLocation getBeginLoc() const LLVM_READONLY
DeclarationNameInfo getMemberNameInfo() const
Retrieve the member declaration name info.
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
A C++ nested-name-specifier augmented with source location information.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
bool hasQualifier() const
Evaluates true when this nested-name-specifier location is non-empty.
An explicit cast in C or a C-style cast in C++, which uses the syntax ([s1][s2]......
static OMPArrayShapingExpr * CreateEmpty(const ASTContext &Context, unsigned NumDims)
static OMPArrayShapingExpr * Create(const ASTContext &Context, QualType T, Expr *Op, SourceLocation L, SourceLocation R, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > BracketRanges)
OpenMP 5.0 [2.1.6 Iterators] Iterators are identifiers that expand to multiple values in the clause o...
static OMPIteratorExpr * Create(const ASTContext &Context, QualType T, SourceLocation IteratorKwLoc, SourceLocation L, SourceLocation R, ArrayRef< IteratorDefinition > Data, ArrayRef< OMPIteratorHelperData > Helpers)
static OMPIteratorExpr * CreateEmpty(const ASTContext &Context, unsigned NumIterators)
SourceLocation getSecondColonLoc(unsigned I) const
Gets the location of the second ':' (if any) in the range for the given iteratori definition.
SourceLocation getColonLoc(unsigned I) const
Gets the location of the first ':' in the range for the given iterator definition.
IteratorRange getIteratorRange(unsigned I)
Gets the iterator range for the given iterator.
OMPIteratorHelperData & getHelper(unsigned I)
Fetches helper data for the specified iteration space.
SourceLocation getAssignLoc(unsigned I) const
Gets the location of '=' for the given iterator definition.
Decl * getIteratorDecl(unsigned I)
Gets the iterator declaration for the given iterator.
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Represents an ObjC class declaration.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
An expression that sends a message to the given Objective-C object or class.
ObjCMethodFamily getMethodFamily() const
bool isInstanceMessage() const
Determine whether this is an instance message to either a computed object or to super.
const ObjCMethodDecl * getMethodDecl() const
ObjCMethodDecl - Represents an instance or class method declaration.
ImplicitParamDecl * getSelfDecl() const
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
static OffsetOfExpr * CreateEmpty(const ASTContext &C, unsigned NumComps, unsigned NumExprs)
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
void setIndexExpr(unsigned Idx, Expr *E)
void setComponent(unsigned Idx, OffsetOfNode ON)
FieldDecl * getField() const
For a field offsetof node, returns the field.
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
@ Identifier
A field in a dependent type, known only by its name.
Kind getKind() const
Determine what kind of offsetof node this is.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
static const OpaqueValueExpr * findInCopyConstruct(const Expr *expr)
Given an expression which invokes a copy constructor — i.e.
This expression type represents an asterisk in an OpenACC Size-Expr, used in the 'tile' and 'gang' cl...
static OpenACCAsteriskSizeExpr * Create(const ASTContext &C, SourceLocation Loc)
static OpenACCAsteriskSizeExpr * CreateEmpty(const ASTContext &C)
ParenExpr - This represents a parenthesized expression, e.g.
static ParenListExpr * CreateEmpty(const ASTContext &Ctx, unsigned NumExprs)
Create an empty paren list.
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
[C99 6.4.2.2] - A predefined identifier such as func.
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
StringRef getIdentKindName() const
static PredefinedExpr * CreateEmpty(const ASTContext &Ctx, bool HasFunctionName)
Create an empty PredefinedExpr.
static std::string ComputeName(PredefinedIdentKind IK, const Decl *CurrentDecl, bool ForceElaboratedPrinting=false)
static void processPathToFileName(SmallVectorImpl< char > &FileName, const PresumedLoc &PLoc, const LangOptions &LangOpts, const TargetInfo &TI)
static void processPathForFileMacro(SmallVectorImpl< char > &Path, const LangOptions &LangOpts, const TargetInfo &TI)
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
Callbacks to use to customize the behavior of the pretty-printer.
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
semantics_iterator semantics_end()
semantics_iterator semantics_begin()
const Expr *const * const_semantics_iterator
static PseudoObjectExpr * Create(const ASTContext &Context, Expr *syntactic, ArrayRef< Expr * > semantic, unsigned resultIndex)
ArrayRef< Expr * > semantics()
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
LangAS getAddressSpace() const
Return the address space of this type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const
QualType getCanonicalType() const
The collection of all-type qualifiers we support.
void removeAddressSpace()
Represents a struct/union/class.
field_iterator field_end() const
field_range fields() const
field_iterator field_begin() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() const
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
static RecoveryExpr * Create(ASTContext &Ctx, QualType T, SourceLocation BeginLoc, SourceLocation EndLoc, ArrayRef< Expr * > SubExprs)
static RecoveryExpr * CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs)
TypeSourceInfo * getTypeSourceInfo()
static SYCLUniqueStableNameExpr * Create(const ASTContext &Ctx, SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
std::string ComputeName(ASTContext &Context) const
static SYCLUniqueStableNameExpr * CreateEmpty(const ASTContext &Ctx)
void setExprs(const ASTContext &C, ArrayRef< Expr * > Exprs)
ShuffleVectorExpr(const ASTContext &C, ArrayRef< Expr * > args, QualType Type, SourceLocation BLoc, SourceLocation RP)
APValue EvaluateInContext(const ASTContext &Ctx, const Expr *DefaultExpr) const
Return the result of evaluating this SourceLocExpr in the specified (and possibly null) default argum...
SourceLocExpr(const ASTContext &Ctx, SourceLocIdentKind Type, QualType ResultTy, SourceLocation BLoc, SourceLocation RParenLoc, DeclContext *Context)
SourceLocation getLocation() const
const DeclContext * getParentContext() const
If the SourceLocExpr has been resolved return the subexpression representing the resolved value.
StringRef getBuiltinStr() const
Return a string representing the name of the specific builtin function.
static bool MayBeDependent(SourceLocIdentKind Kind)
SourceLocIdentKind getIdentKind() const
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
CharSourceRange getExpansionRange(SourceLocation Loc) const
Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate fi...
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
SourceLocation getEndLoc() const LLVM_READONLY
UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits
GenericSelectionExprBitfields GenericSelectionExprBits
ParenListExprBitfields ParenListExprBits
CallExprBitfields CallExprBits
FloatingLiteralBitfields FloatingLiteralBits
child_iterator child_begin()
StmtClass getStmtClass() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
UnaryOperatorBitfields UnaryOperatorBits
SourceLocExprBitfields SourceLocExprBits
ConstantExprBitfields ConstantExprBits
llvm::iterator_range< child_iterator > child_range
StringLiteralBitfields StringLiteralBits
MemberExprBitfields MemberExprBits
DeclRefExprBitfields DeclRefExprBits
ConstStmtIterator const_child_iterator
PredefinedExprBitfields PredefinedExprBits
SourceLocation getBeginLoc() const LLVM_READONLY
BinaryOperatorBitfields BinaryOperatorBits
PseudoObjectExprBitfields PseudoObjectExprBits
llvm::iterator_range< const_child_iterator > const_child_range
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
unsigned getOffsetOfStringByte(const Token &TheTok, unsigned ByteNo) const
getOffsetOfStringByte - This function returns the offset of the specified byte of the string data rep...
unsigned GetStringLength() const
StringLiteral - This represents a string literal expression, e.g.
SourceLocation getStrTokenLoc(unsigned TokNum) const
Get one of the string literal token.
unsigned getLength() const
StringLiteralKind getKind() const
SourceLocation getLocationOfByte(unsigned ByteNo, const SourceManager &SM, const LangOptions &Features, const TargetInfo &Target, unsigned *StartToken=nullptr, unsigned *StartTokenByteOffset=nullptr) const
getLocationOfByte - Return a source location that points to the specified byte of this string literal...
uint32_t getCodeUnit(size_t i) const
void outputString(raw_ostream &OS) const
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumConcatenated)
This is the "fully general" constructor that allows representation of strings formed from multiple co...
static StringLiteral * CreateEmpty(const ASTContext &Ctx, unsigned NumConcatenated, unsigned Length, unsigned CharByteWidth)
Construct an empty string literal.
unsigned getNumConcatenated() const
getNumConcatenated - Get the number of string literal tokens that were concatenated in translation ph...
Represents the declaration of a struct/union/class/enum.
Exposes information about the current target.
A convenient class for passing around template argument information.
A template argument list.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Location wrapper for a TemplateArgument.
void print(const PrintingPolicy &Policy, raw_ostream &Out, bool IncludeType) const
Print this template argument to the given output stream.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
static bool shouldIncludeTypeForArgument(const PrintingPolicy &Policy, const TemplateParameterList *TPL, unsigned Idx)
Token - This structure provides full information about a lexed token.
A container of type source information.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isBooleanType() const
bool hasAttr(attr::Kind AK) const
Determine whether this type had the specified attribute applied to it (looking through top-level type...
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
bool isPointerType() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs.
bool isSpecificPlaceholderType(unsigned K) const
Test for a specific placeholder type.
bool isReferenceType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
bool isVectorType() const
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
const T * getAs() const
Member-template getAs'.
bool isNullPtrType() const
bool isRecordType() const
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
QualType getArgumentType() const
bool isArgumentType() const
UnaryExprOrTypeTraitExpr(UnaryExprOrTypeTrait ExprKind, TypeSourceInfo *TInfo, QualType resultType, SourceLocation op, SourceLocation rp)
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Expr * getSubExpr() const
bool hasStoredFPFeatures() const
Is FPFeatures in Trailing Storage?
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given unary opcode.
static UnaryOperator * Create(const ASTContext &C, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
void setStoredFPFeatures(FPOptionsOverride F)
Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
static StringRef getOpcodeStr(Opcode Op)
getOpcodeStr - Turn an Opcode enum value into the punctuation char it corresponds to,...
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
A call to a literal operator (C++11 [over.literal]) written as a user-defined literal (C++11 [lit....
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
Represents a C array with a specified size that is not an integer-constant-expression.
Represents a GCC generic vector type.
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
ConstantResultStorageKind
Describes the kind of result that can be tail-allocated.
@ Ctor_Base
Base object ctor.
LLVM_READONLY bool isPrintable(unsigned char c)
Return true if this character is an ASCII printable character; that is, a character that should take ...
Expr * IgnoreExprNodes(Expr *E, FnTys &&... Fns)
Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *, Recursively apply each of the f...
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
StmtIterator cast_away_const(const ConstStmtIterator &RHS)
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
@ OK_ObjCProperty
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
@ OK_Ordinary
An ordinary object is located at an address in memory.
ExprDependence computeDependence(FullExpr *E)
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Expr * IgnoreImplicitCastsExtraSingleStep(Expr *E)
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
Expr * IgnoreImplicitCastsSingleStep(Expr *E)
@ Dtor_Base
Base object dtor.
CastKind
CastKind - The kind of operation required for a conversion.
void FixedPointValueToString(SmallVectorImpl< char > &Str, llvm::APSInt Val, unsigned Scale)
Expr * IgnoreImplicitSingleStep(Expr *E)
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Expr * IgnoreParensSingleStep(Expr *E)
const FunctionProtoType * T
Expr * IgnoreImplicitAsWrittenSingleStep(Expr *E)
Expr * IgnoreCastsSingleStep(Expr *E)
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Expr * IgnoreLValueCastsSingleStep(Expr *E)
Expr * IgnoreParensOnlySingleStep(Expr *E)
@ PrettyFunctionNoVirtual
The same as PrettyFunction, except that the 'virtual' keyword is omitted for virtual member functions...
Expr * IgnoreBaseCastsSingleStep(Expr *E)
NonOdrUseReason
The reason why a DeclRefExpr does not constitute an odr-use.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Represents an explicit template argument list in C++, e.g., the "" in "sort".
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
SourceLocation getBeginLoc() const
getBeginLoc - Retrieve the location of the first token.
SourceLocation getEndLoc() const LLVM_READONLY
Stores data related to a single #embed directive.
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.
Iterator range representation begin:end[:step].
Helper expressions and declaration for OMPIteratorExpr class for each iteration space.
Describes how types, statements, expressions, and declarations should be printed.
unsigned SuppressTagKeyword
Whether type printing should skip printing the tag keyword.
const PrintingCallbacks * Callbacks
Callbacks to use to allow the behavior of printing to be customized.
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
An adjustment to be made to the temporary created when emitting a reference binding,...