Expr.cpp revision f8ec55a104e55961f8666f773dce99bbc628298f
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Expr.cpp - Expression AST Node Implementation --------------------===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file implements the Expr class and subclasses. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14c4a1dea2dc56bd1357ec91b829a0b9e68229a13eDaniel Dunbar#include "clang/AST/Expr.h" 150979c805475d1ba49b5d6ef93c4d2ce6d2eab6edDouglas Gregor#include "clang/AST/ExprCXX.h" 16a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/APValue.h" 172eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner#include "clang/AST/ASTContext.h" 18a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/DeclObjC.h" 1998cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor#include "clang/AST/DeclCXX.h" 20aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor#include "clang/AST/DeclTemplate.h" 2119cc4abea06a9b49e0e16a50d335c064cd723572Anders Carlsson#include "clang/AST/RecordLayout.h" 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/StmtVisitor.h" 231b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner#include "clang/Basic/Builtins.h" 24da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner#include "clang/Basic/TargetInfo.h" 25ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor#include <algorithm> 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang; 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions. 305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 32da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate 33da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double. Note that this may cause loss of precision, but is useful for 34da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc. 35da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const { 36da8249e57f3badecf925571881fe57243935c6c1Chris Lattner llvm::APFloat V = getValue(); 37ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen bool ignored; 38ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven, 39ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen &ignored); 40da8249e57f3badecf925571881fe57243935c6c1Chris Lattner return V.convertToDouble(); 41da8249e57f3badecf925571881fe57243935c6c1Chris Lattner} 42da8249e57f3badecf925571881fe57243935c6c1Chris Lattner 432085fd6cd22ec5c268175251db10d7c60caf7aaaChris LattnerStringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData, 442085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner unsigned ByteLength, bool Wide, 452085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner QualType Ty, 46a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson const SourceLocation *Loc, 47a135fb43eb94524a6529768596a4533eed9aa70dAnders Carlsson unsigned NumStrs) { 482085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // Allocate enough space for the StringLiteral plus an array of locations for 492085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner // any concatenated string tokens. 502085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner void *Mem = C.Allocate(sizeof(StringLiteral)+ 512085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner sizeof(SourceLocation)*(NumStrs-1), 522085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner llvm::alignof<StringLiteral>()); 532085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner StringLiteral *SL = new (Mem) StringLiteral(Ty); 542085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner 555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // OPTIMIZE: could allocate this appended to the StringLiteral. 562085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner char *AStrData = new (C, 1) char[ByteLength]; 572085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(AStrData, StrData, ByteLength); 582085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->StrData = AStrData; 592085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->ByteLength = ByteLength; 602085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->IsWide = Wide; 612085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->TokLocs[0] = Loc[0]; 622085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner SL->NumConcatenated = NumStrs; 635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 64726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner if (NumStrs != 1) 652085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1)); 662085fd6cd22ec5c268175251db10d7c60caf7aaaChris Lattner return SL; 67726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner} 68726e168dc09fb23f53c7b004f8e919421ee91806Chris Lattner 69673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas GregorStringLiteral *StringLiteral::CreateEmpty(ASTContext &C, unsigned NumStrs) { 70673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor void *Mem = C.Allocate(sizeof(StringLiteral)+ 71673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor sizeof(SourceLocation)*(NumStrs-1), 72673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor llvm::alignof<StringLiteral>()); 73673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StringLiteral *SL = new (Mem) StringLiteral(QualType()); 74673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->StrData = 0; 75673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->ByteLength = 0; 76673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor SL->NumConcatenated = NumStrs; 77673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor return SL; 78673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 79673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 8042602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorvoid StringLiteral::DoDestroy(ASTContext &C) { 818189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek C.Deallocate(const_cast<char*>(StrData)); 8242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor Expr::DoDestroy(C); 835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 85673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregorvoid StringLiteral::setStrData(ASTContext &C, const char *Str, unsigned Len) { 86673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor if (StrData) 87673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor C.Deallocate(const_cast<char*>(StrData)); 88673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 89673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor char *AStrData = new (C, 1) char[Len]; 90673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor memcpy(AStrData, Str, Len); 91673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor StrData = AStrData; 92673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor ByteLength = Len; 93673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor} 94673ecd6a4a9f7c12fb6f76f84f654dbdcdc89e76Douglas Gregor 955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++". 975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *UnaryOperator::getOpcodeStr(Opcode Op) { 985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: assert(0 && "Unknown unary operator"); 1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case PostInc: return "++"; 1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case PostDec: return "--"; 1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case PreInc: return "++"; 1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case PreDec: return "--"; 1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case AddrOf: return "&"; 1055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Deref: return "*"; 1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Plus: return "+"; 1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Minus: return "-"; 1085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Not: return "~"; 1095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LNot: return "!"; 1105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Real: return "__real"; 1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Imag: return "__imag"; 1125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Extension: return "__extension__"; 11373d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner case OffsetOf: return "__builtin_offsetof"; 1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 117bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::Opcode 118bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorUnaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix) { 119bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (OO) { 120bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: assert(false && "No unary operator for overloaded function"); 121b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_PlusPlus: return Postfix ? PostInc : PreInc; 122b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_MinusMinus: return Postfix ? PostDec : PreDec; 123b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Amp: return AddrOf; 124b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Star: return Deref; 125b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Plus: return Plus; 126b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Minus: return Minus; 127b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Tilde: return Not; 128b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner case OO_Exclaim: return LNot; 129bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 130bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 131bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 132bc736fceca6f0bca31d16003a7587857190408fbDouglas GregorOverloadedOperatorKind UnaryOperator::getOverloadedOperator(Opcode Opc) { 133bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor switch (Opc) { 134bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case PostInc: case PreInc: return OO_PlusPlus; 135bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case PostDec: case PreDec: return OO_MinusMinus; 136bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case AddrOf: return OO_Amp; 137bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case Deref: return OO_Star; 138bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case Plus: return OO_Plus; 139bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case Minus: return OO_Minus; 140bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case Not: return OO_Tilde; 141bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor case LNot: return OO_Exclaim; 142bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor default: return OO_None; 143bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor } 144bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor} 145bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 146bc736fceca6f0bca31d16003a7587857190408fbDouglas Gregor 1475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 1485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators. 1495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 1505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 151668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args, 1528189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek unsigned numargs, QualType t, SourceLocation rparenloc) 153898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(SC, t, 154898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs), 155d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)), 156898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 157668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 158668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek SubExprs = new (C) Stmt*[numargs+1]; 159b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[FN] = fn; 160b4609806e9232593ece09ce08b630836e825865cDouglas Gregor for (unsigned i = 0; i != numargs; ++i) 161b4609806e9232593ece09ce08b630836e825865cDouglas Gregor SubExprs[i+ARGS_START] = args[i]; 162668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 163b4609806e9232593ece09ce08b630836e825865cDouglas Gregor RParenLoc = rparenloc; 164b4609806e9232593ece09ce08b630836e825865cDouglas Gregor} 165e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman 166668bf91d31265b6ea8c3eb854ba450857701f269Ted KremenekCallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs, 167668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek QualType t, SourceLocation rparenloc) 168898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor : Expr(CallExprClass, t, 169898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs), 170d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)), 171898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor NumArgs(numargs) { 172668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 173668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek SubExprs = new (C) Stmt*[numargs+1]; 17477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[FN] = fn; 1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (unsigned i = 0; i != numargs; ++i) 17677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek SubExprs[i+ARGS_START] = args[i]; 177668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer RParenLoc = rparenloc; 1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 181ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios KyrtzidisCallExpr::CallExpr(ASTContext &C, StmtClass SC, EmptyShell Empty) 182ba0a9006dbc4814e1e35f82812cb5a1dad65e8b8Argyrios Kyrtzidis : Expr(SC, Empty), SubExprs(0), NumArgs(0) { 1831f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor SubExprs = new (C) Stmt*[1]; 1841f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor} 1851f0d0133b0e8d1f01f63951ee04927796b34740dDouglas Gregor 18642602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorvoid CallExpr::DoDestroy(ASTContext& C) { 187668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek DestroyChildren(C); 188668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek if (SubExprs) C.Deallocate(SubExprs); 189668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek this->~CallExpr(); 190668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek C.Deallocate(this); 191668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek} 192668bf91d31265b6ea8c3eb854ba450857701f269Ted Kremenek 193a00425414e8c209cabc25d1826b200aeb94259afZhongxing XuFunctionDecl *CallExpr::getDirectCallee() { 194a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu Expr *CEE = getCallee()->IgnoreParenCasts(); 1956346f963145ed18b6edf50a78753b47db505e912Chris Lattner if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) 196a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu return dyn_cast<FunctionDecl>(DRE->getDecl()); 197a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 198a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu return 0; 199a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu} 200a00425414e8c209cabc25d1826b200aeb94259afZhongxing Xu 201d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call. 202d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set 203d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null. 2048189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenekvoid CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) { 205d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // No change, just return. 206d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs == getNumArgs()) return; 207d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 208d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // If shrinking # arguments, just delete the extras and forgot them. 209d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner if (NumArgs < getNumArgs()) { 210d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i) 2118189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek getArg(i)->Destroy(C); 212d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 213d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner return; 214d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner } 215d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 216d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Otherwise, we are growing the # arguments. New an bigger argument array. 21768a049cab6015a7437bec5661601b7d37d23c70cDaniel Dunbar Stmt **NewSubExprs = new (C) Stmt*[NumArgs+1]; 218d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Copy over args. 219d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i) 220d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = SubExprs[i]; 221d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner // Null out new args. 222d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i) 223d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner NewSubExprs[i] = 0; 224d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 22588c9a46f0b84f1ee83e01917825346551ee540d0Douglas Gregor if (SubExprs) C.Deallocate(SubExprs); 226d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner SubExprs = NewSubExprs; 227d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner this->NumArgs = NumArgs; 228d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner} 229d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner 230cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If 231cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0. 2323c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregorunsigned CallExpr::isBuiltinCall(ASTContext &Context) const { 233c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // All simple function calls (e.g. func()) are implicitly cast to pointer to 234c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // function. As a result, we try and obtain the DeclRefExpr from the 235c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff // ImplicitCastExpr. 236c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee()); 237c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()). 238cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 239cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 240c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()); 241c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff if (!DRE) 242cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 243cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 244bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl()); 245bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson if (!FDecl) 246cb888967400a03504c88acedd5248d6778a82f46Chris Lattner return 0; 247cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 2484fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor if (!FDecl->getIdentifier()) 2494fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor return 0; 2504fcd399a52ae45ed8ebfdd3a25e01cfb76fa366dDouglas Gregor 2513c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor return FDecl->getBuiltinID(Context); 252cb888967400a03504c88acedd5248d6778a82f46Chris Lattner} 253bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson 2546dde78f744382a5627a04f984a97049e0c4b5e73Anders CarlssonQualType CallExpr::getCallReturnType() const { 2556dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType CalleeType = getCallee()->getType(); 2566217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *FnTypePtr = CalleeType->getAs<PointerType>()) 2576dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = FnTypePtr->getPointeeType(); 2586217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek else if (const BlockPointerType *BPT = CalleeType->getAs<BlockPointerType>()) 2596dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson CalleeType = BPT->getPointeeType(); 2606dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson 2616dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson const FunctionType *FnType = CalleeType->getAsFunctionType(); 2626dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson return FnType->getResultType(); 2636dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson} 264cb888967400a03504c88acedd5248d6778a82f46Chris Lattner 26583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas GregorMemberExpr::MemberExpr(Expr *base, bool isarrow, NestedNameSpecifier *qual, 26683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor SourceRange qualrange, NamedDecl *memberdecl, 267c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation l, bool has_explicit, 268c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation langle, 269c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor const TemplateArgument *targs, unsigned numtargs, 270c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation rangle, QualType ty) 27183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor : Expr(MemberExprClass, ty, 27283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor base->isTypeDependent() || (qual && qual->isDependent()), 27383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor base->isValueDependent() || (qual && qual->isDependent())), 27483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor Base(base), MemberDecl(memberdecl), MemberLoc(l), IsArrow(isarrow), 275c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor HasQualifier(qual != 0), HasExplicitTemplateArgumentList(has_explicit) { 27683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor // Initialize the qualifier, if any. 27783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (HasQualifier) { 27883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NameQualifier *NQ = getMemberQualifier(); 27983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NQ->NNS = qual; 28083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NQ->Range = qualrange; 28183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 282c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 283c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor // Initialize the explicit template argument list, if any. 284c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (HasExplicitTemplateArgumentList) { 285c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor ExplicitTemplateArgumentList *ETemplateArgs 286c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor = getExplicitTemplateArgumentList(); 287c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor ETemplateArgs->LAngleLoc = langle; 288c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor ETemplateArgs->RAngleLoc = rangle; 289c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor ETemplateArgs->NumTemplateArgs = numtargs; 290c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 291c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor TemplateArgument *TemplateArgs = ETemplateArgs->getTemplateArgs(); 292c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor for (unsigned I = 0; I < numtargs; ++I) 293c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor new (TemplateArgs + I) TemplateArgument(targs[I]); 294c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor } 29583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor} 29683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 29783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas GregorMemberExpr *MemberExpr::Create(ASTContext &C, Expr *base, bool isarrow, 29883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NestedNameSpecifier *qual, 29983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor SourceRange qualrange, 30083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NamedDecl *memberdecl, 301c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation l, 302c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor bool has_explicit, 303c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation langle, 304c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor const TemplateArgument *targs, 305c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor unsigned numtargs, 306c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor SourceLocation rangle, 307c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor QualType ty) { 30883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor std::size_t Size = sizeof(MemberExpr); 30983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (qual != 0) 31083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor Size += sizeof(NameQualifier); 31183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 312c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (has_explicit) 313c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor Size += sizeof(ExplicitTemplateArgumentList) + 314c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor sizeof(TemplateArgument) * numtargs; 315c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor 31683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor void *Mem = C.Allocate(Size, llvm::alignof<MemberExpr>()); 317c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor return new (Mem) MemberExpr(base, isarrow, qual, qualrange, memberdecl, l, 318c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor has_explicit, langle, targs, numtargs, rangle, 31983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor ty); 32083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor} 32183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 322f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlssonconst char *CastExpr::getCastKindName() const { 323f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson switch (getCastKind()) { 324f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_Unknown: 325f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Unknown"; 326f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_BitCast: 327f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BitCast"; 328f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_NoOp: 329f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NoOp"; 330f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_DerivedToBase: 331f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "DerivedToBase"; 332f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_Dynamic: 333f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "Dynamic"; 334f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_ToUnion: 335f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ToUnion"; 336f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_ArrayToPointerDecay: 337f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ArrayToPointerDecay"; 338f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_FunctionToPointerDecay: 339f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "FunctionToPointerDecay"; 340f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_NullToMemberPointer: 341f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "NullToMemberPointer"; 342f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_BaseToDerivedMemberPointer: 343f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "BaseToDerivedMemberPointer"; 344f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_UserDefinedConversion: 345f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "UserDefinedConversion"; 346f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson case CastExpr::CK_ConstructorConversion: 347f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return "ConstructorConversion"; 348f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson } 349f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 350f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson assert(0 && "Unhandled cast kind!"); 351f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson return 0; 352f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson} 353f8ec55a104e55961f8666f773dce99bbc628298fAnders Carlsson 3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it 3555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=". 3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *BinaryOperator::getOpcodeStr(Opcode Op) { 3575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Op) { 358baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor case PtrMemD: return ".*"; 359baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor case PtrMemI: return "->*"; 3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Mul: return "*"; 3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Div: return "/"; 3625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Rem: return "%"; 3635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Add: return "+"; 3645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Sub: return "-"; 3655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Shl: return "<<"; 3665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Shr: return ">>"; 3675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LT: return "<"; 3685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case GT: return ">"; 3695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LE: return "<="; 3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case GE: return ">="; 3715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case EQ: return "=="; 3725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case NE: return "!="; 3735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case And: return "&"; 3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Xor: return "^"; 3755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Or: return "|"; 3765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LAnd: return "&&"; 3775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LOr: return "||"; 3785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Assign: return "="; 3795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MulAssign: return "*="; 3805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case DivAssign: return "/="; 3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case RemAssign: return "%="; 3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case AddAssign: return "+="; 3835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case SubAssign: return "-="; 3845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ShlAssign: return "<<="; 3855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ShrAssign: return ">>="; 3865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case AndAssign: return "&="; 3875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case XorAssign: return "^="; 3885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case OrAssign: return "|="; 3895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case Comma: return ","; 3905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 391baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor 392baf534875ed0a55c6342636ff3f4602b8ac22b69Douglas Gregor return ""; 3935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 3945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 395063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::Opcode 396063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorBinaryOperator::getOverloadedOpcode(OverloadedOperatorKind OO) { 397063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor switch (OO) { 398b7beee9f2b52f34a3b0800a5f0038f0e4295b260Chris Lattner default: assert(false && "Not an overloadable binary operator"); 399063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Plus: return Add; 400063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Minus: return Sub; 401063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Star: return Mul; 402063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Slash: return Div; 403063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Percent: return Rem; 404063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Caret: return Xor; 405063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Amp: return And; 406063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Pipe: return Or; 407063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Equal: return Assign; 408063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Less: return LT; 409063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Greater: return GT; 410063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_PlusEqual: return AddAssign; 411063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_MinusEqual: return SubAssign; 412063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_StarEqual: return MulAssign; 413063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_SlashEqual: return DivAssign; 414063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_PercentEqual: return RemAssign; 415063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_CaretEqual: return XorAssign; 416063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_AmpEqual: return AndAssign; 417063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_PipeEqual: return OrAssign; 418063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_LessLess: return Shl; 419063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_GreaterGreater: return Shr; 420063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_LessLessEqual: return ShlAssign; 421063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_GreaterGreaterEqual: return ShrAssign; 422063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_EqualEqual: return EQ; 423063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_ExclaimEqual: return NE; 424063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_LessEqual: return LE; 425063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_GreaterEqual: return GE; 426063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_AmpAmp: return LAnd; 427063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_PipePipe: return LOr; 428063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_Comma: return Comma; 429063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor case OO_ArrowStar: return PtrMemI; 430063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor } 431063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 432063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 433063daf6e196c51f162e0485478355d8e280eef5cDouglas GregorOverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) { 434063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor static const OverloadedOperatorKind OverOps[] = { 435063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor /* .* Cannot be overloaded */OO_None, OO_ArrowStar, 436063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Star, OO_Slash, OO_Percent, 437063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Plus, OO_Minus, 438063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLess, OO_GreaterGreater, 439063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Less, OO_Greater, OO_LessEqual, OO_GreaterEqual, 440063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_EqualEqual, OO_ExclaimEqual, 441063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Amp, 442063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Caret, 443063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Pipe, 444063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpAmp, 445063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipePipe, 446063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Equal, OO_StarEqual, 447063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_SlashEqual, OO_PercentEqual, 448063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PlusEqual, OO_MinusEqual, 449063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_LessLessEqual, OO_GreaterGreaterEqual, 450063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_AmpEqual, OO_CaretEqual, 451063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_PipeEqual, 452063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor OO_Comma 453063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor }; 454063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor return OverOps[Opc]; 455063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor} 456063daf6e196c51f162e0485478355d8e280eef5cDouglas Gregor 45766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonInitListExpr::InitListExpr(SourceLocation lbraceloc, 458418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner Expr **initExprs, unsigned numInits, 4594c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor SourceLocation rbraceloc) 4609ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor : Expr(InitListExprClass, QualType(), 4619ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor hasAnyTypeDependentArguments(initExprs, numInits), 4629ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor hasAnyValueDependentArguments(initExprs, numInits)), 4630bb76897bedb8b747efc6523efb432fc24966118Douglas Gregor LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0), 464a9c878086036de36482cc21e35a33cabe9699b0aDouglas Gregor UnionFieldInit(0), HadArrayRangeDesignator(false) { 465418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner 466418f6c7d142e5ff4607f70cd8431d008442bafe9Chris Lattner InitExprs.insert(InitExprs.end(), initExprs, initExprs+numInits); 46766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 469fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregorvoid InitListExpr::reserveInits(unsigned NumInits) { 470fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor if (NumInits > InitExprs.size()) 471fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor InitExprs.reserve(NumInits); 472fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor} 473fa2192042f223b5122a9e17719930f77634fd31fDouglas Gregor 4744c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregorvoid InitListExpr::resizeInits(ASTContext &Context, unsigned NumInits) { 475d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner for (unsigned Idx = NumInits, LastIdx = InitExprs.size(); 476f592c929bd1f083abcc8199b24bb825fdd28df1cDaniel Dunbar Idx < LastIdx; ++Idx) 477068636800594844c53fba0bc871c579745757d0eDouglas Gregor InitExprs[Idx]->Destroy(Context); 4784c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs.resize(NumInits, 0); 4794c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 4804c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 4814c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas GregorExpr *InitListExpr::updateInit(unsigned Init, Expr *expr) { 4824c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor if (Init >= InitExprs.size()) { 4834c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs.insert(InitExprs.end(), Init - InitExprs.size() + 1, 0); 4844c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs.back() = expr; 4854c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return 0; 4864c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor } 4874c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 4884c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor Expr *Result = cast_or_null<Expr>(InitExprs[Init]); 4894c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor InitExprs[Init] = expr; 4904c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor return Result; 4914c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor} 4924c67834407ca6ab344dcf44fc599ad4938cfa96dDouglas Gregor 493bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block. 4944eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff/// 4954eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffconst FunctionType *BlockExpr::getFunctionType() const { 4966217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek return getType()->getAs<BlockPointerType>()-> 4974eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff getPointeeType()->getAsFunctionType(); 4984eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff} 4994eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 50056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffSourceLocation BlockExpr::getCaretLocation() const { 50156ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff return TheBlock->getCaretLocation(); 50256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff} 5037297134f128423fce2e88f92421ed135bded7d4eDouglas Gregorconst Stmt *BlockExpr::getBody() const { 5047297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor return TheBlock->getBody(); 5057297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 5067297134f128423fce2e88f92421ed135bded7d4eDouglas GregorStmt *BlockExpr::getBody() { 5077297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor return TheBlock->getBody(); 5087297134f128423fce2e88f92421ed135bded7d4eDouglas Gregor} 50956ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 51056ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff 5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 5125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines 5135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 515026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// isUnusedResultAWarning - Return true if this immediate expression should 516026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// be warned about if the result is unused. If so, fill in Loc and Ranges 517026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// with location to warn on and the source range[s] to report with the 518026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner/// warning. 519026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattnerbool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, 52040b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis SourceRange &R2) const { 521ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // Don't warn if the expr is type dependent. The type could end up 522ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson // instantiating to void. 523ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson if (isTypeDependent()) 524ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson return false; 525ffce2df6ae280d354d51371282a579df1eb86876Anders Carlsson 5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getStmtClass()) { 5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 528026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = getExprLoc(); 529026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 530026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ParenExprClass: 532026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return cast<ParenExpr>(this)->getSubExpr()-> 53340b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis isUnusedResultAWarning(Loc, R1, R2); 5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperatorClass: { 5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const UnaryOperator *UO = cast<UnaryOperator>(this); 5365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (UO->getOpcode()) { 538026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner default: break; 5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::PostInc: 5405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::PostDec: 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::PreInc: 542026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner case UnaryOperator::PreDec: // ++/-- 543026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; // Not a warning. 5445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Deref: 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Dereferencing a volatile pointer is a side-effect. 546026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (getType().isVolatileQualified()) 547026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 548026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 5495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Real: 5505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Imag: 5515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // accessing a piece of a volatile complex is a side-effect. 552026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (UO->getSubExpr()->getType().isVolatileQualified()) 553026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 554026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner break; 5555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Extension: 55640b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2); 5575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 558026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = UO->getOperatorLoc(); 559026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = UO->getSubExpr()->getSourceRange(); 560026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 562e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner case BinaryOperatorClass: { 563026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const BinaryOperator *BO = cast<BinaryOperator>(this); 564026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // Consider comma to have side effects if the LHS or RHS does. 565026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (BO->getOpcode() == BinaryOperator::Comma) 56640b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2) || 56740b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2); 568e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner 569026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (BO->isAssignmentOp()) 570026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 571026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = BO->getOperatorLoc(); 572026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = BO->getLHS()->getSourceRange(); 573026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = BO->getRHS()->getSourceRange(); 574026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 575e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner } 576eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner case CompoundAssignOperatorClass: 577026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 5785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 579ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian case ConditionalOperatorClass: { 580026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // The condition must be evaluated, but if either the LHS or RHS is a 581026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // warning, warn about them. 582ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian const ConditionalOperator *Exp = cast<ConditionalOperator>(this); 58368584ed35ad819a1668e3f527ba7f5dd4ae6a333Douglas Gregor if (Exp->getLHS() && 58440b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2)) 585026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 58640b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2); 587ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian } 588ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian 5895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case MemberExprClass: 590026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the base pointer or element is to a volatile pointer/field, accessing 591026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // it is a side effect. 592026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (getType().isVolatileQualified()) 593026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 594026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<MemberExpr>(this)->getMemberLoc(); 595026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = SourceRange(Loc, Loc); 596026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<MemberExpr>(this)->getBase()->getSourceRange(); 597026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 598026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner 5995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ArraySubscriptExprClass: 6005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If the base pointer or element is to a volatile pointer/field, accessing 601026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // it is a side effect. 602026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (getType().isVolatileQualified()) 603026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 604026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc(); 605026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange(); 606026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange(); 607026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 608211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman 6095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case CallExprClass: 610852871abbff45f1c1d3787755a27fce08365b166Eli Friedman case CXXOperatorCallExprClass: 611852871abbff45f1c1d3787755a27fce08365b166Eli Friedman case CXXMemberCallExprClass: { 612026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If this is a direct call, get the callee. 613026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const CallExpr *CE = cast<CallExpr>(this); 614026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner const Expr *CalleeExpr = CE->getCallee()->IgnoreParenCasts(); 615026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (const DeclRefExpr *CalleeDRE = dyn_cast<DeclRefExpr>(CalleeExpr)) { 616026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // If the callee has attribute pure, const, or warn_unused_result, warn 617026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner // about it. void foo() { strlen("bar"); } should warn. 618026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CalleeDRE->getDecl())) 61940b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis if (FD->getAttr<WarnUnusedResultAttr>() || 62040b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) { 621026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = CE->getCallee()->getLocStart(); 622026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = CE->getCallee()->getSourceRange(); 623026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner 624026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (unsigned NumArgs = CE->getNumArgs()) 625026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R2 = SourceRange(CE->getArg(0)->getLocStart(), 626026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner CE->getArg(NumArgs-1)->getLocEnd()); 627026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 628026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 629026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 630026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 631026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner } 632a9c01021724b9b546d282b8609cbe559734812ecChris Lattner case ObjCMessageExprClass: 633026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 634a50089ec68a583d13718107c1b0c898f0903709eChris Lattner 63509105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian case ObjCImplicitSetterGetterRefExprClass: { // Dot syntax for message send. 636a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#if 0 63709105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian const ObjCImplicitSetterGetterRefExpr *Ref = 63809105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian cast<ObjCImplicitSetterGetterRefExpr>(this); 639a50089ec68a583d13718107c1b0c898f0903709eChris Lattner // FIXME: We really want the location of the '.' here. 640154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian Loc = Ref->getLocation(); 641154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian R1 = SourceRange(Ref->getLocation(), Ref->getLocation()); 642154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian if (Ref->getBase()) 643154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian R2 = Ref->getBase()->getSourceRange(); 6445e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner#else 6455e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner Loc = getExprLoc(); 6465e94a0d82b1f49be41c35a73106b219e3f588c8cChris Lattner R1 = getSourceRange(); 647a50089ec68a583d13718107c1b0c898f0903709eChris Lattner#endif 648a50089ec68a583d13718107c1b0c898f0903709eChris Lattner return true; 649a50089ec68a583d13718107c1b0c898f0903709eChris Lattner } 650611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner case StmtExprClass: { 651611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // Statement exprs don't logically have side effects themselves, but are 652611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // sometimes used in macros in ways that give them a type that is unused. 653611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // For example ({ blah; foo(); }) will end up with a type if foo has a type. 654611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // however, if the result of the stmt expr is dead, we don't want to emit a 655611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner // warning. 656611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt(); 657611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (!CS->body_empty()) 658611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner if (const Expr *E = dyn_cast<Expr>(CS->body_back())) 65940b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis return E->isUnusedResultAWarning(Loc, R1, R2); 660026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner 661026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<StmtExpr>(this)->getLParenLoc(); 662026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = getSourceRange(); 663026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 664611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner } 6656eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor case CStyleCastExprClass: 666fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner // If this is an explicit cast to void, allow it. People do this when they 667fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner // think they know what they're doing :). 668026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner if (getType()->isVoidType()) 669fb84664349ca6f37f5ec4df440f6c362cca62470Chris Lattner return false; 670026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<CStyleCastExpr>(this)->getLParenLoc(); 671026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange(); 672026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 673987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis case CXXFunctionalCastExprClass: 6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If this is a cast to void, check the operand. Otherwise, the result of 6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // the cast is unused. 6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (getType()->isVoidType()) 67768584ed35ad819a1668e3f527ba7f5dd4ae6a333Douglas Gregor return cast<CastExpr>(this)->getSubExpr() 67840b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis ->isUnusedResultAWarning(Loc, R1, R2); 679026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc(); 680026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange(); 681026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return true; 682026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner 6834be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman case ImplicitCastExprClass: 6844be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman // Check the operand, since implicit casts are inserted by Sema 685026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return cast<ImplicitCastExpr>(this) 68640b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2); 6874be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman 68804421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner case CXXDefaultArgExprClass: 689026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return cast<CXXDefaultArgExpr>(this) 69040b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis ->getExpr()->isUnusedResultAWarning(Loc, R1, R2); 6914c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl 6924c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXNewExprClass: 6934c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // FIXME: In theory, there might be new expressions that don't have side 6944c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl // effects (e.g. a placement new with an uninitialized POD). 6954c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl case CXXDeleteExprClass: 696026dc96ac6ece60da5e1b98e2a71bd0ff0939fd8Chris Lattner return false; 6972d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson case CXXBindTemporaryExprClass: 6982d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson return cast<CXXBindTemporaryExpr>(this) 6992d46eb21eb2c904831b0e9f75ab3523384c70e66Anders Carlsson ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2); 7006b1d283fe879fb11d7ce7a69feecf66e77b0eaf3Anders Carlsson case CXXExprWithTemporariesClass: 7016b1d283fe879fb11d7ce7a69feecf66e77b0eaf3Anders Carlsson return cast<CXXExprWithTemporaries>(this) 70240b598eea1310ec9ed554d56ce3e25b34c585458Argyrios Kyrtzidis ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2); 7034c5d320a7581f4b80b151630c91cea5727fa9923Sebastian Redl } 7045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 7055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 706ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor/// DeclCanBeLvalue - Determine whether the given declaration can be 707ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor/// an lvalue. This is a helper routine for isLvalue. 708ba7e210a999275695f58be03ef402758cfec3635Douglas Gregorstatic bool DeclCanBeLvalue(const NamedDecl *Decl, ASTContext &Ctx) { 70972c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor // C++ [temp.param]p6: 71072c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor // A non-type non-reference template-parameter is not an lvalue. 71172c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor if (const NonTypeTemplateParmDecl *NTTParm 71272c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor = dyn_cast<NonTypeTemplateParmDecl>(Decl)) 71372c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor return NTTParm->getType()->isReferenceType(); 71472c3f314d92d65c050ee1c07b7753623c044d6c7Douglas Gregor 71544b4321feab46299d3f5cfd404680884752a0fcfDouglas Gregor return isa<VarDecl>(Decl) || isa<FieldDecl>(Decl) || 716ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor // C++ 3.10p2: An lvalue refers to an object or function. 717ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor (Ctx.getLangOptions().CPlusPlus && 71883314aa1cf61ed2458a8a20c83b2d4708192d5dcDouglas Gregor (isa<FunctionDecl>(Decl) || isa<OverloadedFunctionDecl>(Decl) || 71983314aa1cf61ed2458a8a20c83b2d4708192d5dcDouglas Gregor isa<FunctionTemplateDecl>(Decl))); 720ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor} 721ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor 7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or an 7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// incomplete type other than void. Nonarray expressions that can be lvalues: 7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - name, where name must be a variable 7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - e[i] 7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - (e), where e must be an lvalue 7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - e.name, where e must be an lvalue 7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - e->name 7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - *e, the type of e cannot be a function type 7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// - string-constant 7317da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner/// - (__real__ e) and (__imag__ e) where e is an lvalue [GNU extension] 73208ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling/// - reference type [C++ [expr]] 7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 73428be73f74c9e241a23ea24fe5756623de6bf1084Chris LattnerExpr::isLvalueResult Expr::isLvalue(ASTContext &Ctx) const { 73553202857c60214d80950a975e6e52aebf30bd16aEli Friedman assert(!TR->isReferenceType() && "Expressions can't have reference type."); 73653202857c60214d80950a975e6e52aebf30bd16aEli Friedman 73753202857c60214d80950a975e6e52aebf30bd16aEli Friedman isLvalueResult Res = isLvalueInternal(Ctx); 73853202857c60214d80950a975e6e52aebf30bd16aEli Friedman if (Res != LV_Valid || Ctx.getLangOptions().CPlusPlus) 73953202857c60214d80950a975e6e52aebf30bd16aEli Friedman return Res; 74053202857c60214d80950a975e6e52aebf30bd16aEli Friedman 74198cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor // first, check the type (C99 6.3.2.1). Expressions with function 74298cd599ee8a9b259ed7388ee2921a20d97658864Douglas Gregor // type in C are not lvalues, but they can be lvalues in C++. 74383314aa1cf61ed2458a8a20c83b2d4708192d5dcDouglas Gregor if (TR->isFunctionType() || TR == Ctx.OverloadTy) 7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return LV_NotObjectType; 7455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 746acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff // Allow qualified void which is an incomplete type other than void (yuck). 74728be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner if (TR->isVoidType() && !Ctx.getCanonicalType(TR).getCVRQualifiers()) 748acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff return LV_IncompleteVoidType; 749acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff 75053202857c60214d80950a975e6e52aebf30bd16aEli Friedman return LV_Valid; 75153202857c60214d80950a975e6e52aebf30bd16aEli Friedman} 75208ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling 75353202857c60214d80950a975e6e52aebf30bd16aEli Friedman// Check whether the expression can be sanely treated like an l-value 75453202857c60214d80950a975e6e52aebf30bd16aEli FriedmanExpr::isLvalueResult Expr::isLvalueInternal(ASTContext &Ctx) const { 7555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (getStmtClass()) { 756eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case StringLiteralClass: // C99 6.5.1p4 757eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case ObjCEncodeExprClass: // @encode behaves like its string in every way. 7587323a6297edad643c202594dcf3d9a174de96ca6Anders Carlsson return LV_Valid; 7595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2)))) 7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // For vectors, make sure base is an lvalue (i.e. not a function call). 7615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType()) 76228be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue(Ctx); 7635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return LV_Valid; 7641a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor case DeclRefExprClass: 7651a49af9681c350fef58e677f85ccb9a77e8e9d0aDouglas Gregor case QualifiedDeclRefExprClass: { // C99 6.5.1p2 766ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor const NamedDecl *RefdDecl = cast<DeclRefExpr>(this)->getDecl(); 767ba7e210a999275695f58be03ef402758cfec3635Douglas Gregor if (DeclCanBeLvalue(RefdDecl, Ctx)) 7685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return LV_Valid; 7695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 7704111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner } 771dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff case BlockDeclRefExprClass: { 772dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this); 7734f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff if (isa<VarDecl>(BDR->getDecl())) 774dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff return LV_Valid; 775dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff break; 776dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff } 77783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor case MemberExprClass: { 7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const MemberExpr *m = cast<MemberExpr>(this); 77986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (Ctx.getLangOptions().CPlusPlus) { // C++ [expr.ref]p4: 78086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor NamedDecl *Member = m->getMemberDecl(); 78186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // C++ [expr.ref]p4: 78286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // If E2 is declared to have type "reference to T", then E1.E2 78386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // is an lvalue. 78486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (ValueDecl *Value = dyn_cast<ValueDecl>(Member)) 78586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (Value->getType()->isReferenceType()) 78686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor return LV_Valid; 78786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 78886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // -- If E2 is a static data member [...] then E1.E2 is an lvalue. 7892d2e9cfdc1dbb6e4a22f8c0b1abcd30437e3795dDouglas Gregor if (isa<VarDecl>(Member) && Member->getDeclContext()->isRecord()) 79086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor return LV_Valid; 79186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 79286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // -- If E2 is a non-static data member [...]. If E1 is an 79386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // lvalue, then E1.E2 is an lvalue. 79486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (isa<FieldDecl>(Member)) 79586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(Ctx); 79686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 79786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // -- If it refers to a static member function [...], then 79886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // E1.E2 is an lvalue. 79986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // -- Otherwise, if E1.E2 refers to a non-static member 80086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // function [...], then E1.E2 is not an lvalue. 80186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Member)) 80286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor return Method->isStatic()? LV_Valid : LV_MemberFunction; 80386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 80486f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // -- If E2 is a member enumerator [...], the expression E1.E2 80586f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // is not an lvalue. 80686f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (isa<EnumConstantDecl>(Member)) 80786f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor return LV_InvalidExpression; 80886f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 80986f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // Not an lvalue. 81086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor return LV_InvalidExpression; 81186f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor } 81286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor 81386f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor // C99 6.5.2.3p4 81428be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(Ctx); 815fdd75663fffeb2058a7847975e50837e61200593Anton Korobeynikov } 8167da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner case UnaryOperatorClass: 8175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref) 8187da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner return LV_Valid; // C99 6.5.3p4 8197da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner 8207da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real || 821baf0d6678418e0dd9309438c3e50274253cfc7b2Chris Lattner cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag || 822baf0d6678418e0dd9309438c3e50274253cfc7b2Chris Lattner cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Extension) 82328be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(Ctx); // GNU. 82474253736184c0717a0649922551bf9d8b6815651Douglas Gregor 82574253736184c0717a0649922551bf9d8b6815651Douglas Gregor if (Ctx.getLangOptions().CPlusPlus && // C++ [expr.pre.incr]p1 82674253736184c0717a0649922551bf9d8b6815651Douglas Gregor (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::PreInc || 82774253736184c0717a0649922551bf9d8b6815651Douglas Gregor cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::PreDec)) 82874253736184c0717a0649922551bf9d8b6815651Douglas Gregor return LV_Valid; 8295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 830eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor case ImplicitCastExprClass: 831eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor return cast<ImplicitCastExpr>(this)->isLvalueCast()? LV_Valid 832eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor : LV_InvalidExpression; 8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case ParenExprClass: // C99 6.5.1p5 83428be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner return cast<ParenExpr>(this)->getSubExpr()->isLvalue(Ctx); 835eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor case BinaryOperatorClass: 836eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor case CompoundAssignOperatorClass: { 837eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor const BinaryOperator *BinOp = cast<BinaryOperator>(this); 838337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor 839337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor if (Ctx.getLangOptions().CPlusPlus && // C++ [expr.comma]p1 840337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor BinOp->getOpcode() == BinaryOperator::Comma) 841337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor return BinOp->getRHS()->isLvalue(Ctx); 842337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor 843224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl // C++ [expr.mptr.oper]p6 844224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl if ((BinOp->getOpcode() == BinaryOperator::PtrMemD || 845224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl BinOp->getOpcode() == BinaryOperator::PtrMemI) && 846224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl !BinOp->getType()->isFunctionType()) 847224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl return BinOp->getLHS()->isLvalue(Ctx); 848224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl 849bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor if (!BinOp->isAssignmentOp()) 850eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor return LV_InvalidExpression; 851eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor 852bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor if (Ctx.getLangOptions().CPlusPlus) 853bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor // C++ [expr.ass]p1: 854bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor // The result of an assignment operation [...] is an lvalue. 855bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor return LV_Valid; 856bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor 857bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor 858bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor // C99 6.5.16: 859bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor // An assignment expression [...] is not an lvalue. 860bf3af056289893f58d37b05a2c80970708781d61Douglas Gregor return LV_InvalidExpression; 861eb8f3063257a392f15aea48d42fb73ec51afc548Douglas Gregor } 862b4609806e9232593ece09ce08b630836e825865cDouglas Gregor case CallExprClass: 86388a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor case CXXOperatorCallExprClass: 86488a3514f36de96b19cdf50141c640df1a5f13f6cDouglas Gregor case CXXMemberCallExprClass: { 8657c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // C++0x [expr.call]p10 8669d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // A function call is an lvalue if and only if the result type 8677c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // is an lvalue reference. 8686dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson QualType ReturnType = cast<CallExpr>(this)->getCallReturnType(); 8696dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson if (ReturnType->isLValueReferenceType()) 8706dde78f744382a5627a04f984a97049e0c4b5e73Anders Carlsson return LV_Valid; 8717c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl 8729d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor break; 8739d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor } 874e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff case CompoundLiteralExprClass: // C99 6.5.2.5p5 875e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff return LV_Valid; 876670a62cd1d51042ea076cda5e93f26a1d8327fb3Chris Lattner case ChooseExprClass: 877670a62cd1d51042ea076cda5e93f26a1d8327fb3Chris Lattner // __builtin_choose_expr is an lvalue if the selected operand is. 8787976932a1c256d447316ffac58e9821417725e34Eli Friedman return cast<ChooseExpr>(this)->getChosenSubExpr(Ctx)->isLvalue(Ctx); 879213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman case ExtVectorElementExprClass: 880213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman if (cast<ExtVectorElementExpr>(this)->containsDuplicateElements()) 881fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return LV_DuplicateVectorComponents; 882fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return LV_Valid; 883027282d1c1ac151aa7b1b3b45babc918b8ad456aSteve Naroff case ObjCIvarRefExprClass: // ObjC instance variables are lvalues. 884027282d1c1ac151aa7b1b3b45babc918b8ad456aSteve Naroff return LV_Valid; 885799a6a6850af625946bb8d88ca960bb6604e3858Steve Naroff case ObjCPropertyRefExprClass: // FIXME: check if read-only property. 886799a6a6850af625946bb8d88ca960bb6604e3858Steve Naroff return LV_Valid; 88709105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian case ObjCImplicitSetterGetterRefExprClass: // FIXME: check if read-only property. 888670a62cd1d51042ea076cda5e93f26a1d8327fb3Chris Lattner return LV_Valid; 889d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner case PredefinedExprClass: 890796da18402f286b897782a298ae3b20c459c102eDouglas Gregor return LV_Valid; 89104421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner case CXXDefaultArgExprClass: 89228be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner return cast<CXXDefaultArgExpr>(this)->getExpr()->isLvalue(Ctx); 89324b41fa8239c63b9eb570d3e83c4a82840656a65Argyrios Kyrtzidis case CXXConditionDeclExprClass: 89424b41fa8239c63b9eb570d3e83c4a82840656a65Argyrios Kyrtzidis return LV_Valid; 8956eec8e883de118b431e3ead5b1e604a6ac68ff6bDouglas Gregor case CStyleCastExprClass: 8969d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor case CXXFunctionalCastExprClass: 8979d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor case CXXStaticCastExprClass: 8989d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor case CXXDynamicCastExprClass: 8999d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor case CXXReinterpretCastExprClass: 9009d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor case CXXConstCastExprClass: 9019d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // The result of an explicit cast is an lvalue if the type we are 9027c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl // casting to is an lvalue reference type. See C++ [expr.cast]p1, 9039d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // C++ [expr.static.cast]p2, C++ [expr.dynamic.cast]p2, 9049d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor // C++ [expr.reinterpret.cast]p1, C++ [expr.const.cast]p1. 9057c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl if (cast<ExplicitCastExpr>(this)->getTypeAsWritten()-> 9067c80bd64032e610c0dbd74fc0ef6ea334447f2fdSebastian Redl isLValueReferenceType()) 9079d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor return LV_Valid; 9089d293dfc0ad7c44ae0b5eb9517f1ed8c8d8b7ff7Douglas Gregor break; 909c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl case CXXTypeidExprClass: 910c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl // C++ 5.2.8p1: The result of a typeid expression is an lvalue of ... 911c42e1183846228a7fa5143ad76507d6d60f5c6f3Sebastian Redl return LV_Valid; 9126f68027af2b6ce294a2706f23a1d3cb7ca1b8d37Anders Carlsson case CXXBindTemporaryExprClass: 9136f68027af2b6ce294a2706f23a1d3cb7ca1b8d37Anders Carlsson return cast<CXXBindTemporaryExpr>(this)->getSubExpr()-> 9146f68027af2b6ce294a2706f23a1d3cb7ca1b8d37Anders Carlsson isLvalueInternal(Ctx); 91576458501a8963fa11b91c9337a487de6871169b4Sebastian Redl case ConditionalOperatorClass: { 91676458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // Complicated handling is only for C++. 91776458501a8963fa11b91c9337a487de6871169b4Sebastian Redl if (!Ctx.getLangOptions().CPlusPlus) 91876458501a8963fa11b91c9337a487de6871169b4Sebastian Redl return LV_InvalidExpression; 91976458501a8963fa11b91c9337a487de6871169b4Sebastian Redl 92076458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // Sema should have taken care to ensure that a CXXTemporaryObjectExpr is 92176458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // everywhere there's an object converted to an rvalue. Also, any other 92276458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // casts should be wrapped by ImplicitCastExprs. There's just the special 92376458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // case involving throws to work out. 92476458501a8963fa11b91c9337a487de6871169b4Sebastian Redl const ConditionalOperator *Cond = cast<ConditionalOperator>(this); 925d5f3a0fde43bca9f3738aed931b0f13ca73a9f11Douglas Gregor Expr *True = Cond->getTrueExpr(); 926d5f3a0fde43bca9f3738aed931b0f13ca73a9f11Douglas Gregor Expr *False = Cond->getFalseExpr(); 92776458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // C++0x 5.16p2 92876458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // If either the second or the third operand has type (cv) void, [...] 92976458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // the result [...] is an rvalue. 930d5f3a0fde43bca9f3738aed931b0f13ca73a9f11Douglas Gregor if (True->getType()->isVoidType() || False->getType()->isVoidType()) 93176458501a8963fa11b91c9337a487de6871169b4Sebastian Redl return LV_InvalidExpression; 93276458501a8963fa11b91c9337a487de6871169b4Sebastian Redl 93376458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // Both sides must be lvalues for the result to be an lvalue. 934d5f3a0fde43bca9f3738aed931b0f13ca73a9f11Douglas Gregor if (True->isLvalue(Ctx) != LV_Valid || False->isLvalue(Ctx) != LV_Valid) 93576458501a8963fa11b91c9337a487de6871169b4Sebastian Redl return LV_InvalidExpression; 93676458501a8963fa11b91c9337a487de6871169b4Sebastian Redl 93776458501a8963fa11b91c9337a487de6871169b4Sebastian Redl // That's it. 93876458501a8963fa11b91c9337a487de6871169b4Sebastian Redl return LV_Valid; 93976458501a8963fa11b91c9337a487de6871169b4Sebastian Redl } 94076458501a8963fa11b91c9337a487de6871169b4Sebastian Redl 9415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer break; 9435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 9445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return LV_InvalidExpression; 9455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 9465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type, 9485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// does not have an incomplete type, does not have a const-qualified type, and 9495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// if it is a structure or union, does not have any member (including, 9505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// recursively, any member or element of all contained aggregates or unions) 9515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with a const-qualified type. 95244e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel DunbarExpr::isModifiableLvalueResult 95344e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel DunbarExpr::isModifiableLvalue(ASTContext &Ctx, SourceLocation *Loc) const { 95428be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner isLvalueResult lvalResult = isLvalue(Ctx); 9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (lvalResult) { 957ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor case LV_Valid: 958ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor // C++ 3.10p11: Functions cannot be modified, but pointers to 959ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor // functions can be modifiable. 960ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor if (Ctx.getLangOptions().CPlusPlus && TR->isFunctionType()) 961ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor return MLV_NotObjectType; 962ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor break; 963ae8d467e75a4e72b19e1eca199bf93dfaab47acfDouglas Gregor 9645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LV_NotObjectType: return MLV_NotObjectType; 9655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case LV_IncompleteVoidType: return MLV_IncompleteVoidType; 966fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents; 967ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner case LV_InvalidExpression: 968ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner // If the top level is a C-style cast, and the subexpression is a valid 969ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner // lvalue, then this is probably a use of the old-school "cast as lvalue" 970ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner // GCC extension. We don't support it, but we want to produce good 971ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner // diagnostics when it happens so that the user knows why. 97244e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar if (const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(IgnoreParens())) { 97344e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar if (CE->getSubExpr()->isLvalue(Ctx) == LV_Valid) { 97444e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar if (Loc) 97544e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar *Loc = CE->getLParenLoc(); 976ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner return MLV_LValueCast; 97744e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar } 97844e35f7b2b5da1eb338639e46bf0b5522e75c5f3Daniel Dunbar } 979ca354faa7e9b99af17070c82b9662a5fca76422cChris Lattner return MLV_InvalidExpression; 98086f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor case LV_MemberFunction: return MLV_MemberFunction; 9815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 98204831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman 98304831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman // The following is illegal: 98404831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman // void takeclosure(void (^C)(void)); 98504831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman // void func() { int x = 1; takeclosure(^{ x = 7; }); } 98604831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman // 9877fd0995e993438a3a1f5408d8549b3af0009ff30Chris Lattner if (isa<BlockDeclRefExpr>(this)) { 98804831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this); 98904831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl())) 99004831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman return MLV_NotBlockQualified; 99104831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman } 99204831aa3271edc5f00a651bf7152c2902981d7c3Eli Friedman 993c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner QualType CT = Ctx.getCanonicalType(getType()); 994c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner 995c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (CT.isConstQualified()) 9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return MLV_ConstQualified; 997c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (CT->isArrayType()) 9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return MLV_ArrayType; 999c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner if (CT->isIncompleteType()) 10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return MLV_IncompleteType; 10015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 10026217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const RecordType *r = CT->getAs<RecordType>()) { 10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (r->hasConstFields()) 10045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return MLV_ConstQualified; 10055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1006d1fa6449e9dbdd667466e9e1e971aa17c9793e8aFariborz Jahanian 1007ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian // Assigning to an 'implicit' property? 100809105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian else if (isa<ObjCImplicitSetterGetterRefExpr>(this)) { 100909105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian const ObjCImplicitSetterGetterRefExpr* Expr = 101009105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian cast<ObjCImplicitSetterGetterRefExpr>(this); 1011154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian if (Expr->getSetterMethod() == 0) 1012ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian return MLV_NoSetterProperty; 1013ba8d2d684e74a20bef03828c21c991d222c7e9e5Fariborz Jahanian } 10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return MLV_Valid; 10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 101744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// isOBJCGCCandidate - Check if an expression is objc gc'able. 101844baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian/// 1019102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanianbool Expr::isOBJCGCCandidate(ASTContext &Ctx) const { 102044baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian switch (getStmtClass()) { 102144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian default: 102244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 102344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ObjCIvarRefExprClass: 102444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return true; 1025207c5210eb0ac7b632609f0c006eb97ef2738948Fariborz Jahanian case Expr::UnaryOperatorClass: 1026102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<UnaryOperator>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 102744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ParenExprClass: 1028102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ParenExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 102944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ImplicitCastExprClass: 1030102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ImplicitCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 103106b89124a9a5971a0528cc9da6817740bac43164Fariborz Jahanian case CStyleCastExprClass: 1032102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<CStyleCastExpr>(this)->getSubExpr()->isOBJCGCCandidate(Ctx); 103344baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case DeclRefExprClass: 103444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case QualifiedDeclRefExprClass: { 103544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian const Decl *D = cast<DeclRefExpr>(this)->getDecl(); 1036102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { 1037102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (VD->hasGlobalStorage()) 1038102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return true; 1039102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian QualType T = VD->getType(); 1040102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian // dereferencing to an object pointer is always a gc'able candidate 1041102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian if (T->isPointerType() && 10426217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek T->getAs<PointerType>()->getPointeeType()->isObjCObjectPointerType()) 1043102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return true; 1044102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian 1045102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian } 104644baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian return false; 104744baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 104883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor case MemberExprClass: { 104944baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian const MemberExpr *M = cast<MemberExpr>(this); 1050102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return M->getBase()->isOBJCGCCandidate(Ctx); 105144baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 105244baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian case ArraySubscriptExprClass: 1053102e390bcb5a1fb1a8fdbc8505e6dfd905374bbdFariborz Jahanian return cast<ArraySubscriptExpr>(this)->getBase()->isOBJCGCCandidate(Ctx); 105444baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian } 105544baa8abba2a1552b6b50bf750a8750ab9da9f76Fariborz Jahanian} 10564e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() { 10574e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek Expr* E = this; 10584e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek while (ParenExpr* P = dyn_cast<ParenExpr>(E)) 10594e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek E = P->getSubExpr(); 10604e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 10614e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek return E; 10624e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek} 10634e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek 106456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr 106556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand. 106656f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() { 106756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner Expr *E = this; 106856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner while (true) { 106956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) 107056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 107156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner else if (CastExpr *P = dyn_cast<CastExpr>(E)) 107256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner E = P->getSubExpr(); 107356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner else 107456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner return E; 107556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner } 107656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner} 107756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner 1078ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the 1079ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// value (including ptr->int casts of the same size). Strip off any 1080ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner/// ParenExpr or CastExprs, returning their operand. 1081ecdd84147c0765caa999ddc22dde25b42712bb4dChris LattnerExpr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) { 1082ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *E = this; 1083ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner while (true) { 1084ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (ParenExpr *P = dyn_cast<ParenExpr>(E)) { 1085ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = P->getSubExpr(); 1086ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1087ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1088ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 1089ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (CastExpr *P = dyn_cast<CastExpr>(E)) { 1090ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner // We ignore integer <-> casts that are of the same width, ptr<->ptr and 1091ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner // ptr<->int casts of the same width. We also ignore all identify casts. 1092ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Expr *SE = P->getSubExpr(); 1093ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 1094ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) { 1095ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 1096ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1097ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1098ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 1099ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner if ((E->getType()->isPointerType() || E->getType()->isIntegralType()) && 1100ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner (SE->getType()->isPointerType() || SE->getType()->isIntegralType()) && 1101ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) { 1102ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner E = SE; 1103ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner continue; 1104ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1105ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1106ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 1107ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner return E; 1108ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner } 1109ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner} 1110ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 1111ecdd84147c0765caa999ddc22dde25b42712bb4dChris Lattner 1112898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyTypeDependentArguments - Determines if any of the expressions 1113898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is type-dependent. 1114898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) { 1115898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned I = 0; I < NumExprs; ++I) 1116898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isTypeDependent()) 1117898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 1118898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1119898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1120898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1121898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1122898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// hasAnyValueDependentArguments - Determines if any of the expressions 1123898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor/// in Exprs is value-dependent. 1124898574e7496ba8fd76290079d3a9d06954992734Douglas Gregorbool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) { 1125898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor for (unsigned I = 0; I < NumExprs; ++I) 1126898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor if (Exprs[I]->isValueDependent()) 1127898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return true; 1128898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1129898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor return false; 1130898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor} 1131898574e7496ba8fd76290079d3a9d06954992734Douglas Gregor 1132c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedmanbool Expr::isConstantInitializer(ASTContext &Ctx) const { 1133c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // This function is attempting whether an expression is an initializer 1134c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // which can be evaluated at compile-time. isEvaluatable handles most 1135c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // of the cases, but it can't deal with some initializer-specific 1136c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // expressions, and it can't deal with aggregates; we deal with those here, 1137c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // and fall back to isEvaluatable for the other cases. 1138c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman 11391f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This function assumes the variable being assigned to 11401f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // isn't a reference type! 11411f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman 1142e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson switch (getStmtClass()) { 1143c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman default: break; 1144e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case StringLiteralClass: 114514108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff case ObjCStringLiteralClass: 1146eaf2bb89eb2aad3b80673de30febe52df43c10ecChris Lattner case ObjCEncodeExprClass: 1147e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return true; 114859b5da6d853b4368b984700315adf7b37de05764Nate Begeman case CompoundLiteralExprClass: { 11491f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // This handles gcc's extension that allows global initializers like 11501f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // "struct x {int x;} x = (struct x) {};". 11511f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This accepts other cases it shouldn't! 115259b5da6d853b4368b984700315adf7b37de05764Nate Begeman const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer(); 1153c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman return Exp->isConstantInitializer(Ctx); 115459b5da6d853b4368b984700315adf7b37de05764Nate Begeman } 1155e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson case InitListExprClass: { 11561f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This doesn't deal with fields with reference types correctly. 11571f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // FIXME: This incorrectly allows pointers cast to integers to be assigned 11581f4a6db271f389d6ab3cb1bc28cb5c23a7828602Eli Friedman // to bitfields. 1159e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson const InitListExpr *Exp = cast<InitListExpr>(this); 1160e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson unsigned numInits = Exp->getNumInits(); 1161e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson for (unsigned i = 0; i < numInits; i++) { 1162c9e8f606787b0bc0c3b08e566b87cc1751694168Eli Friedman if (!Exp->getInit(i)->isConstantInitializer(Ctx)) 1163e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson return false; 1164e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 1165c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return true; 1166e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 11673498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor case ImplicitValueInitExprClass: 11683498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return true; 1169c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case ParenExprClass: { 1170c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return cast<ParenExpr>(this)->getSubExpr()->isConstantInitializer(Ctx); 1171c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman } 1172c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case UnaryOperatorClass: { 1173c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman const UnaryOperator* Exp = cast<UnaryOperator>(this); 1174c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman if (Exp->getOpcode() == UnaryOperator::Extension) 1175c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return Exp->getSubExpr()->isConstantInitializer(Ctx); 1176c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 1177c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman } 117881045d8dcd967def69d8e0945566214a9fe9ffccChris Lattner case ImplicitCastExprClass: 1179c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman case CStyleCastExprClass: 1180c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // Handle casts with a destination that's a struct or union; this 1181c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // deals with both the gcc no-op struct cast extension and the 1182c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman // cast-to-union extension. 1183c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman if (getType()->isRecordType()) 1184c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return cast<CastExpr>(this)->getSubExpr()->isConstantInitializer(Ctx); 1185c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman break; 1186e8a32b855ce4e8580a191f8d29d2f3f459834302Anders Carlsson } 1187c39dc9a25a9d74a5302e8567a4d3fc008212024cEli Friedman return isEvaluatable(Ctx); 118838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff} 118938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff 11905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIntegerConstantExpr - this recursive routine will test if an expression is 1191e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman/// an integer constant expression. 11925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 11935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FIXME: Pass up a reason why! Invalid operation in i-c-e, division by zero, 11945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comma, etc 11955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// 1196ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// FIXME: Handle offsetof. Two things to do: Handle GCC's __builtin_offsetof 1197ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// to support gcc 4.0+ and handle the idiom GCC recognizes with a null pointer 1198ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// cast+dereference. 11992d6744ff04c1690a1485178d550d2fab84a0270bDaniel Dunbar 1200e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// CheckICE - This function does the fundamental ICE checking: the returned 1201e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// ICEDiag contains a Val of 0, 1, or 2, and a possibly null SourceLocation. 1202e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// Note that to reduce code duplication, this helper does no evaluation 1203e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// itself; the caller checks whether the expression is evaluatable, and 1204e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// in the rare cases where CheckICE actually cares about the evaluated 1205e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// value, it calls into Evalute. 1206e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// 1207e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// Meanings of Val: 1208e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// 0: This expression is an ICE if it can be evaluated by Evaluate. 1209e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// 1: This expression is not an ICE, but if it isn't evaluated, it's 1210e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// a legal subexpression for an ICE. This return value is used to handle 1211e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// the comma operator in C99 mode. 1212e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman// 2: This expression is not an ICE, and is not a legal subexpression for one. 1213e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman 1214e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedmanstruct ICEDiag { 1215e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman unsigned Val; 1216e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman SourceLocation Loc; 1217e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman 1218e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman public: 1219e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag(unsigned v, SourceLocation l) : Val(v), Loc(l) {} 1220e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag() : Val(0) {} 1221e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman}; 1222e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman 1223e28d7195aad595154130ac8d03cc6c6513ece1bfEli FriedmanICEDiag NoDiag() { return ICEDiag(); } 1224e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman 122560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedmanstatic ICEDiag CheckEvalInICE(const Expr* E, ASTContext &Ctx) { 122660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman Expr::EvalResult EVResult; 122760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (!E->Evaluate(EVResult, Ctx) || EVResult.HasSideEffects || 122860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman !EVResult.Val.isInt()) { 122960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return ICEDiag(2, E->getLocStart()); 123060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } 123160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return NoDiag(); 123260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman} 123360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman 1234e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedmanstatic ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) { 1235c3082413e4207173b32c118e922d63149df6261fAnders Carlsson assert(!E->isValueDependent() && "Should not see value dependent exprs!"); 1236e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (!E->getType()->isIntegralType()) { 1237e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 1238a6afa768aa7bd3102a2807aa720917e4a1771e4eEli Friedman } 1239e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman 1240e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman switch (E->getStmtClass()) { 12415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 1242e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 1243e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::ParenExprClass: 1244e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return CheckICE(cast<ParenExpr>(E)->getSubExpr(), Ctx); 1245e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::IntegerLiteralClass: 1246e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CharacterLiteralClass: 1247e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CXXBoolLiteralExprClass: 1248e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CXXZeroInitValueExprClass: 1249e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::TypesCompatibleExprClass: 1250e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::UnaryTypeTraitExprClass: 1251e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 1252e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CallExprClass: 1253e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CXXOperatorCallExprClass: { 1254e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman const CallExpr *CE = cast<CallExpr>(E); 125560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (CE->isBuiltinCall(Ctx)) 125660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return CheckEvalInICE(E, Ctx); 1257e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 125813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff } 1259e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::DeclRefExprClass: 1260e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::QualifiedDeclRefExprClass: 1261e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (isa<EnumConstantDecl>(cast<DeclRefExpr>(E)->getDecl())) 1262e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 12634a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl if (Ctx.getLangOptions().CPlusPlus && 1264e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman E->getType().getCVRQualifiers() == QualType::Const) { 12654a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl // C++ 7.1.5.1p2 12664a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl // A variable of non-volatile const-qualified integral or enumeration 12674a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl // type initialized by an ICE can be used in ICEs. 12684a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl if (const VarDecl *Dcl = 1269e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman dyn_cast<VarDecl>(cast<DeclRefExpr>(E)->getDecl())) { 127078d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor if (Dcl->isInitKnownICE()) { 127178d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor // We have already checked whether this subexpression is an 127278d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor // integral constant expression. 127378d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor if (Dcl->isInitICE()) 127478d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor return NoDiag(); 127578d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor else 127678d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor return ICEDiag(2, E->getLocStart()); 127778d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor } 127878d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor 127978d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor if (const Expr *Init = Dcl->getInit()) { 128078d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor ICEDiag Result = CheckICE(Init, Ctx); 128178d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor // Cache the result of the ICE test. 128278d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor Dcl->setInitKnownICE(Ctx, Result.Val == 0); 128378d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor return Result; 128478d1583d0b36b7d6d8d10234cdc19ab94adf765aDouglas Gregor } 12854a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl } 12864a4251b9e719415f30db0f5170abf31296a62225Sebastian Redl } 1287e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 1288e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::UnaryOperatorClass: { 1289e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman const UnaryOperator *Exp = cast<UnaryOperator>(E); 12905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Exp->getOpcode()) { 12915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 1292e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 12935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Extension: 1294e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case UnaryOperator::LNot: 12955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Plus: 12965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Minus: 12975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case UnaryOperator::Not: 129860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman case UnaryOperator::Real: 129960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman case UnaryOperator::Imag: 1300e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return CheckICE(Exp->getSubExpr(), Ctx); 13015a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson case UnaryOperator::OffsetOf: 130260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // Note that per C99, offsetof must be an ICE. And AFAIK, using 130360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // Evaluate matches the proposed gcc behavior for cases like 130460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // "offsetof(struct s{int x[4];}, x[!.0])". This doesn't affect 130560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // compliance: we should warn earlier for offsetof expressions with 130660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // array subscripts that aren't ICEs, and if the array subscripts 130760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // are ICEs, the value of the offsetof must be an integer constant. 130860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return CheckEvalInICE(E, Ctx); 13095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 13105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1311e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::SizeOfAlignOfExprClass: { 1312e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman const SizeOfAlignOfExpr *Exp = cast<SizeOfAlignOfExpr>(E); 1313e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (Exp->isSizeOf() && Exp->getTypeOfArgument()->isVariableArrayType()) 1314e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 1315e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 13165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1317e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::BinaryOperatorClass: { 1318e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman const BinaryOperator *Exp = cast<BinaryOperator>(E); 13195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer switch (Exp->getOpcode()) { 13205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer default: 1321e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 13225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BinaryOperator::Mul: 13235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BinaryOperator::Div: 13245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BinaryOperator::Rem: 1325e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::Add: 1326e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::Sub: 13275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BinaryOperator::Shl: 13285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer case BinaryOperator::Shr: 1329e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::LT: 1330e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::GT: 1331e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::LE: 1332e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::GE: 1333e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::EQ: 1334e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::NE: 1335e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::And: 1336e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::Xor: 1337e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::Or: 1338e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::Comma: { 1339e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag LHSResult = CheckICE(Exp->getLHS(), Ctx); 1340e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag RHSResult = CheckICE(Exp->getRHS(), Ctx); 134160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (Exp->getOpcode() == BinaryOperator::Div || 134260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman Exp->getOpcode() == BinaryOperator::Rem) { 134360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // Evaluate gives an error for undefined Div/Rem, so make sure 134460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // we don't evaluate one. 134560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (LHSResult.Val != 2 && RHSResult.Val != 2) { 134660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman llvm::APSInt REval = Exp->getRHS()->EvaluateAsInt(Ctx); 134760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (REval == 0) 134860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return ICEDiag(1, E->getLocStart()); 134960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (REval.isSigned() && REval.isAllOnesValue()) { 135060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman llvm::APSInt LEval = Exp->getLHS()->EvaluateAsInt(Ctx); 135160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (LEval.isMinSignedValue()) 135260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return ICEDiag(1, E->getLocStart()); 135360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } 135460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } 135560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } 135660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (Exp->getOpcode() == BinaryOperator::Comma) { 135760ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (Ctx.getLangOptions().C99) { 135860ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // C99 6.6p3 introduces a strange edge case: comma can be in an ICE 135960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // if it isn't evaluated. 136060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (LHSResult.Val == 0 && RHSResult.Val == 0) 136160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return ICEDiag(1, E->getLocStart()); 136260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } else { 136360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman // In both C89 and C++, commas in ICEs are illegal. 136460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return ICEDiag(2, E->getLocStart()); 136560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } 1366b11e77836dd0867955c5abf32baf1c3e6c7f81e1Eli Friedman } 1367e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (LHSResult.Val >= RHSResult.Val) 1368e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return LHSResult; 1369e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return RHSResult; 13705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1371e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::LAnd: 1372e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case BinaryOperator::LOr: { 1373e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag LHSResult = CheckICE(Exp->getLHS(), Ctx); 1374e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag RHSResult = CheckICE(Exp->getRHS(), Ctx); 1375e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (LHSResult.Val == 0 && RHSResult.Val == 1) { 1376e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman // Rare case where the RHS has a comma "side-effect"; we need 1377e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman // to actually check the condition to see whether the side 1378e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman // with the comma is evaluated. 1379e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if ((Exp->getOpcode() == BinaryOperator::LAnd) != 138060ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman (Exp->getLHS()->EvaluateAsInt(Ctx) == 0)) 1381e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return RHSResult; 1382e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 1383a135975d4257ccc83f13b607b29d882bb00c80b6Daniel Dunbar } 138460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman 1385e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (LHSResult.Val >= RHSResult.Val) 1386e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return LHSResult; 1387e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return RHSResult; 13885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1389987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner } 13905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1391e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::ImplicitCastExprClass: 1392e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CStyleCastExprClass: 1393e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CXXFunctionalCastExprClass: { 1394e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman const Expr *SubExpr = cast<CastExpr>(E)->getSubExpr(); 1395e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (SubExpr->getType()->isIntegralType()) 1396e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return CheckICE(SubExpr, Ctx); 1397e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (isa<FloatingLiteral>(SubExpr->IgnoreParens())) 1398e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 1399e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return ICEDiag(2, E->getLocStart()); 1400e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman } 1401e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::ConditionalOperatorClass: { 1402e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman const ConditionalOperator *Exp = cast<ConditionalOperator>(E); 140328daa53db73341b7ee7f269924ccfca1c6d179acChris Lattner // If the condition (ignoring parens) is a __builtin_constant_p call, 140428daa53db73341b7ee7f269924ccfca1c6d179acChris Lattner // then only the true side is actually considered in an integer constant 140542b83dde7c700b34f9435ad746984169888ae705Chris Lattner // expression, and it is fully evaluated. This is an important GNU 140642b83dde7c700b34f9435ad746984169888ae705Chris Lattner // extension. See GCC PR38377 for discussion. 1407e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (const CallExpr *CallCE = dyn_cast<CallExpr>(Exp->getCond()->IgnoreParenCasts())) 14083c385e5f8d9008fff18597ca302be19fa86e51f6Douglas Gregor if (CallCE->isBuiltinCall(Ctx) == Builtin::BI__builtin_constant_p) { 1409e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman Expr::EvalResult EVResult; 1410e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (!E->Evaluate(EVResult, Ctx) || EVResult.HasSideEffects || 1411e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman !EVResult.Val.isInt()) { 141260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman return ICEDiag(2, E->getLocStart()); 1413e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman } 1414e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 141542b83dde7c700b34f9435ad746984169888ae705Chris Lattner } 1416e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag CondResult = CheckICE(Exp->getCond(), Ctx); 1417e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag TrueResult = CheckICE(Exp->getTrueExpr(), Ctx); 1418e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag FalseResult = CheckICE(Exp->getFalseExpr(), Ctx); 1419e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (CondResult.Val == 2) 1420e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return CondResult; 1421e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (TrueResult.Val == 2) 1422e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return TrueResult; 1423e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (FalseResult.Val == 2) 1424e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return FalseResult; 1425e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (CondResult.Val == 1) 1426e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return CondResult; 1427e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (TrueResult.Val == 0 && FalseResult.Val == 0) 1428e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return NoDiag(); 1429e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman // Rare case where the diagnostics depend on which side is evaluated 1430e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman // Note that if we get here, CondResult is 0, and at least one of 1431e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman // TrueResult and FalseResult is non-zero. 143260ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (Exp->getCond()->EvaluateAsInt(Ctx) == 0) { 1433e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return FalseResult; 1434e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman } 1435e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return TrueResult; 14365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1437e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman case Expr::CXXDefaultArgExprClass: 1438e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return CheckICE(cast<CXXDefaultArgExpr>(E)->getExpr(), Ctx); 143960ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman case Expr::ChooseExprClass: { 14407976932a1c256d447316ffac58e9821417725e34Eli Friedman return CheckICE(cast<ChooseExpr>(E)->getChosenSubExpr(Ctx), Ctx); 144160ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman } 14425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1443e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman} 14445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1445e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedmanbool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx, 1446e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman SourceLocation *Loc, bool isEvaluated) const { 1447e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman ICEDiag d = CheckICE(this, Ctx); 1448e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (d.Val != 0) { 1449e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman if (Loc) *Loc = d.Loc; 1450e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman return false; 1451e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman } 1452e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman EvalResult EvalResult; 145360ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman if (!Evaluate(EvalResult, Ctx)) 145460ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman assert(0 && "ICE cannot be evaluated!"); 145560ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman assert(!EvalResult.HasSideEffects && "ICE with side effects!"); 145660ce9635b969d17ff1bbe269deff5ec3c6b1bc06Eli Friedman assert(EvalResult.Val.isInt() && "ICE that isn't integer!"); 1457e28d7195aad595154130ac8d03cc6c6513ece1bfEli Friedman Result = EvalResult.Val.getInt(); 14585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return true; 14595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 14605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 14615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an 14625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// integer constant expression with the value zero, or if this is one that is 14635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// cast to void*. 1464efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlssonbool Expr::isNullPointerConstant(ASTContext &Ctx) const 1465efa9b3877ef298bcb792600ac33521827e1f7fafAnders Carlsson{ 14660777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Strip off a cast to void*, if it exists. Except in C++. 14670835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) { 14686215dee86c0e715b9f2b0d401ab2a5fcf629f1afSebastian Redl if (!Ctx.getLangOptions().CPlusPlus) { 14690777972d38a3125efed962b045704c30ae6965cfSebastian Redl // Check that it is a cast to void*. 14706217b80b7a1379b74cced1c076338262c3c980b3Ted Kremenek if (const PointerType *PT = CE->getType()->getAs<PointerType>()) { 14710777972d38a3125efed962b045704c30ae6965cfSebastian Redl QualType Pointee = PT->getPointeeType(); 14720777972d38a3125efed962b045704c30ae6965cfSebastian Redl if (Pointee.getCVRQualifiers() == 0 && 14730777972d38a3125efed962b045704c30ae6965cfSebastian Redl Pointee->isVoidType() && // to void* 14740777972d38a3125efed962b045704c30ae6965cfSebastian Redl CE->getSubExpr()->getType()->isIntegerType()) // from int. 1475d26527708b2b2f3b1d747f570efd10149d48364eAnders Carlsson return CE->getSubExpr()->isNullPointerConstant(Ctx); 14760777972d38a3125efed962b045704c30ae6965cfSebastian Redl } 14775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1478aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) { 1479aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Ignore the ImplicitCastExpr type entirely. 1480d26527708b2b2f3b1d747f570efd10149d48364eAnders Carlsson return ICE->getSubExpr()->isNullPointerConstant(Ctx); 1481aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) { 1482aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // Accept ((void*)0) as a null pointer constant, as many other 1483aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // implementations do. 1484d26527708b2b2f3b1d747f570efd10149d48364eAnders Carlsson return PE->getSubExpr()->isNullPointerConstant(Ctx); 14858123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner } else if (const CXXDefaultArgExpr *DefaultArg 14868123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner = dyn_cast<CXXDefaultArgExpr>(this)) { 148704421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner // See through default argument expressions 1488d26527708b2b2f3b1d747f570efd10149d48364eAnders Carlsson return DefaultArg->getExpr()->isNullPointerConstant(Ctx); 14892d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor } else if (isa<GNUNullExpr>(this)) { 14902d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor // The GNU __null extension is always a null pointer constant. 14912d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor return true; 1492aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff } 14932d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 14946e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl // C++0x nullptr_t is always a null pointer constant. 14956e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl if (getType()->isNullPtrType()) 14966e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl return true; 14976e8ed16ffef02b82995a90bdcf10ffff7d63839aSebastian Redl 1498aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff // This expression must be an integer type. 1499aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff if (!getType()->isIntegerType()) 1500aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff return false; 1501aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff 15025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If we have an integer constant expression, we need to *evaluate* it and 15035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // test for the value 0. 150409de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman llvm::APSInt Result; 150509de1767990d4828bcaf0dd22033a5dddeecbe08Eli Friedman return isIntegerConstantExpr(Result, Ctx) && Result == 0; 15065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} 150731a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff 150833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas GregorFieldDecl *Expr::getBitField() { 15096f4a69a3107e7ff1569c747f7c6bdf7cff8cbf55Douglas Gregor Expr *E = this->IgnoreParens(); 151033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 151127c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E)) 151286f194083504938df72135b5b66bf0c5cafd9498Douglas Gregor if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl())) 151333bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (Field->isBitField()) 151433bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return Field; 151533bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 151633bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E)) 151733bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor if (BinOp->isAssignmentOp() && BinOp->getLHS()) 151833bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return BinOp->getLHS()->getBitField(); 151933bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor 152033bbbc5ec8269bc2cde5b84f970fa49319a30267Douglas Gregor return 0; 152127c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor} 152227c8dc06f65d7abcf6a7e7f64a7960c9a150ca01Douglas Gregor 15232140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// isArrow - Return true if the base expression is a pointer to vector, 15242140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner/// return false if the base expression is a vector. 15252140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattnerbool ExtVectorElementExpr::isArrow() const { 15262140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner return getBase()->getType()->isPointerType(); 15272140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner} 15282140e904dbe53657339cb5b1cc13de563ca0d1fcChris Lattner 1529213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const { 15308a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman if (const VectorType *VT = getType()->getAsVectorType()) 15318a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return VT->getNumElements(); 15328a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman return 1; 15334d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner} 15344d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner 15358a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated. 1536213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const { 1537d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor const char *compStr = Accessor->getName(); 1538d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor unsigned length = Accessor->getLength(); 1539190d6a25393995b42e32086949a68285ee423fb9Nate Begeman 1540190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Halving swizzles do not contain duplicate elements. 1541190d6a25393995b42e32086949a68285ee423fb9Nate Begeman if (!strcmp(compStr, "hi") || !strcmp(compStr, "lo") || 1542190d6a25393995b42e32086949a68285ee423fb9Nate Begeman !strcmp(compStr, "even") || !strcmp(compStr, "odd")) 1543190d6a25393995b42e32086949a68285ee423fb9Nate Begeman return false; 1544190d6a25393995b42e32086949a68285ee423fb9Nate Begeman 1545190d6a25393995b42e32086949a68285ee423fb9Nate Begeman // Advance past s-char prefix on hex swizzles. 1546131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman if (*compStr == 's' || *compStr == 'S') { 1547190d6a25393995b42e32086949a68285ee423fb9Nate Begeman compStr++; 1548190d6a25393995b42e32086949a68285ee423fb9Nate Begeman length--; 1549190d6a25393995b42e32086949a68285ee423fb9Nate Begeman } 1550fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff 15517e3e9b152e06edf329ceb32190d3255f248d4d5fChris Lattner for (unsigned i = 0; i != length-1; i++) { 1552fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff const char *s = compStr+i; 1553fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff for (const char c = *s++; *s; s++) 1554fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff if (c == *s) 1555fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return true; 1556fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff } 1557fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff return false; 1558fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff} 1559b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 15608a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray. 15613b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess( 15623b8d116703db8018f855cbb4733ace426422623bNate Begeman llvm::SmallVectorImpl<unsigned> &Elts) const { 1563d3c98a02c73417689deaaa6671ea6df7f2a8a73cDouglas Gregor const char *compStr = Accessor->getName(); 1564131f4658249b2a7d2d7e30fe07e84c484f79ef99Nate Begeman if (*compStr == 's' || *compStr == 'S') 1565353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman compStr++; 1566353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman 1567353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman bool isHi = !strcmp(compStr, "hi"); 1568353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman bool isLo = !strcmp(compStr, "lo"); 1569353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman bool isEven = !strcmp(compStr, "even"); 1570353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman bool isOdd = !strcmp(compStr, "odd"); 1571353417af9d254d4fd0eb7d0a3ff71c4d8594ac58Nate Begeman 15728a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman for (unsigned i = 0, e = getNumElements(); i != e; ++i) { 15738a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman uint64_t Index; 15748a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 15758a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman if (isHi) 15768a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = e + i; 15778a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isLo) 15788a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = i; 15798a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isEven) 15808a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i; 15818a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else if (isOdd) 15828a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = 2 * i + 1; 15838a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman else 15848a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman Index = ExtVectorType::getAccessorIdx(compStr[i]); 1585b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner 15863b8d116703db8018f855cbb4733ace426422623bNate Begeman Elts.push_back(Index); 1587b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner } 15888a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman} 15898a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman 159068d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// constructor for instance messages. 1591bcfb06ac6da1aa3c74ac1ef7a49c2807522366e7Steve NaroffObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo, 1592a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek QualType retType, ObjCMethodDecl *mproto, 1593db611d556f71f98b66b69514d45958d76e5727abSteve Naroff SourceLocation LBrac, SourceLocation RBrac, 159449f109c786f99eb7468dac3976db083a65493444Steve Naroff Expr **ArgExprs, unsigned nargs) 1595db611d556f71f98b66b69514d45958d76e5727abSteve Naroff : Expr(ObjCMessageExprClass, retType), SelName(selInfo), 1596ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted Kremenek MethodProto(mproto) { 159749f109c786f99eb7468dac3976db083a65493444Steve Naroff NumArgs = nargs; 15985549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek SubExprs = new Stmt*[NumArgs+1]; 159968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff SubExprs[RECEIVER] = receiver; 160049f109c786f99eb7468dac3976db083a65493444Steve Naroff if (NumArgs) { 160149f109c786f99eb7468dac3976db083a65493444Steve Naroff for (unsigned i = 0; i != NumArgs; ++i) 160268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]); 160368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff } 1604563477da25f824e37c535131695dc4dc9b68c465Steve Naroff LBracloc = LBrac; 1605563477da25f824e37c535131695dc4dc9b68c465Steve Naroff RBracloc = RBrac; 1606563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 1607563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 160868d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// constructor for class messages. 160968d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// FIXME: clsName should be typed to ObjCInterfaceType 1610bcfb06ac6da1aa3c74ac1ef7a49c2807522366e7Steve NaroffObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo, 1611a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek QualType retType, ObjCMethodDecl *mproto, 1612db611d556f71f98b66b69514d45958d76e5727abSteve Naroff SourceLocation LBrac, SourceLocation RBrac, 161349f109c786f99eb7468dac3976db083a65493444Steve Naroff Expr **ArgExprs, unsigned nargs) 1614db611d556f71f98b66b69514d45958d76e5727abSteve Naroff : Expr(ObjCMessageExprClass, retType), SelName(selInfo), 1615ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted Kremenek MethodProto(mproto) { 161649f109c786f99eb7468dac3976db083a65493444Steve Naroff NumArgs = nargs; 16175549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek SubExprs = new Stmt*[NumArgs+1]; 16184df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek SubExprs[RECEIVER] = (Expr*) ((uintptr_t) clsName | IsClsMethDeclUnknown); 161949f109c786f99eb7468dac3976db083a65493444Steve Naroff if (NumArgs) { 162049f109c786f99eb7468dac3976db083a65493444Steve Naroff for (unsigned i = 0; i != NumArgs; ++i) 162168d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]); 162268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff } 1623563477da25f824e37c535131695dc4dc9b68c465Steve Naroff LBracloc = LBrac; 1624563477da25f824e37c535131695dc4dc9b68c465Steve Naroff RBracloc = RBrac; 1625563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 1626563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 16274df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek// constructor for class messages. 16284df728e368fa1f65ffc57572fed613dcca5b4fe8Ted KremenekObjCMessageExpr::ObjCMessageExpr(ObjCInterfaceDecl *cls, Selector selInfo, 16294df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek QualType retType, ObjCMethodDecl *mproto, 16304df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek SourceLocation LBrac, SourceLocation RBrac, 16314df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek Expr **ArgExprs, unsigned nargs) 16324df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek: Expr(ObjCMessageExprClass, retType), SelName(selInfo), 16334df728e368fa1f65ffc57572fed613dcca5b4fe8Ted KremenekMethodProto(mproto) { 16344df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek NumArgs = nargs; 16354df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek SubExprs = new Stmt*[NumArgs+1]; 16364df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek SubExprs[RECEIVER] = (Expr*) ((uintptr_t) cls | IsClsMethDeclKnown); 16374df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek if (NumArgs) { 16384df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek for (unsigned i = 0; i != NumArgs; ++i) 16394df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]); 16404df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek } 16414df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek LBracloc = LBrac; 16424df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek RBracloc = RBrac; 16434df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek} 16444df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 16454df728e368fa1f65ffc57572fed613dcca5b4fe8Ted KremenekObjCMessageExpr::ClassInfo ObjCMessageExpr::getClassInfo() const { 16464df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek uintptr_t x = (uintptr_t) SubExprs[RECEIVER]; 16474df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek switch (x & Flags) { 16484df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek default: 16494df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek assert(false && "Invalid ObjCMessageExpr."); 16504df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek case IsInstMeth: 16514df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek return ClassInfo(0, 0); 16524df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek case IsClsMethDeclUnknown: 16534df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek return ClassInfo(0, (IdentifierInfo*) (x & ~Flags)); 16544df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek case IsClsMethDeclKnown: { 16554df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek ObjCInterfaceDecl* D = (ObjCInterfaceDecl*) (x & ~Flags); 16564df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek return ClassInfo(D, D->getIdentifier()); 16574df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek } 16584df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek } 16594df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek} 16604df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek 16610389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattnervoid ObjCMessageExpr::setClassInfo(const ObjCMessageExpr::ClassInfo &CI) { 16620389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner if (CI.first == 0 && CI.second == 0) 16630389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner SubExprs[RECEIVER] = (Expr*)((uintptr_t)0 | IsInstMeth); 16640389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner else if (CI.first == 0) 16650389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.second | IsClsMethDeclUnknown); 16660389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner else 16670389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.first | IsClsMethDeclKnown); 16680389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner} 16690389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 16700389e6bd0159bfdd08f7c50a37543b6e3adf0c33Chris Lattner 167127437caadea35f84d550cd29f024fcf3ea240eecChris Lattnerbool ChooseExpr::isConditionTrue(ASTContext &C) const { 16729a901bb63990574ff0bcc12ff851d7a71cff8ddbEli Friedman return getCond()->EvaluateAsInt(C) != 0; 167327437caadea35f84d550cd29f024fcf3ea240eecChris Lattner} 167427437caadea35f84d550cd29f024fcf3ea240eecChris Lattner 1675888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::setExprs(ASTContext &C, Expr ** Exprs, 1676888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman unsigned NumExprs) { 1677888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman if (SubExprs) C.Deallocate(SubExprs); 1678888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 1679888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman SubExprs = new (C) Stmt* [NumExprs]; 168094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor this->NumExprs = NumExprs; 168194cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor memcpy(SubExprs, Exprs, sizeof(Expr *) * NumExprs); 1682888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman} 1683888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman 1684888376a2bbcfc2f047902249f8455918e2489ae1Nate Begemanvoid ShuffleVectorExpr::DoDestroy(ASTContext& C) { 1685888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman DestroyChildren(C); 1686888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman if (SubExprs) C.Deallocate(SubExprs); 1687888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman this->~ShuffleVectorExpr(); 1688888376a2bbcfc2f047902249f8455918e2489ae1Nate Begeman C.Deallocate(this); 168994cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor} 169094cd5d1397bb1a8bcd109602aa38dd787b164c22Douglas Gregor 169142602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorvoid SizeOfAlignOfExpr::DoDestroy(ASTContext& C) { 16920518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // Override default behavior of traversing children. If this has a type 16930518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // operand and the type is a variable-length array, the child iteration 16940518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // will iterate over the size expression. However, this expression belongs 16950518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // to the type, not to this, so we don't want to delete it. 16960518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // We still want to delete this expression. 16978189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek if (isArgumentType()) { 16988189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek this->~SizeOfAlignOfExpr(); 16998189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek C.Deallocate(this); 17008189cde56b4f6f938cd65f53c932fe1860d0204cTed Kremenek } 17010518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl else 170242602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor Expr::DoDestroy(C); 17039048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar} 17049048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar 170577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 170605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor// DesignatedInitExpr 170705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 170805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 170905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorIdentifierInfo *DesignatedInitExpr::Designator::getFieldName() { 171005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(Kind == FieldDesignator && "Only valid on a field designator"); 171105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (Field.NameOrField & 0x01) 171205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01); 171305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 171405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return getField()->getIdentifier(); 171505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 171605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 1717ffb4b6e299069139908540ce97be4462e16b53a4Douglas GregorDesignatedInitExpr::DesignatedInitExpr(QualType Ty, unsigned NumDesignators, 1718ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Designators, 1719ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor SourceLocation EqualOrColonLoc, 1720ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor bool GNUSyntax, 17219ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr **IndexExprs, 17229ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned NumIndexExprs, 17239ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Init) 17249ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor : Expr(DesignatedInitExprClass, Ty, 17259ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Init->isTypeDependent(), Init->isValueDependent()), 1726ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax), 17279ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor NumDesignators(NumDesignators), NumSubExprs(NumIndexExprs + 1) { 1728ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor this->Designators = new Designator[NumDesignators]; 17299ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 17309ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Record the initializer itself. 17319ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor child_iterator Child = child_begin(); 17329ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = Init; 17339ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 17349ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the designators and their subexpressions, computing 17359ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // value-dependence along the way. 17369ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor unsigned IndexIdx = 0; 17379ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor for (unsigned I = 0; I != NumDesignators; ++I) { 1738ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor this->Designators[I] = Designators[I]; 17399ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 17409ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor if (this->Designators[I].isArrayDesignator()) { 17419ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 17429ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Index = IndexExprs[IndexIdx]; 17439ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ValueDependent = ValueDependent || 17449ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Index->isTypeDependent() || Index->isValueDependent(); 17459ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 17469ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the index expressions into permanent storage. 17479ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 17489ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } else if (this->Designators[I].isArrayRangeDesignator()) { 17499ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Compute type- and value-dependence. 17509ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *Start = IndexExprs[IndexIdx]; 17519ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Expr *End = IndexExprs[IndexIdx + 1]; 17529ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ValueDependent = ValueDependent || 17539ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor Start->isTypeDependent() || Start->isValueDependent() || 17549ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor End->isTypeDependent() || End->isValueDependent(); 17559ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 17569ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor // Copy the start/end expressions into permanent storage. 17579ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 17589ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor *Child++ = IndexExprs[IndexIdx++]; 17599ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 17609ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor } 17619ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor 17629ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor assert(IndexIdx == NumIndexExprs && "Wrong number of index expressions"); 1763ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 1764ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 176505c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr * 176605c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorDesignatedInitExpr::Create(ASTContext &C, Designator *Designators, 176705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor unsigned NumDesignators, 176805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Expr **IndexExprs, unsigned NumIndexExprs, 176905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation ColonOrEqualLoc, 177005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor bool UsesColonSyntax, Expr *Init) { 1771c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 1772c0ac4923f08b25ae973a8ee7942cf3eb89da57b7Steve Naroff sizeof(Stmt *) * (NumIndexExprs + 1), 8); 17739ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor return new (Mem) DesignatedInitExpr(C.VoidTy, NumDesignators, Designators, 17749ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor ColonOrEqualLoc, UsesColonSyntax, 17759ea62768fca25d829d80199cf4f8cf0f4dd39251Douglas Gregor IndexExprs, NumIndexExprs, Init); 177605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 177705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 1778d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas GregorDesignatedInitExpr *DesignatedInitExpr::CreateEmpty(ASTContext &C, 1779d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumIndexExprs) { 1780d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor void *Mem = C.Allocate(sizeof(DesignatedInitExpr) + 1781d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor sizeof(Stmt *) * (NumIndexExprs + 1), 8); 1782d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor return new (Mem) DesignatedInitExpr(NumIndexExprs + 1); 1783d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 1784d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 1785d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregorvoid DesignatedInitExpr::setDesignators(const Designator *Desigs, 1786d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor unsigned NumDesigs) { 1787d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor if (Designators) 1788d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor delete [] Designators; 1789d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 1790d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Designators = new Designator[NumDesigs]; 1791d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor NumDesignators = NumDesigs; 1792d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor for (unsigned I = 0; I != NumDesigs; ++I) 1793d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor Designators[I] = Desigs[I]; 1794d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor} 1795d077d759d0c7fceee98f4e77b6423a3f11cfc849Douglas Gregor 179605c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorSourceRange DesignatedInitExpr::getSourceRange() const { 179705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor SourceLocation StartLoc; 1798d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner Designator &First = 1799d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner *const_cast<DesignatedInitExpr*>(this)->designators_begin(); 180005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor if (First.isFieldDesignator()) { 1801eeae8f072748affce25ab4064982626361293390Douglas Gregor if (GNUSyntax) 180205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc); 180305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor else 180405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc); 180505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor } else 1806d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner StartLoc = 1807d603eaa682cecac2c10771a700cb83aa301653b4Chris Lattner SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc); 180805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return SourceRange(StartLoc, getInit()->getSourceRange().getEnd()); 180905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 181005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 181105c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayIndex(const Designator& D) { 181205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(D.Kind == Designator::ArrayDesignator && "Requires array designator"); 181305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 181405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 181505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 181605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 181705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 181805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 181905c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) { 182005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(D.Kind == Designator::ArrayRangeDesignator && 182105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 182205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 182305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 182405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 182505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1)); 182605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 182705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 182805c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorExpr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) { 182905c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor assert(D.Kind == Designator::ArrayRangeDesignator && 183005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor "Requires array range designator"); 183105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 183205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 183305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 183405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2)); 183505c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 183605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 1837ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// \brief Replaces the designator at index @p Idx with the series 1838ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor/// of designators in [First, Last). 1839ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregorvoid DesignatedInitExpr::ExpandDesignator(unsigned Idx, 1840ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *First, 1841ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor const Designator *Last) { 1842ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor unsigned NumNewDesignators = Last - First; 1843ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor if (NumNewDesignators == 0) { 1844ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy_backward(Designators + Idx + 1, 1845ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + NumDesignators, 1846ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators + Idx); 1847ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor --NumNewDesignators; 1848ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 1849ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } else if (NumNewDesignators == 1) { 1850ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators[Idx] = *First; 1851ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor return; 1852ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor } 1853ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 1854ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designator *NewDesignators 1855ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor = new Designator[NumDesignators - 1 + NumNewDesignators]; 1856ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators, Designators + Idx, NewDesignators); 1857ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(First, Last, NewDesignators + Idx); 1858ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor std::copy(Designators + Idx + 1, Designators + NumDesignators, 1859ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NewDesignators + Idx + NumNewDesignators); 1860ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor delete [] Designators; 1861ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor Designators = NewDesignators; 1862ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor NumDesignators = NumDesignators - 1 + NumNewDesignators; 1863ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 1864ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 186542602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregorvoid DesignatedInitExpr::DoDestroy(ASTContext &C) { 1866ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor delete [] Designators; 186742602bb40aefcc2751d4078ba88aacf4d965c9bdDouglas Gregor Expr::DoDestroy(C); 1868ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor} 1869ffb4b6e299069139908540ce97be4462e16b53a4Douglas Gregor 18702ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanParenListExpr::ParenListExpr(ASTContext& C, SourceLocation lparenloc, 18712ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Expr **exprs, unsigned nexprs, 18722ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman SourceLocation rparenloc) 18732ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman: Expr(ParenListExprClass, QualType(), 18742ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman hasAnyTypeDependentArguments(exprs, nexprs), 18752ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman hasAnyValueDependentArguments(exprs, nexprs)), 18762ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman NumExprs(nexprs), LParenLoc(lparenloc), RParenLoc(rparenloc) { 18772ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 18782ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs = new (C) Stmt*[nexprs]; 18792ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman for (unsigned i = 0; i != nexprs; ++i) 18802ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman Exprs[i] = exprs[i]; 18812ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 18822ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 18832ef13e5abef0570a9f567b4671367275c05d4d34Nate Begemanvoid ParenListExpr::DoDestroy(ASTContext& C) { 18842ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman DestroyChildren(C); 18852ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman if (Exprs) C.Deallocate(Exprs); 18862ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman this->~ParenListExpr(); 18872ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman C.Deallocate(this); 18882ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 18892ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 189005c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor//===----------------------------------------------------------------------===// 1891ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek// ExprIterator. 1892ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 1893ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 1894ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); } 1895ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator*() const { return cast<Expr>(*I); } 1896ce2fc3a343ea6098a96d587071cee7299f11957aTed KremenekExpr* ExprIterator::operator->() const { return cast<Expr>(*I); } 1897ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator[](size_t idx) const { 1898ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek return cast<Expr>(I[idx]); 1899ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek} 1900ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); } 1901ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenekconst Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); } 1902ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek 1903ce2fc3a343ea6098a96d587071cee7299f11957aTed Kremenek//===----------------------------------------------------------------------===// 190477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// Child Iterators for iterating over subexpressions/substatements 190577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===// 190677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 190777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// DeclRefExpr 19089ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); } 19099ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); } 191077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 19117779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff// ObjCIvarRefExpr 19125549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_begin() { return &Base; } 19135549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_end() { return &Base+1; } 19147779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff 1915e3e9add4fd788927df6f545570e7838db59c01d7Steve Naroff// ObjCPropertyRefExpr 19165549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_begin() { return &Base; } 19175549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_end() { return &Base+1; } 1918ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff 191909105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz Jahanian// ObjCImplicitSetterGetterRefExpr 192009105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz JahanianStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_begin() { 1921154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian return &Base; 1922154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian} 192309105f52b1f28cbb1374c27c3c70f5517e2c465dFariborz JahanianStmt::child_iterator ObjCImplicitSetterGetterRefExpr::child_end() { 1924154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian return &Base+1; 1925154440e6a8fa6ac5bca395876d79b530b39a2c1cFariborz Jahanian} 19265daf570d0ce027e18ed5f9d66e6b2a14a40b720dFariborz Jahanian 1927cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor// ObjCSuperExpr 1928cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas GregorStmt::child_iterator ObjCSuperExpr::child_begin() { return child_iterator(); } 1929cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas GregorStmt::child_iterator ObjCSuperExpr::child_end() { return child_iterator(); } 1930cd9b46e5442a3ef17f83f75177d8545cb5b3e2b9Douglas Gregor 1931f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff// ObjCIsaExpr 1932f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_begin() { return &Base; } 1933f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve NaroffStmt::child_iterator ObjCIsaExpr::child_end() { return &Base+1; } 1934f242b1b0c4e998911cb96b2ba7e27ab4a5abaed3Steve Naroff 1935d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner// PredefinedExpr 1936d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); } 1937d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); } 193877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 193977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// IntegerLiteral 19409ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); } 19419ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); } 194277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 194377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CharacterLiteral 1944d603eaa682cecac2c10771a700cb83aa301653b4Chris LattnerStmt::child_iterator CharacterLiteral::child_begin() { return child_iterator();} 19459ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); } 194677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 194777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// FloatingLiteral 19489ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); } 19499ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); } 195077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 19515d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner// ImaginaryLiteral 19525549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_begin() { return &Val; } 19535549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_end() { return &Val+1; } 19545d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner 195577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// StringLiteral 19569ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_begin() { return child_iterator(); } 19579ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_end() { return child_iterator(); } 195877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 195977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ParenExpr 19605549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_begin() { return &Val; } 19615549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_end() { return &Val+1; } 196277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 196377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// UnaryOperator 19645549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_begin() { return &Val; } 19655549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_end() { return &Val+1; } 196677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 19670518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl// SizeOfAlignOfExpr 19680518999d3adcc289997bd974dce90cc97f5c1c44Sebastian RedlStmt::child_iterator SizeOfAlignOfExpr::child_begin() { 19690518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // If this is of a type and the type is a VLA type (and not a typedef), the 19700518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // size expression of the VLA needs to be treated as an executable expression. 19710518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl // Why isn't this weirdness documented better in StmtIterator? 19720518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) { 19730518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (VariableArrayType* T = dyn_cast<VariableArrayType>( 19740518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl getArgumentType().getTypePtr())) 19750518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return child_iterator(T); 19760518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return child_iterator(); 19770518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl } 1978d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return child_iterator(&Argument.Ex); 19799ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 19800518999d3adcc289997bd974dce90cc97f5c1c44Sebastian RedlStmt::child_iterator SizeOfAlignOfExpr::child_end() { 19810518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl if (isArgumentType()) 19820518999d3adcc289997bd974dce90cc97f5c1c44Sebastian Redl return child_iterator(); 1983d457589fc69dc7a9c80cd74d317c0b81a35a27c9Sebastian Redl return child_iterator(&Argument.Ex + 1); 19849ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 198577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 198677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ArraySubscriptExpr 19871237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_begin() { 19885549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 198977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 19901237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_end() { 19915549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+END_EXPR; 199277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 199377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek 199477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CallExpr 19951237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_begin() { 19965549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 199777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 19981237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_end() { 19995549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+NumArgs+ARGS_START; 200077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek} 20011237c673c07f9d827129ba02720108816abde562Ted Kremenek 20021237c673c07f9d827129ba02720108816abde562Ted Kremenek// MemberExpr 20035549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_begin() { return &Base; } 20045549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_end() { return &Base+1; } 20051237c673c07f9d827129ba02720108816abde562Ted Kremenek 2006213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman// ExtVectorElementExpr 20075549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_begin() { return &Base; } 20085549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_end() { return &Base+1; } 20091237c673c07f9d827129ba02720108816abde562Ted Kremenek 20101237c673c07f9d827129ba02720108816abde562Ted Kremenek// CompoundLiteralExpr 20115549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_begin() { return &Init; } 20125549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_end() { return &Init+1; } 20131237c673c07f9d827129ba02720108816abde562Ted Kremenek 20141237c673c07f9d827129ba02720108816abde562Ted Kremenek// CastExpr 20155549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_begin() { return &Op; } 20165549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_end() { return &Op+1; } 20171237c673c07f9d827129ba02720108816abde562Ted Kremenek 20181237c673c07f9d827129ba02720108816abde562Ted Kremenek// BinaryOperator 20191237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_begin() { 20205549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 20211237c673c07f9d827129ba02720108816abde562Ted Kremenek} 20221237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_end() { 20235549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+END_EXPR; 20241237c673c07f9d827129ba02720108816abde562Ted Kremenek} 20251237c673c07f9d827129ba02720108816abde562Ted Kremenek 20261237c673c07f9d827129ba02720108816abde562Ted Kremenek// ConditionalOperator 20271237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_begin() { 20285549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 20291237c673c07f9d827129ba02720108816abde562Ted Kremenek} 20301237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_end() { 20315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+END_EXPR; 20321237c673c07f9d827129ba02720108816abde562Ted Kremenek} 20331237c673c07f9d827129ba02720108816abde562Ted Kremenek 20341237c673c07f9d827129ba02720108816abde562Ted Kremenek// AddrLabelExpr 20359ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); } 20369ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); } 20371237c673c07f9d827129ba02720108816abde562Ted Kremenek 20381237c673c07f9d827129ba02720108816abde562Ted Kremenek// StmtExpr 20395549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_begin() { return &SubStmt; } 20405549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_end() { return &SubStmt+1; } 20411237c673c07f9d827129ba02720108816abde562Ted Kremenek 20421237c673c07f9d827129ba02720108816abde562Ted Kremenek// TypesCompatibleExpr 20439ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_begin() { 20449ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 20459ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 20469ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek 20479ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_end() { 20489ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 20499ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 20501237c673c07f9d827129ba02720108816abde562Ted Kremenek 20511237c673c07f9d827129ba02720108816abde562Ted Kremenek// ChooseExpr 20525549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_begin() { return &SubExprs[0]; } 20535549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_end() { return &SubExprs[0]+END_EXPR; } 20542d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor 20552d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas Gregor// GNUNullExpr 20562d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_begin() { return child_iterator(); } 20572d8b273470684a9cd47f0ce24743cc1f71ef7cbcDouglas GregorStmt::child_iterator GNUNullExpr::child_end() { return child_iterator(); } 20581237c673c07f9d827129ba02720108816abde562Ted Kremenek 2059d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman// ShuffleVectorExpr 2060d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_begin() { 20615549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]; 2062d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman} 2063d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_end() { 20645549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+NumExprs; 2065d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman} 2066d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman 20677c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson// VAArgExpr 20685549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_begin() { return &Val; } 20695549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_end() { return &Val+1; } 20707c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson 207166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson// InitListExpr 207266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonStmt::child_iterator InitListExpr::child_begin() { 20735549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return InitExprs.size() ? &InitExprs[0] : 0; 207466b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 207566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonStmt::child_iterator InitListExpr::child_end() { 20765549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return InitExprs.size() ? &InitExprs[0] + InitExprs.size() : 0; 207766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson} 207866b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson 20793498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// DesignatedInitExpr 208005c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_begin() { 208105c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor char* Ptr = static_cast<char*>(static_cast<void *>(this)); 208205c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor Ptr += sizeof(DesignatedInitExpr); 208305c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr)); 208405c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 208505c13a3411782108d65aab3c77b1a231a4963bc0Douglas GregorStmt::child_iterator DesignatedInitExpr::child_end() { 208605c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor return child_iterator(&*child_begin() + NumSubExprs); 208705c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor} 208805c13a3411782108d65aab3c77b1a231a4963bc0Douglas Gregor 20893498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor// ImplicitValueInitExpr 20903498bdb9e9cb300de74c7b51c92608e2902b2348Douglas GregorStmt::child_iterator ImplicitValueInitExpr::child_begin() { 20913498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return child_iterator(); 20923498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor} 20933498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 20943498bdb9e9cb300de74c7b51c92608e2902b2348Douglas GregorStmt::child_iterator ImplicitValueInitExpr::child_end() { 20953498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor return child_iterator(); 20963498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor} 20973498bdb9e9cb300de74c7b51c92608e2902b2348Douglas Gregor 20982ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman// ParenListExpr 20992ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_begin() { 21002ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return &Exprs[0]; 21012ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 21022ef13e5abef0570a9f567b4671367275c05d4d34Nate BegemanStmt::child_iterator ParenListExpr::child_end() { 21032ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman return &Exprs[0]+NumExprs; 21042ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman} 21052ef13e5abef0570a9f567b4671367275c05d4d34Nate Begeman 21061237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCStringLiteral 21079ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCStringLiteral::child_begin() { 2108c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner return &String; 21099ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 21109ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCStringLiteral::child_end() { 2111c6c16af963eddc3e9b75b5d2614d069e1162fe27Chris Lattner return &String+1; 21129ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 21131237c673c07f9d827129ba02720108816abde562Ted Kremenek 21141237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCEncodeExpr 21159ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); } 21169ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); } 21171237c673c07f9d827129ba02720108816abde562Ted Kremenek 2118b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian// ObjCSelectorExpr 21199ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCSelectorExpr::child_begin() { 21209ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 21219ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 21229ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCSelectorExpr::child_end() { 21239ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 21249ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 2125b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian 2126390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian// ObjCProtocolExpr 21279ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_begin() { 21289ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 21299ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 21309ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_end() { 21319ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek return child_iterator(); 21329ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek} 2133390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian 2134563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr 2135ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted KremenekStmt::child_iterator ObjCMessageExpr::child_begin() { 21365549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return getReceiver() ? &SubExprs[0] : &SubExprs[0] + ARGS_START; 2137563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 2138563477da25f824e37c535131695dc4dc9b68c465Steve NaroffStmt::child_iterator ObjCMessageExpr::child_end() { 21395549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek return &SubExprs[0]+ARGS_START+getNumArgs(); 2140563477da25f824e37c535131695dc4dc9b68c465Steve Naroff} 2141563477da25f824e37c535131695dc4dc9b68c465Steve Naroff 21424eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Blocks 214356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_begin() { return child_iterator(); } 214456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_end() { return child_iterator(); } 21454eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff 21469da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_begin() { return child_iterator();} 21479da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator(); } 2148