Expr.cpp revision ee5a700af3fe9ae1a639c271f093f40677dddc04
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"
15a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/APValue.h"
162eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner#include "clang/AST/ASTContext.h"
17a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner#include "clang/AST/DeclObjC.h"
18e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar#include "clang/AST/RecordLayout.h"
195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/AST/StmtVisitor.h"
20da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner#include "clang/Basic/TargetInfo.h"
215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerusing namespace clang;
225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Primary Expressions.
255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
27da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// getValueAsApproximateDouble - This returns the value as an inaccurate
28da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// double.  Note that this may cause loss of precision, but is useful for
29da8249e57f3badecf925571881fe57243935c6c1Chris Lattner/// debugging dumps, etc.
30da8249e57f3badecf925571881fe57243935c6c1Chris Lattnerdouble FloatingLiteral::getValueAsApproximateDouble() const {
31da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  llvm::APFloat V = getValue();
32ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen  bool ignored;
33ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen  V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven,
34ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen            &ignored);
35da8249e57f3badecf925571881fe57243935c6c1Chris Lattner  return V.convertToDouble();
36da8249e57f3badecf925571881fe57243935c6c1Chris Lattner}
37da8249e57f3badecf925571881fe57243935c6c1Chris Lattner
38da8249e57f3badecf925571881fe57243935c6c1Chris Lattner
395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerStringLiteral::StringLiteral(const char *strData, unsigned byteLength,
405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             bool Wide, QualType t, SourceLocation firstLoc,
415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                             SourceLocation lastLoc) :
425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Expr(StringLiteralClass, t) {
435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // OPTIMIZE: could allocate this appended to the StringLiteral.
445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  char *AStrData = new char[byteLength];
455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  memcpy(AStrData, strData, byteLength);
465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  StrData = AStrData;
475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  ByteLength = byteLength;
485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  IsWide = Wide;
495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  firstTokLoc = firstLoc;
505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  lastTokLoc = lastLoc;
515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerStringLiteral::~StringLiteral() {
545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  delete[] StrData;
555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool UnaryOperator::isPostfix(Opcode Op) {
585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (Op) {
595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PostInc:
605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PostDec:
615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return true;
625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
675a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenekbool UnaryOperator::isPrefix(Opcode Op) {
685a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  switch (Op) {
695a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek    case PreInc:
705a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek    case PreDec:
715a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek      return true;
725a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek    default:
735a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek      return false;
745a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek  }
755a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek}
765a56ac30d04e8f0431a08980885662a47a6308aaTed Kremenek
775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "sizeof" or "[pre]++".
795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *UnaryOperator::getOpcodeStr(Opcode Op) {
805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (Op) {
815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default: assert(0 && "Unknown unary operator");
825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PostInc: return "++";
835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PostDec: return "--";
845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PreInc:  return "++";
855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case PreDec:  return "--";
865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case AddrOf:  return "&";
875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Deref:   return "*";
885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Plus:    return "+";
895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Minus:   return "-";
905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Not:     return "~";
915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LNot:    return "!";
925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Real:    return "__real";
935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Imag:    return "__imag";
945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case SizeOf:  return "sizeof";
955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case AlignOf: return "alignof";
965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Extension: return "__extension__";
9773d0d4fac161ed12926e010dcf8b448a8de6a2ecChris Lattner  case OffsetOf: return "__builtin_offsetof";
985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
1015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
1025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Postfix Operators.
1035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
1045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
105e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman
1065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid SpencerCallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
1075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                   SourceLocation rparenloc)
10877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  : Expr(CallExprClass, t), NumArgs(numargs) {
1095549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  SubExprs = new Stmt*[numargs+1];
11077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek  SubExprs[FN] = fn;
1115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  for (unsigned i = 0; i != numargs; ++i)
11277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek    SubExprs[i+ARGS_START] = args[i];
1135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  RParenLoc = rparenloc;
1145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
1155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
116d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// setNumArgs - This changes the number of arguments present in this call.
117d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// Any orphaned expressions are deleted by this, and any new operands are set
118d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner/// to null.
119d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattnervoid CallExpr::setNumArgs(unsigned NumArgs) {
120d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // No change, just return.
121d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  if (NumArgs == getNumArgs()) return;
122d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
123d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // If shrinking # arguments, just delete the extras and forgot them.
124d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  if (NumArgs < getNumArgs()) {
125d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i)
126d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner      delete getArg(i);
127d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    this->NumArgs = NumArgs;
128d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    return;
129d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  }
130d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
131d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Otherwise, we are growing the # arguments.  New an bigger argument array.
1325549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  Stmt **NewSubExprs = new Stmt*[NumArgs+1];
133d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Copy over args.
134d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i)
135d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    NewSubExprs[i] = SubExprs[i];
136d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  // Null out new args.
137d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i)
138d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner    NewSubExprs[i] = 0;
139d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
140d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  delete[] SubExprs;
141d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  SubExprs = NewSubExprs;
142d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner  this->NumArgs = NumArgs;
143d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner}
144d18b3299debb7b0dbd9d34d9369189dc98c87f53Chris Lattner
145cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// isBuiltinCall - If this is a call to a builtin, return the builtin ID.  If
146cb888967400a03504c88acedd5248d6778a82f46Chris Lattner/// not, return 0.
147cb888967400a03504c88acedd5248d6778a82f46Chris Lattnerunsigned CallExpr::isBuiltinCall() const {
148c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  // All simple function calls (e.g. func()) are implicitly cast to pointer to
149c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  // function. As a result, we try and obtain the DeclRefExpr from the
150c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  // ImplicitCastExpr.
151c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee());
152c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
153cb888967400a03504c88acedd5248d6778a82f46Chris Lattner    return 0;
154cb888967400a03504c88acedd5248d6778a82f46Chris Lattner
155c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr());
156c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff  if (!DRE)
157cb888967400a03504c88acedd5248d6778a82f46Chris Lattner    return 0;
158cb888967400a03504c88acedd5248d6778a82f46Chris Lattner
159bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl());
160bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson  if (!FDecl)
161cb888967400a03504c88acedd5248d6778a82f46Chris Lattner    return 0;
162cb888967400a03504c88acedd5248d6778a82f46Chris Lattner
163cb888967400a03504c88acedd5248d6778a82f46Chris Lattner  return FDecl->getIdentifier()->getBuiltinID();
164cb888967400a03504c88acedd5248d6778a82f46Chris Lattner}
165bcba201a1118d7852b8b97187d495ae2a4f49519Anders Carlsson
166cb888967400a03504c88acedd5248d6778a82f46Chris Lattner
1675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
1685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// corresponds to, e.g. "<<=".
1695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerconst char *BinaryOperator::getOpcodeStr(Opcode Op) {
1705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (Op) {
1715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default: assert(0 && "Unknown binary operator");
1725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Mul:       return "*";
1735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Div:       return "/";
1745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Rem:       return "%";
1755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Add:       return "+";
1765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Sub:       return "-";
1775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Shl:       return "<<";
1785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Shr:       return ">>";
1795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LT:        return "<";
1805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case GT:        return ">";
1815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LE:        return "<=";
1825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case GE:        return ">=";
1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case EQ:        return "==";
1845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case NE:        return "!=";
1855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case And:       return "&";
1865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Xor:       return "^";
1875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Or:        return "|";
1885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LAnd:      return "&&";
1895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LOr:       return "||";
1905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Assign:    return "=";
1915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case MulAssign: return "*=";
1925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DivAssign: return "/=";
1935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case RemAssign: return "%=";
1945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case AddAssign: return "+=";
1955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case SubAssign: return "-=";
1965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ShlAssign: return "<<=";
1975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ShrAssign: return ">>=";
1985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case AndAssign: return "&=";
1995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case XorAssign: return "^=";
2005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case OrAssign:  return "|=";
2015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case Comma:     return ",";
2025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
2035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
2045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
20566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonInitListExpr::InitListExpr(SourceLocation lbraceloc,
20666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson                           Expr **initexprs, unsigned numinits,
20766b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson                           SourceLocation rbraceloc)
208c5ae899b4bbf65488445316c63168079177db0edSteve Naroff  : Expr(InitListExprClass, QualType()),
209c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    LBraceLoc(lbraceloc), RBraceLoc(rbraceloc)
21066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson{
21166b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson  for (unsigned i = 0; i != numinits; i++)
212c5ae899b4bbf65488445316c63168079177db0edSteve Naroff    InitExprs.push_back(initexprs[i]);
21366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}
2145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
215bfdcae678d44906293e21c0cddc6537f3ee8b5a4Steve Naroff/// getFunctionType - Return the underlying function type for this block.
2164eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff///
2174eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroffconst FunctionType *BlockExpr::getFunctionType() const {
2184eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff  return getType()->getAsBlockPointerType()->
2194eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff                    getPointeeType()->getAsFunctionType();
2204eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff}
2214eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
22256ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffSourceLocation BlockExpr::getCaretLocation() const {
22356ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff  return TheBlock->getCaretLocation();
22456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff}
22556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroffconst Stmt *BlockExpr::getBody() const { return TheBlock->getBody(); }
22656ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt *BlockExpr::getBody() { return TheBlock->getBody(); }
22756ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
22856ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve Naroff
2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// Generic Expression Routines
2315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===//
2325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// hasLocalSideEffect - Return true if this immediate expression has side
2345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// effects, not counting any sub-expressions.
2355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerbool Expr::hasLocalSideEffect() const {
2365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (getStmtClass()) {
2375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
2385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
2395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ParenExprClass:
2405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return cast<ParenExpr>(this)->getSubExpr()->hasLocalSideEffect();
2415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case UnaryOperatorClass: {
2425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const UnaryOperator *UO = cast<UnaryOperator>(this);
2435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    switch (UO->getOpcode()) {
2455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    default: return false;
2465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::PostInc:
2475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::PostDec:
2485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::PreInc:
2495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::PreDec:
2505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return true;                     // ++/--
2515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Deref:
2535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // Dereferencing a volatile pointer is a side-effect.
2545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return getType().isVolatileQualified();
2555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Real:
2565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Imag:
2575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // accessing a piece of a volatile complex is a side-effect.
2585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return UO->getSubExpr()->getType().isVolatileQualified();
2595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
2605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Extension:
2615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return UO->getSubExpr()->hasLocalSideEffect();
2625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
2635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
264e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner  case BinaryOperatorClass: {
265e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner    const BinaryOperator *BinOp = cast<BinaryOperator>(this);
266e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner    // Consider comma to have side effects if the LHS and RHS both do.
267e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner    if (BinOp->getOpcode() == BinaryOperator::Comma)
268e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner      return BinOp->getLHS()->hasLocalSideEffect() &&
269e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner             BinOp->getRHS()->hasLocalSideEffect();
270e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner
271e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner    return BinOp->isAssignmentOp();
272e7716e6133e23e4a89248a65a388bc840d8c130cChris Lattner  }
273eb14fe839ec24c2ca14e5f094be147a34e3d3339Chris Lattner  case CompoundAssignOperatorClass:
2741f683e9cf2e855b32d3fb4b142aa121cd3cf1088Chris Lattner    return true;
2755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
276ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian  case ConditionalOperatorClass: {
277ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian    const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
278ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian    return Exp->getCond()->hasLocalSideEffect()
279ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian           || (Exp->getLHS() && Exp->getLHS()->hasLocalSideEffect())
280ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian           || (Exp->getRHS() && Exp->getRHS()->hasLocalSideEffect());
281ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian  }
282ab38e4b50268633f037a10841fdfb612513f8d33Fariborz Jahanian
2835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case MemberExprClass:
2845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ArraySubscriptExprClass:
2855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // If the base pointer or element is to a volatile pointer/field, accessing
2865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // if is a side effect.
2875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return getType().isVolatileQualified();
288211f6adf1301a1461015fb6cb08a05f0a35b65f3Eli Friedman
2895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case CallExprClass:
2905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // TODO: check attributes for pure/const.   "void foo() { strlen("bar"); }"
2915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // should warn.
2925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return true;
293a9c01021724b9b546d282b8609cbe559734812ecChris Lattner  case ObjCMessageExprClass:
294a9c01021724b9b546d282b8609cbe559734812ecChris Lattner    return true;
295611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner  case StmtExprClass: {
296611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // Statement exprs don't logically have side effects themselves, but are
297611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // sometimes used in macros in ways that give them a type that is unused.
298611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // For example ({ blah; foo(); }) will end up with a type if foo has a type.
299611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // however, if the result of the stmt expr is dead, we don't want to emit a
300611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    // warning.
301611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt();
302611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    if (!CS->body_empty())
303611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner      if (const Expr *E = dyn_cast<Expr>(CS->body_back()))
304611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner        return E->hasLocalSideEffect();
305611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner    return false;
306611b2eccaf3869f32de51ecc02985426d1c0aaefChris Lattner  }
3070835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  case ExplicitCastExprClass:
308987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  case CXXFunctionalCastExprClass:
3095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // If this is a cast to void, check the operand.  Otherwise, the result of
3105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // the cast is unused.
3115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (getType()->isVoidType())
3125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return cast<CastExpr>(this)->getSubExpr()->hasLocalSideEffect();
3135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
31404421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner
3154be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman  case ImplicitCastExprClass:
3164be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman    // Check the operand, since implicit casts are inserted by Sema
3174be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman    return cast<ImplicitCastExpr>(this)->getSubExpr()->hasLocalSideEffect();
3184be1f47de20525ad90f02ba8682a7e2cbd3205d1Eli Friedman
31904421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
32004421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    return cast<CXXDefaultArgExpr>(this)->getExpr()->hasLocalSideEffect();
3215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
3225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
3235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
3245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or an
3255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// incomplete type other than void. Nonarray expressions that can be lvalues:
3265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - name, where name must be a variable
3275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - e[i]
3285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - (e), where e must be an lvalue
3295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - e.name, where e must be an lvalue
3305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - e->name
3315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - *e, the type of e cannot be a function type
3325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///  - string-constant
3337da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner///  - (__real__ e) and (__imag__ e) where e is an lvalue  [GNU extension]
33408ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling///  - reference type [C++ [expr]]
3355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
33628be73f74c9e241a23ea24fe5756623de6bf1084Chris LattnerExpr::isLvalueResult Expr::isLvalue(ASTContext &Ctx) const {
3375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // first, check the type (C99 6.3.2.1)
338cb4f9a6d0be445d84af35ba81323be6127816f9eChris Lattner  if (TR->isFunctionType()) // from isObjectType()
3395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return LV_NotObjectType;
3405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
341acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff  // Allow qualified void which is an incomplete type other than void (yuck).
34228be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner  if (TR->isVoidType() && !Ctx.getCanonicalType(TR).getCVRQualifiers())
343acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff    return LV_IncompleteVoidType;
344acb818a4f7d9b608826171094d6b5a555a8fe694Steve Naroff
345cb4f9a6d0be445d84af35ba81323be6127816f9eChris Lattner  if (TR->isReferenceType()) // C++ [expr]
34608ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling    return LV_Valid;
34708ad47cbd1f81fcb31dbc731c13b885a07e12704Bill Wendling
3485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // the type looks fine, now check the expression
3495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (getStmtClass()) {
3505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case StringLiteralClass: // C99 6.5.1p4
3517323a6297edad643c202594dcf3d9a174de96ca6Anders Carlsson    return LV_Valid;
3525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2))))
3535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // For vectors, make sure base is an lvalue (i.e. not a function call).
3545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType())
35528be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner      return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue(Ctx);
3565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return LV_Valid;
3574111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  case DeclRefExprClass: { // C99 6.5.1p2
3584111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner    const Decl *RefdDecl = cast<DeclRefExpr>(this)->getDecl();
3594111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner    if (isa<VarDecl>(RefdDecl) || isa<ImplicitParamDecl>(RefdDecl))
3605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return LV_Valid;
3615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
3624111024be81e7c0525e42dadcc126d27e5bf2425Chris Lattner  }
363dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff  case BlockDeclRefExprClass: {
364dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff    const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this);
3654f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff    if (isa<VarDecl>(BDR->getDecl()))
366dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff      return LV_Valid;
367dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff    break;
368dd972f20dc2bd3609d833893e5c6544ac09b59a9Steve Naroff  }
369fdd75663fffeb2058a7847975e50837e61200593Anton Korobeynikov  case MemberExprClass: { // C99 6.5.2.3p4
3705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const MemberExpr *m = cast<MemberExpr>(this);
37128be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner    return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(Ctx);
372fdd75663fffeb2058a7847975e50837e61200593Anton Korobeynikov  }
3737da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner  case UnaryOperatorClass:
3745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
3757da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner      return LV_Valid; // C99 6.5.3p4
3767da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner
3777da36f642e907ff5a5ba4b18b5bfebfabf36ecc7Chris Lattner    if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real ||
378baf0d6678418e0dd9309438c3e50274253cfc7b2Chris Lattner        cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag ||
379baf0d6678418e0dd9309438c3e50274253cfc7b2Chris Lattner        cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Extension)
38028be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner      return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(Ctx);  // GNU.
3815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
3825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ParenExprClass: // C99 6.5.1p5
38328be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner    return cast<ParenExpr>(this)->getSubExpr()->isLvalue(Ctx);
384e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff  case CompoundLiteralExprClass: // C99 6.5.2.5p5
385e6386394677ed4f77b20e2e3d5446a3a2f628e53Steve Naroff    return LV_Valid;
386213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman  case ExtVectorElementExprClass:
387213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman    if (cast<ExtVectorElementExpr>(this)->containsDuplicateElements())
388fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff      return LV_DuplicateVectorComponents;
389fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    return LV_Valid;
390027282d1c1ac151aa7b1b3b45babc918b8ad456aSteve Naroff  case ObjCIvarRefExprClass: // ObjC instance variables are lvalues.
391027282d1c1ac151aa7b1b3b45babc918b8ad456aSteve Naroff    return LV_Valid;
392799a6a6850af625946bb8d88ca960bb6604e3858Steve Naroff  case ObjCPropertyRefExprClass: // FIXME: check if read-only property.
393799a6a6850af625946bb8d88ca960bb6604e3858Steve Naroff    return LV_Valid;
394d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  case PredefinedExprClass:
395d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner    return (cast<PredefinedExpr>(this)->getIdentType()
396d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner               == PredefinedExpr::CXXThis
3977c4a191d8be7eac565a64369de072b2a52bf6749Chris Lattner            ? LV_InvalidExpression : LV_Valid);
39804421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
39928be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner    return cast<CXXDefaultArgExpr>(this)->getExpr()->isLvalue(Ctx);
40024b41fa8239c63b9eb570d3e83c4a82840656a65Argyrios Kyrtzidis  case CXXConditionDeclExprClass:
40124b41fa8239c63b9eb570d3e83c4a82840656a65Argyrios Kyrtzidis    return LV_Valid;
4025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
4035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
4045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return LV_InvalidExpression;
4065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
4095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// does not have an incomplete type, does not have a const-qualified type, and
4105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// if it is a structure or union, does not have any member (including,
4115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// recursively, any member or element of all contained aggregates or unions)
4125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// with a const-qualified type.
41328be73f74c9e241a23ea24fe5756623de6bf1084Chris LattnerExpr::isModifiableLvalueResult Expr::isModifiableLvalue(ASTContext &Ctx) const {
41428be73f74c9e241a23ea24fe5756623de6bf1084Chris Lattner  isLvalueResult lvalResult = isLvalue(Ctx);
4155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (lvalResult) {
4175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LV_Valid: break;
4185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LV_NotObjectType: return MLV_NotObjectType;
4195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LV_IncompleteVoidType: return MLV_IncompleteVoidType;
420fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents;
4215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case LV_InvalidExpression: return MLV_InvalidExpression;
4225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
423c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
424c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  QualType CT = Ctx.getCanonicalType(getType());
425c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner
426c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  if (CT.isConstQualified())
4275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return MLV_ConstQualified;
428c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  if (CT->isArrayType())
4295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return MLV_ArrayType;
430c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  if (CT->isIncompleteType())
4315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return MLV_IncompleteType;
4325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
433c63a1f276f7b324fd9a4be82098b1c8f7bf30733Chris Lattner  if (const RecordType *r = CT->getAsRecordType()) {
4345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (r->hasConstFields())
4355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return MLV_ConstQualified;
4365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
4374f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff  // The following is illegal:
4384f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff  //   void takeclosure(void (^C)(void));
4394f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff  //   void func() { int x = 1; takeclosure(^{ x = 7 }); }
4404f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff  //
4414f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff  if (getStmtClass() == BlockDeclRefExprClass) {
4424f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff    const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this);
4434f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff    if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl()))
4444f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff      return MLV_NotBlockQualified;
4454f6a7d7ead09b439216c32f2de806a998aeb222aSteve Naroff  }
4465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return MLV_Valid;
4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
4485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
4492e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek/// hasGlobalStorage - Return true if this expression has static storage
4504cc627111453b75519d5130b57e06256da7b00e8Chris Lattner/// duration.  This means that the address of this expression is a link-time
4514cc627111453b75519d5130b57e06256da7b00e8Chris Lattner/// constant.
4522e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenekbool Expr::hasGlobalStorage() const {
4531d09ecca892185ba067e47ba879f424de59950efChris Lattner  switch (getStmtClass()) {
4541d09ecca892185ba067e47ba879f424de59950efChris Lattner  default:
4551d09ecca892185ba067e47ba879f424de59950efChris Lattner    return false;
4564cc627111453b75519d5130b57e06256da7b00e8Chris Lattner  case ParenExprClass:
4572e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek    return cast<ParenExpr>(this)->getSubExpr()->hasGlobalStorage();
4584cc627111453b75519d5130b57e06256da7b00e8Chris Lattner  case ImplicitCastExprClass:
4592e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek    return cast<ImplicitCastExpr>(this)->getSubExpr()->hasGlobalStorage();
460e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff  case CompoundLiteralExprClass:
461e9b12198c4cc7f5687960100351b4af006c14469Steve Naroff    return cast<CompoundLiteralExpr>(this)->isFileScope();
4621d09ecca892185ba067e47ba879f424de59950efChris Lattner  case DeclRefExprClass: {
4631d09ecca892185ba067e47ba879f424de59950efChris Lattner    const Decl *D = cast<DeclRefExpr>(this)->getDecl();
4641d09ecca892185ba067e47ba879f424de59950efChris Lattner    if (const VarDecl *VD = dyn_cast<VarDecl>(D))
4652e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek      return VD->hasGlobalStorage();
46663f067f5a75ae97b53dc7a6a6530e2c72c8bb7f8Seo Sanghyeon    if (isa<FunctionDecl>(D))
46763f067f5a75ae97b53dc7a6a6530e2c72c8bb7f8Seo Sanghyeon      return true;
4681d09ecca892185ba067e47ba879f424de59950efChris Lattner    return false;
4691d09ecca892185ba067e47ba879f424de59950efChris Lattner  }
470fb7080663a0f0abd687a6f58ac917d9a76318b73Chris Lattner  case MemberExprClass: {
4711d09ecca892185ba067e47ba879f424de59950efChris Lattner    const MemberExpr *M = cast<MemberExpr>(this);
4722e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek    return !M->isArrow() && M->getBase()->hasGlobalStorage();
473fb7080663a0f0abd687a6f58ac917d9a76318b73Chris Lattner  }
4744cc627111453b75519d5130b57e06256da7b00e8Chris Lattner  case ArraySubscriptExprClass:
4752e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek    return cast<ArraySubscriptExpr>(this)->getBase()->hasGlobalStorage();
476d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner  case PredefinedExprClass:
477fa28b30d5a1e93e5263be33e343532b900d2c643Chris Lattner    return true;
47804421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
47904421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    return cast<CXXDefaultArgExpr>(this)->getExpr()->hasGlobalStorage();
4801d09ecca892185ba067e47ba879f424de59950efChris Lattner  }
4811d09ecca892185ba067e47ba879f424de59950efChris Lattner}
4821d09ecca892185ba067e47ba879f424de59950efChris Lattner
4834e99a5fc3b203397a91136c6e695e405fb8fc606Ted KremenekExpr* Expr::IgnoreParens() {
4844e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  Expr* E = this;
4854e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  while (ParenExpr* P = dyn_cast<ParenExpr>(E))
4864e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek    E = P->getSubExpr();
4874e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
4884e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek  return E;
4894e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek}
4904e99a5fc3b203397a91136c6e695e405fb8fc606Ted Kremenek
49156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
49256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner/// or CastExprs or ImplicitCastExprs, returning their operand.
49356f349400c5932a196509c0480ff6f99a9a0b48fChris LattnerExpr *Expr::IgnoreParenCasts() {
49456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  Expr *E = this;
49556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  while (true) {
49656f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    if (ParenExpr *P = dyn_cast<ParenExpr>(E))
49756f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      E = P->getSubExpr();
49856f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    else if (CastExpr *P = dyn_cast<CastExpr>(E))
49956f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      E = P->getSubExpr();
50056f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner    else
50156f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner      return E;
50256f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner  }
50356f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner}
50456f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
50556f349400c5932a196509c0480ff6f99a9a0b48fChris Lattner
50638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroffbool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
50738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  switch (getStmtClass()) {
50838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  default:
50938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (Loc) *Loc = getLocStart();
51038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    return false;
51138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case ParenExprClass:
51238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    return cast<ParenExpr>(this)->getSubExpr()->isConstantExpr(Ctx, Loc);
51338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case StringLiteralClass:
5145d37e32a5bfefacdd7b4d0664199d72c703d489dSteve Naroff  case ObjCStringLiteralClass:
51538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case FloatingLiteralClass:
51638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case IntegerLiteralClass:
51738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case CharacterLiteralClass:
51838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case ImaginaryLiteralClass:
5191a86b33c1870fee08d281c9f07ac1280195a7faeAnders Carlsson  case TypesCompatibleExprClass:
5201a86b33c1870fee08d281c9f07ac1280195a7faeAnders Carlsson  case CXXBoolLiteralExprClass:
52115425f9d2d92e2a5f99b09b8e2fc00025631e593Anders Carlsson  case AddrLabelExprClass:
5222777e494c96bee69141a10a0174d5da16e7b927bChris Lattner    return true;
52338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case CallExprClass: {
52438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    const CallExpr *CE = cast<CallExpr>(this);
52545b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner
52645b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner    // Allow any constant foldable calls to builtins.
52745b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner    if (CE->isBuiltinCall() && CE->isEvaluatable(Ctx))
528c4f8e8b645b8e0e685c089dde0674c6f29a24168Steve Naroff      return true;
52945b6b9d080ac56917337d73d8f1cd6374b27b05dChris Lattner
53038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (Loc) *Loc = getLocStart();
53138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    return false;
53238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
5334ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner  case DeclRefExprClass: {
5344ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner    const Decl *D = cast<DeclRefExpr>(this)->getDecl();
5354ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner    // Accept address of function.
5364ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner    if (isa<EnumConstantDecl>(D) || isa<FunctionDecl>(D))
5372777e494c96bee69141a10a0174d5da16e7b927bChris Lattner      return true;
53838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (Loc) *Loc = getLocStart();
5391d09ecca892185ba067e47ba879f424de59950efChris Lattner    if (isa<VarDecl>(D))
5401d09ecca892185ba067e47ba879f424de59950efChris Lattner      return TR->isArrayType();
54138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    return false;
5424ef8dd6e8736097bf9e3c387139c668565d89dcaChris Lattner  }
543b8f13a8baff3df080fe024fec47746e9a79fe649Steve Naroff  case CompoundLiteralExprClass:
544b8f13a8baff3df080fe024fec47746e9a79fe649Steve Naroff    if (Loc) *Loc = getLocStart();
545b8f13a8baff3df080fe024fec47746e9a79fe649Steve Naroff    // Allow "(int []){2,4}", since the array will be converted to a pointer.
546d47d4f518e43eaa716e2d18359bd725a03b87f58Nate Begeman    // Allow "(vector type){2,4}" since the elements are all constant.
547d47d4f518e43eaa716e2d18359bd725a03b87f58Nate Begeman    return TR->isArrayType() || TR->isVectorType();
54838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case UnaryOperatorClass: {
54938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    const UnaryOperator *Exp = cast<UnaryOperator>(this);
55038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
5511d09ecca892185ba067e47ba879f424de59950efChris Lattner    // C99 6.6p9
552239c15e5b07a6cc84278ede87edf638922767520Chris Lattner    if (Exp->getOpcode() == UnaryOperator::AddrOf) {
5532e5f54aa1dd15a62c34a9d1d24a5a0692f43934aTed Kremenek      if (!Exp->getSubExpr()->hasGlobalStorage()) {
554239c15e5b07a6cc84278ede87edf638922767520Chris Lattner        if (Loc) *Loc = getLocStart();
555239c15e5b07a6cc84278ede87edf638922767520Chris Lattner        return false;
556239c15e5b07a6cc84278ede87edf638922767520Chris Lattner      }
557239c15e5b07a6cc84278ede87edf638922767520Chris Lattner      return true;
558239c15e5b07a6cc84278ede87edf638922767520Chris Lattner    }
5591d09ecca892185ba067e47ba879f424de59950efChris Lattner
56038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    // Get the operand value.  If this is sizeof/alignof, do not evalute the
56138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    // operand.  This affects C99 6.6p3.
562d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    if (!Exp->isSizeOfAlignOfOp() &&
563d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff        Exp->getOpcode() != UnaryOperator::OffsetOf &&
56438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff        !Exp->getSubExpr()->isConstantExpr(Ctx, Loc))
56538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
56638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
56738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    switch (Exp->getOpcode()) {
56838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    // Address, indirect, pre/post inc/dec, etc are not valid constant exprs.
56938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    // See C99 6.6p3.
57038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    default:
57138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      if (Loc) *Loc = Exp->getOperatorLoc();
57238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
57338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::Extension:
57438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return true;  // FIXME: this is wrong.
57538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::SizeOf:
57638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::AlignOf:
577d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    case UnaryOperator::OffsetOf:
57838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
5793c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman      if (!Exp->getSubExpr()->getType()->isConstantSizeType()) {
58065383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner        if (Loc) *Loc = Exp->getOperatorLoc();
58138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff        return false;
58265383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner      }
5832777e494c96bee69141a10a0174d5da16e7b927bChris Lattner      return true;
58438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::LNot:
58538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::Plus:
58638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::Minus:
58738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    case UnaryOperator::Not:
5882777e494c96bee69141a10a0174d5da16e7b927bChris Lattner      return true;
58938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    }
59038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
59138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case SizeOfAlignOfTypeExprClass: {
59238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this);
59338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    // alignof always evaluates to a constant.
594a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner    if (Exp->isSizeOf() && !Exp->getArgumentType()->isVoidType() &&
595a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner        !Exp->getArgumentType()->isConstantSizeType()) {
59665383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner      if (Loc) *Loc = Exp->getOperatorLoc();
59738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
59865383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner    }
5992777e494c96bee69141a10a0174d5da16e7b927bChris Lattner    return true;
60038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
60138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case BinaryOperatorClass: {
60238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    const BinaryOperator *Exp = cast<BinaryOperator>(this);
60338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
60438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    // The LHS of a constant expr is always evaluated and needed.
60538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (!Exp->getLHS()->isConstantExpr(Ctx, Loc))
60638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
60738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
60838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (!Exp->getRHS()->isConstantExpr(Ctx, Loc))
60938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
6102777e494c96bee69141a10a0174d5da16e7b927bChris Lattner    return true;
61138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
61238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case ImplicitCastExprClass:
613987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  case ExplicitCastExprClass:
614987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  case CXXFunctionalCastExprClass: {
6150835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    const Expr *SubExpr = cast<CastExpr>(this)->getSubExpr();
6160835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    SourceLocation CastLoc = getLocStart();
61738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    if (!SubExpr->isConstantExpr(Ctx, Loc)) {
61838374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      if (Loc) *Loc = SubExpr->getLocStart();
61938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
62038374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    }
6212777e494c96bee69141a10a0174d5da16e7b927bChris Lattner    return true;
62238374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
62338374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  case ConditionalOperatorClass: {
62438374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff    const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
6252777e494c96bee69141a10a0174d5da16e7b927bChris Lattner    if (!Exp->getCond()->isConstantExpr(Ctx, Loc) ||
6263907323dd6665c0c4e383435cb145233f4533406Anders Carlsson        // Handle the GNU extension for missing LHS.
6273907323dd6665c0c4e383435cb145233f4533406Anders Carlsson        !(Exp->getLHS() && Exp->getLHS()->isConstantExpr(Ctx, Loc)) ||
6282777e494c96bee69141a10a0174d5da16e7b927bChris Lattner        !Exp->getRHS()->isConstantExpr(Ctx, Loc))
62938374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff      return false;
6302777e494c96bee69141a10a0174d5da16e7b927bChris Lattner    return true;
63138374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
632d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff  case InitListExprClass: {
633d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    const InitListExpr *Exp = cast<InitListExpr>(this);
634d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    unsigned numInits = Exp->getNumInits();
635d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    for (unsigned i = 0; i < numInits; i++) {
636d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff      if (!Exp->getInit(i)->isConstantExpr(Ctx, Loc)) {
637d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff        if (Loc) *Loc = Exp->getInit(i)->getLocStart();
638d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff        return false;
639d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff      }
640d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    }
641d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff    return true;
642d0091aa3850a8c8be94c68710ed4ef1317729ba0Steve Naroff  }
64304421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
64404421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    return cast<CXXDefaultArgExpr>(this)->getExpr()->isConstantExpr(Ctx, Loc);
64538374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff  }
64638374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff}
64738374b05791ee93300b9fbe8ceb3957f54184b37Steve Naroff
6485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isIntegerConstantExpr - this recursive routine will test if an expression is
6495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// an integer constant expression. Note: With the introduction of VLA's in
6505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// C99 the result of the sizeof operator is no longer always a constant
6515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expression. The generalization of the wording to include any subexpression
6525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// that is not evaluated (C99 6.6p3) means that nonconstant subexpressions
6535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// can appear as operands to other operators (e.g. &&, ||, ?:). For instance,
6545f6b632391e24b08ead3e62ba2e2765e770382edNuno Lopes/// "0 || f()" can be treated as a constant expression. In C90 this expression,
6555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// occurring in a context requiring a constant, would have been a constraint
6565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// violation. FIXME: This routine currently implements C90 semantics.
6575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// To properly implement C99 semantics this routine will need to evaluate
6585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// expressions involving operators previously mentioned.
6595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
6605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FIXME: Pass up a reason why! Invalid operation in i-c-e, division by zero,
6615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// comma, etc
6625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer///
6635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// FIXME: This should ext-warn on overflow during evaluation!  ISO C does not
664ccc213f5d4034bb6fcda14cad112d9029a508b66Chris Lattner/// permit this.  This includes things like (int)1e1000
665ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner///
666ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// FIXME: Handle offsetof.  Two things to do:  Handle GCC's __builtin_offsetof
667ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// to support gcc 4.0+  and handle the idiom GCC recognizes with a null pointer
668ce0afc0b09accbf7370b2ba87574b2c4be7fb032Chris Lattner/// cast+dereference.
669590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattnerbool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
670590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                                 SourceLocation *Loc, bool isEvaluated) const {
6715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  switch (getStmtClass()) {
6725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  default:
6735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Loc) *Loc = getLocStart();
6745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
6755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ParenExprClass:
6765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return cast<ParenExpr>(this)->getSubExpr()->
677590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner                     isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated);
6785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case IntegerLiteralClass:
6795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    Result = cast<IntegerLiteral>(this)->getValue();
6805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
6812eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner  case CharacterLiteralClass: {
6822eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner    const CharacterLiteral *CL = cast<CharacterLiteral>(this);
68398be4943e8dc4f3905629a7102668960873cf863Chris Lattner    Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
6842eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner    Result = CL->getValue();
685f0fbcb356bc4eb5f6467dc4fc4bc447e9a630102Chris Lattner    Result.setIsUnsigned(!getType()->isSignedIntegerType());
6865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
6872eadfb638eb1bb6ccfd6fd0453e764d47e27eed9Chris Lattner  }
688b88d45ea7eb835d36c4a4b3ea84b1260b120dd0aAnders Carlsson  case CXXBoolLiteralExprClass: {
689b88d45ea7eb835d36c4a4b3ea84b1260b120dd0aAnders Carlsson    const CXXBoolLiteralExpr *BL = cast<CXXBoolLiteralExpr>(this);
690b88d45ea7eb835d36c4a4b3ea84b1260b120dd0aAnders Carlsson    Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
691b88d45ea7eb835d36c4a4b3ea84b1260b120dd0aAnders Carlsson    Result = BL->getValue();
692b88d45ea7eb835d36c4a4b3ea84b1260b120dd0aAnders Carlsson    Result.setIsUnsigned(!getType()->isSignedIntegerType());
693b88d45ea7eb835d36c4a4b3ea84b1260b120dd0aAnders Carlsson    break;
694b88d45ea7eb835d36c4a4b3ea84b1260b120dd0aAnders Carlsson  }
6957267f7832e5f0c7f951765e201c5a2650eb1637bArgyrios Kyrtzidis  case CXXZeroInitValueExprClass:
6967267f7832e5f0c7f951765e201c5a2650eb1637bArgyrios Kyrtzidis    Result.clear();
6977267f7832e5f0c7f951765e201c5a2650eb1637bArgyrios Kyrtzidis    break;
6987b658aa315784fa489a32daeacfe400512ce468dSteve Naroff  case TypesCompatibleExprClass: {
6997b658aa315784fa489a32daeacfe400512ce468dSteve Naroff    const TypesCompatibleExpr *TCE = cast<TypesCompatibleExpr>(this);
70098be4943e8dc4f3905629a7102668960873cf863Chris Lattner    Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
701ec0550fa3653d46560bf4484a2e988329c228e39Steve Naroff    Result = Ctx.typesAreCompatible(TCE->getArgType1(), TCE->getArgType2());
702389cecc83f33e93c8ba6bf2e8269b8690404416fSteve Naroff    break;
7037b658aa315784fa489a32daeacfe400512ce468dSteve Naroff  }
70413b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  case CallExprClass: {
70513b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    const CallExpr *CE = cast<CallExpr>(this);
70698be4943e8dc4f3905629a7102668960873cf863Chris Lattner    Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
707a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner
708a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner    // If this is a call to a builtin function, constant fold it otherwise
709a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner    // reject it.
710a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner    if (CE->isBuiltinCall()) {
711a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner      APValue ResultAP;
712a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner      if (CE->tryEvaluate(ResultAP, Ctx)) {
713a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner        Result = ResultAP.getInt();
714a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner        break;  // It is a constant, expand it.
715a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner      }
716a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner    }
717a4d55d89c8076b402bb168e3edeef0c2cd2a78c3Chris Lattner
71813b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    if (Loc) *Loc = getLocStart();
71913b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff    return false;
72013b7c5ff42d6077a8d59e2c9ec9e7fedd0150ae6Steve Naroff  }
7215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case DeclRefExprClass:
7225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (const EnumConstantDecl *D =
7235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer          dyn_cast<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl())) {
7245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result = D->getInitVal();
7255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
7265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
7275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Loc) *Loc = getLocStart();
7285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    return false;
7295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case UnaryOperatorClass: {
7305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const UnaryOperator *Exp = cast<UnaryOperator>(this);
7315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Get the operand value.  If this is sizeof/alignof, do not evalute the
7335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // operand.  This affects C99 6.6p3.
7345a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    if (!Exp->isSizeOfAlignOfOp() && !Exp->isOffsetOfOp() &&
735602dafdea34b78c7bc1f4601f94062afa4139e76Chris Lattner        !Exp->getSubExpr()->isIntegerConstantExpr(Result, Ctx, Loc,isEvaluated))
7365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
7375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
7385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    switch (Exp->getOpcode()) {
7395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Address, indirect, pre/post inc/dec, etc are not valid constant exprs.
7405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // See C99 6.6p3.
7415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    default:
7425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      if (Loc) *Loc = Exp->getOperatorLoc();
7435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
7445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Extension:
74576e773a443be9f006610f46529e07d4c8d857680Chris Lattner      return true;  // FIXME: this is wrong.
7465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::SizeOf:
7475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::AlignOf:
748a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner      // Return the result in the right width.
74998be4943e8dc4f3905629a7102668960873cf863Chris Lattner      Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
750a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner
751a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner      // sizeof(void) and __alignof__(void) = 1 as a gcc extension.
752a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner      if (Exp->getSubExpr()->getType()->isVoidType()) {
753a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner        Result = 1;
754a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner        break;
755a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner      }
756a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner
7575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
7583c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman      if (!Exp->getSubExpr()->getType()->isConstantSizeType()) {
75965383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner        if (Loc) *Loc = Exp->getOperatorLoc();
7605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
76165383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner      }
7625f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
76376e773a443be9f006610f46529e07d4c8d857680Chris Lattner      // Get information about the size or align.
764efdd1574e3cca00ef0410aee8b7ee36eda5a2f71Chris Lattner      if (Exp->getSubExpr()->getType()->isFunctionType()) {
765efdd1574e3cca00ef0410aee8b7ee36eda5a2f71Chris Lattner        // GCC extension: sizeof(function) = 1.
766efdd1574e3cca00ef0410aee8b7ee36eda5a2f71Chris Lattner        Result = Exp->getOpcode() == UnaryOperator::AlignOf ? 4 : 1;
767da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner      } else {
76898be4943e8dc4f3905629a7102668960873cf863Chris Lattner        unsigned CharSize = Ctx.Target.getCharWidth();
76964a31ef8d46fcdf2bca38098e3206a45052b515dAnders Carlsson        if (Exp->getOpcode() == UnaryOperator::AlignOf)
77098be4943e8dc4f3905629a7102668960873cf863Chris Lattner          Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType()) / CharSize;
77164a31ef8d46fcdf2bca38098e3206a45052b515dAnders Carlsson        else
77298be4943e8dc4f3905629a7102668960873cf863Chris Lattner          Result = Ctx.getTypeSize(Exp->getSubExpr()->getType()) / CharSize;
773da5a6b6d9fd52899499d5b7b46273ec844dcaa6eChris Lattner      }
7745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
7755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::LNot: {
776bf7553889594886213e05cd3f94a6d6f7747bf7bChris Lattner      bool Val = Result == 0;
77798be4943e8dc4f3905629a7102668960873cf863Chris Lattner      Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
7785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result = Val;
7795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
7805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
7815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Plus:
7825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
7835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Minus:
7845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result = -Result;
7855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
7865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case UnaryOperator::Not:
7875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result = ~Result;
7885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
7895a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    case UnaryOperator::OffsetOf:
790aa1f9f1d50adf294674b74510b62e863b68572bcDaniel Dunbar      Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
7915a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson      Result = Exp->evaluateOffsetOf(Ctx);
7925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
7935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
7945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
7955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case SizeOfAlignOfTypeExprClass: {
7965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this);
797a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner
798a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner    // Return the result in the right width.
79998be4943e8dc4f3905629a7102668960873cf863Chris Lattner    Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
800a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner
801a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner    // sizeof(void) and __alignof__(void) = 1 as a gcc extension.
802a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner    if (Exp->getArgumentType()->isVoidType()) {
803a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner      Result = 1;
804a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner      break;
805a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner    }
806a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner
807a269ebfd91c4fa47e051fa1fa904833a022fe025Chris Lattner    // alignof always evaluates to a constant, sizeof does if arg is not VLA.
8083c2b3170041f69a92904e3bab9b6d654eaf260acEli Friedman    if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType()) {
80965383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner      if (Loc) *Loc = Exp->getOperatorLoc();
8105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
81165383479cb2caf0f136f58fecdbdbaf9c497b7a1Chris Lattner    }
8125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
81376e773a443be9f006610f46529e07d4c8d857680Chris Lattner    // Get information about the size or align.
814efdd1574e3cca00ef0410aee8b7ee36eda5a2f71Chris Lattner    if (Exp->getArgumentType()->isFunctionType()) {
815efdd1574e3cca00ef0410aee8b7ee36eda5a2f71Chris Lattner      // GCC extension: sizeof(function) = 1.
816efdd1574e3cca00ef0410aee8b7ee36eda5a2f71Chris Lattner      Result = Exp->isSizeOf() ? 1 : 4;
8176a24acbb3dbb3bea9426716bee6ad6023ad15f3fAnders Carlsson    } else {
81898be4943e8dc4f3905629a7102668960873cf863Chris Lattner      unsigned CharSize = Ctx.Target.getCharWidth();
8196a24acbb3dbb3bea9426716bee6ad6023ad15f3fAnders Carlsson      if (Exp->isSizeOf())
82098be4943e8dc4f3905629a7102668960873cf863Chris Lattner        Result = Ctx.getTypeSize(Exp->getArgumentType()) / CharSize;
8216a24acbb3dbb3bea9426716bee6ad6023ad15f3fAnders Carlsson      else
82298be4943e8dc4f3905629a7102668960873cf863Chris Lattner        Result = Ctx.getTypeAlign(Exp->getArgumentType()) / CharSize;
823060e470e53b73167114284eb0b8c3e25bb3dad99Ted Kremenek    }
8245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
8255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
8265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case BinaryOperatorClass: {
8275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const BinaryOperator *Exp = cast<BinaryOperator>(this);
828e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    llvm::APSInt LHS, RHS;
829e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar
830e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    // Initialize result to have correct signedness and width.
831e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    Result = llvm::APSInt(static_cast<uint32_t>(Ctx.getTypeSize(getType())),
832e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar                          !getType()->isSignedIntegerType());
8335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // The LHS of a constant expr is always evaluated and needed.
835e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    if (!Exp->getLHS()->isIntegerConstantExpr(LHS, Ctx, Loc, isEvaluated))
8365f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
8375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // The short-circuiting &&/|| operators don't necessarily evaluate their
8395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // RHS.  Make sure to pass isEvaluated down correctly.
8405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Exp->isLogicalOp()) {
8415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      bool RHSEval;
8425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      if (Exp->getOpcode() == BinaryOperator::LAnd)
843e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar        RHSEval = LHS != 0;
8445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      else {
8455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        assert(Exp->getOpcode() == BinaryOperator::LOr &&"Unexpected logical");
846e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar        RHSEval = LHS == 0;
8475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      }
8485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
849590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner      if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc,
8505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer                                                isEvaluated & RHSEval))
8515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
8525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    } else {
853590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner      if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc, isEvaluated))
8545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
8555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
8565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
8575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    switch (Exp->getOpcode()) {
8585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    default:
8595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      if (Loc) *Loc = getLocStart();
8605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
8615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Mul:
862e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar      Result = LHS * RHS;
8635f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
8645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Div:
8655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      if (RHS == 0) {
8665f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        if (!isEvaluated) break;
8675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        if (Loc) *Loc = getLocStart();
8685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
8695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      }
870e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar      Result = LHS / RHS;
8715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
8725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Rem:
8735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      if (RHS == 0) {
8745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        if (!isEvaluated) break;
8755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        if (Loc) *Loc = getLocStart();
8765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
8775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      }
878e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar      Result = LHS % RHS;
8795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
880e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    case BinaryOperator::Add: Result = LHS + RHS; break;
881e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    case BinaryOperator::Sub: Result = LHS - RHS; break;
8825f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Shl:
883e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar      Result = LHS <<
884e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar        static_cast<uint32_t>(RHS.getLimitedValue(LHS.getBitWidth()-1));
885e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    break;
8865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Shr:
887e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar      Result = LHS >>
888e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar        static_cast<uint32_t>(RHS.getLimitedValue(LHS.getBitWidth()-1));
8895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
890e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    case BinaryOperator::LT:  Result = LHS < RHS; break;
891e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    case BinaryOperator::GT:  Result = LHS > RHS; break;
892e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    case BinaryOperator::LE:  Result = LHS <= RHS; break;
893e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    case BinaryOperator::GE:  Result = LHS >= RHS; break;
894e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    case BinaryOperator::EQ:  Result = LHS == RHS; break;
895e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    case BinaryOperator::NE:  Result = LHS != RHS; break;
896e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    case BinaryOperator::And: Result = LHS & RHS; break;
897e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    case BinaryOperator::Xor: Result = LHS ^ RHS; break;
898e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar    case BinaryOperator::Or:  Result = LHS | RHS; break;
8995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::LAnd:
900e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar      Result = LHS != 0 && RHS != 0;
9015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
9025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::LOr:
903e1226d24d23510e422160eb2413d9bb90de9b144Daniel Dunbar      Result = LHS != 0 || RHS != 0;
9045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
9055f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    case BinaryOperator::Comma:
9075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // C99 6.6p3: "shall not contain assignment, ..., or comma operators,
9085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // *except* when they are contained within a subexpression that is not
9095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // evaluated".  Note that Assignment can never happen due to constraints
9105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // on the LHS subexpr, so we don't need to check it here.
9115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      if (isEvaluated) {
9125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        if (Loc) *Loc = getLocStart();
9135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
9145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      }
9155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      // The result of the constant expr is the RHS.
9175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Result = RHS;
9185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return true;
9195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
9205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    assert(!Exp->isAssignmentOp() && "LHS can't be a constant expr!");
9225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
9235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
92426dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner  case ImplicitCastExprClass:
925987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  case ExplicitCastExprClass:
926987a14bf5883ef6e5d07f1c83eb6d41a8212a78cArgyrios Kyrtzidis  case CXXFunctionalCastExprClass: {
9270835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    const Expr *SubExpr = cast<CastExpr>(this)->getSubExpr();
9280835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis    SourceLocation CastLoc = getLocStart();
92926dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner
9305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // C99 6.6p6: shall only convert arithmetic types to integer types.
93126dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner    if (!SubExpr->getType()->isArithmeticType() ||
93226dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner        !getType()->isIntegerType()) {
93326dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      if (Loc) *Loc = SubExpr->getLocStart();
9345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
9355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
936987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner
93798be4943e8dc4f3905629a7102668960873cf863Chris Lattner    uint32_t DestWidth = static_cast<uint32_t>(Ctx.getTypeSize(getType()));
938987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner
9395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Handle simple integer->integer casts.
94026dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner    if (SubExpr->getType()->isIntegerType()) {
94126dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      if (!SubExpr->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
9425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer        return false;
94326dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner
94426dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      // Figure out if this is a truncate, extend or noop cast.
94526dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      // If the input is signed, do a sign extend, noop, or truncate.
946c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner      if (getType()->isBooleanType()) {
947c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner        // Conversion to bool compares against zero.
948c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner        Result = Result != 0;
949c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner        Result.zextOrTrunc(DestWidth);
950c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner      } else if (SubExpr->getType()->isSignedIntegerType())
95126dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner        Result.sextOrTrunc(DestWidth);
95226dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner      else  // If the input is unsigned, do a zero extend, noop, or truncate.
95326dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner        Result.zextOrTrunc(DestWidth);
9545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      break;
9555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
9565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Allow floating constants that are the immediate operands of casts or that
9585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // are parenthesized.
95926dc7b39267b7d29b35a7887a5b8e54697192192Chris Lattner    const Expr *Operand = SubExpr;
9605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    while (const ParenExpr *PE = dyn_cast<ParenExpr>(Operand))
9615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      Operand = PE->getSubExpr();
962987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner
963987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    // If this isn't a floating literal, we can't handle it.
964987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(Operand);
965987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    if (!FL) {
966987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner      if (Loc) *Loc = Operand->getLocStart();
967987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner      return false;
968987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    }
969c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner
970c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner    // If the destination is boolean, compare against zero.
971c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner    if (getType()->isBooleanType()) {
972c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner      Result = !FL->getValue().isZero();
973c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner      Result.zextOrTrunc(DestWidth);
974c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner      break;
975c0a356b4fa35bf3f7d6031c229c071eef1a8f7a9Chris Lattner    }
9765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
977987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    // Determine whether we are converting to unsigned or signed.
978987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    bool DestSigned = getType()->isSignedIntegerType();
979ccc213f5d4034bb6fcda14cad112d9029a508b66Chris Lattner
980ccc213f5d4034bb6fcda14cad112d9029a508b66Chris Lattner    // TODO: Warn on overflow, but probably not here: isIntegerConstantExpr can
981ccc213f5d4034bb6fcda14cad112d9029a508b66Chris Lattner    // be called multiple times per AST.
982ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen    uint64_t Space[4];
983ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen    bool ignored;
984ccc213f5d4034bb6fcda14cad112d9029a508b66Chris Lattner    (void)FL->getValue().convertToInteger(Space, DestWidth, DestSigned,
985ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen                                          llvm::APFloat::rmTowardZero,
986ee5a700af3fe9ae1a639c271f093f40677dddc04Dale Johannesen                                          &ignored);
987987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    Result = llvm::APInt(DestWidth, 4, Space);
988987b15db39745cd7fb2e634ba1a4b85469ac9131Chris Lattner    break;
9895f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
9905f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  case ConditionalOperatorClass: {
9915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
9925f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
993590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattner    if (!Exp->getCond()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
9945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
9955f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
9965f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const Expr *TrueExp  = Exp->getLHS();
9975f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    const Expr *FalseExp = Exp->getRHS();
9985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    if (Result == 0) std::swap(TrueExp, FalseExp);
9995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Evaluate the false one first, discard the result.
10013907323dd6665c0c4e383435cb145233f4533406Anders Carlsson    if (FalseExp && !FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false))
10025f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
10035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    // Evalute the true one, capture the result.
10043907323dd6665c0c4e383435cb145233f4533406Anders Carlsson    if (TrueExp &&
10053907323dd6665c0c4e383435cb145233f4533406Anders Carlsson        !TrueExp->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
10065f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      return false;
10075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    break;
10085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
100904421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner  case CXXDefaultArgExprClass:
101004421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    return cast<CXXDefaultArgExpr>(this)
101104421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner             ->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated);
10125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  }
10135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // Cases that are valid constant exprs fall through to here.
10155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  Result.setIsUnsigned(getType()->isUnsignedIntegerType());
10165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  return true;
10175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
10185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer
10195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// isNullPointerConstant - C99 6.3.2.3p3 -  Return true if this is either an
10205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// integer constant expression with the value zero, or if this is one that is
10215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// cast to void*.
1022590b6646ef747d2f7b42e5f40487ff07642d7b6fChris Lattnerbool Expr::isNullPointerConstant(ASTContext &Ctx) const {
1023aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  // Strip off a cast to void*, if it exists.
10240835a3cdeefe714b4959d31127ea155e56393125Argyrios Kyrtzidis  if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) {
1025aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // Check that it is a cast to void*.
10264b3f9b367c16e494c181d6f03d53497ae1275fbeEli Friedman    if (const PointerType *PT = CE->getType()->getAsPointerType()) {
10275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer      QualType Pointee = PT->getPointeeType();
1028f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner      if (Pointee.getCVRQualifiers() == 0 &&
1029f46699ce225811d8d9dbab9d00189a0e54469457Chris Lattner          Pointee->isVoidType() &&                                 // to void*
1030aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff          CE->getSubExpr()->getType()->isIntegerType())            // from int.
1031aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff        return CE->getSubExpr()->isNullPointerConstant(Ctx);
10325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer    }
1033aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
1034aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // Ignore the ImplicitCastExpr type entirely.
1035aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    return ICE->getSubExpr()->isNullPointerConstant(Ctx);
1036aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
1037aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // Accept ((void*)0) as a null pointer constant, as many other
1038aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    // implementations do.
1039aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    return PE->getSubExpr()->isNullPointerConstant(Ctx);
10408123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner  } else if (const CXXDefaultArgExpr *DefaultArg
10418123a95c33b792d35c2e4992ba6e27882748fb0dChris Lattner               = dyn_cast<CXXDefaultArgExpr>(this)) {
104204421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    // See through default argument expressions
104304421087832a031c90bd58f128c7c0e741db8dd2Chris Lattner    return DefaultArg->getExpr()->isNullPointerConstant(Ctx);
1044aaffbf7c790a324ed114184db771aae2d2e9151cSteve Naroff  }
1045aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff
1046aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  // This expression must be an integer type.
1047aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  if (!getType()->isIntegerType())
1048aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff    return false;
1049aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff
10505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // If we have an integer constant expression, we need to *evaluate* it and
10515f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  // test for the value 0.
10525f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer  llvm::APSInt Val(32);
1053aa58f00ebba5f14955001736b7aea20bb5bd91e6Steve Naroff  return isIntegerConstantExpr(Val, Ctx, 0, true) && Val == 0;
10545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}
105531a458462c6cf417a84e0c47852b18fb22d79acbSteve Naroff
1056213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanunsigned ExtVectorElementExpr::getNumElements() const {
10578a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  if (const VectorType *VT = getType()->getAsVectorType())
10588a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    return VT->getNumElements();
10598a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  return 1;
10604d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner}
10614d0ac88428b3ed7c6f3a2f4e758ea5424ecd70aeChris Lattner
10628a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// containsDuplicateElements - Return true if any element access is repeated.
1063213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begemanbool ExtVectorElementExpr::containsDuplicateElements() const {
1064fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  const char *compStr = Accessor.getName();
1065fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  unsigned length = strlen(compStr);
1066fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff
1067fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  for (unsigned i = 0; i < length-1; i++) {
1068fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    const char *s = compStr+i;
1069fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff    for (const char c = *s++; *s; s++)
1070fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff      if (c == *s)
1071fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff        return true;
1072fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  }
1073fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff  return false;
1074fec0b49c3fa621fbf63e420f3d54a5bb3a0265d2Steve Naroff}
1075b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
10768a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
10773b8d116703db8018f855cbb4733ace426422623bNate Begemanvoid ExtVectorElementExpr::getEncodedElementAccess(
10783b8d116703db8018f855cbb4733ace426422623bNate Begeman                                  llvm::SmallVectorImpl<unsigned> &Elts) const {
1079b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  const char *compStr = Accessor.getName();
10808a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman
10818a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  bool isHi =   !strcmp(compStr, "hi");
10828a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  bool isLo =   !strcmp(compStr, "lo");
10838a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  bool isEven = !strcmp(compStr, "e");
10848a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  bool isOdd  = !strcmp(compStr, "o");
10858a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman
10868a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman  for (unsigned i = 0, e = getNumElements(); i != e; ++i) {
10878a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    uint64_t Index;
10888a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman
10898a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    if (isHi)
10908a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = e + i;
10918a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isLo)
10928a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = i;
10938a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isEven)
10948a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = 2 * i;
10958a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else if (isOdd)
10968a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = 2 * i + 1;
10978a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman    else
10988a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman      Index = ExtVectorType::getAccessorIdx(compStr[i]);
1099b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner
11003b8d116703db8018f855cbb4733ace426422623bNate Begeman    Elts.push_back(Index);
1101b8f849da3cedee2f61ad98389115ddd04e439d60Chris Lattner  }
11028a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman}
11038a99764f9b778a54e7440b1ee06a1e48f25d76d8Nate Begeman
110468d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// constructor for instance messages.
1105bcfb06ac6da1aa3c74ac1ef7a49c2807522366e7Steve NaroffObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo,
1106a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                QualType retType, ObjCMethodDecl *mproto,
1107db611d556f71f98b66b69514d45958d76e5727abSteve Naroff                SourceLocation LBrac, SourceLocation RBrac,
110849f109c786f99eb7468dac3976db083a65493444Steve Naroff                Expr **ArgExprs, unsigned nargs)
1109db611d556f71f98b66b69514d45958d76e5727abSteve Naroff  : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
1110ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted Kremenek    MethodProto(mproto) {
111149f109c786f99eb7468dac3976db083a65493444Steve Naroff  NumArgs = nargs;
11125549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  SubExprs = new Stmt*[NumArgs+1];
111368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  SubExprs[RECEIVER] = receiver;
111449f109c786f99eb7468dac3976db083a65493444Steve Naroff  if (NumArgs) {
111549f109c786f99eb7468dac3976db083a65493444Steve Naroff    for (unsigned i = 0; i != NumArgs; ++i)
111668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
111768d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  }
1118563477da25f824e37c535131695dc4dc9b68c465Steve Naroff  LBracloc = LBrac;
1119563477da25f824e37c535131695dc4dc9b68c465Steve Naroff  RBracloc = RBrac;
1120563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
1121563477da25f824e37c535131695dc4dc9b68c465Steve Naroff
112268d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// constructor for class messages.
112368d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff// FIXME: clsName should be typed to ObjCInterfaceType
1124bcfb06ac6da1aa3c74ac1ef7a49c2807522366e7Steve NaroffObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
1125a526c5c67e5a0473c340903ee542ce570119665fTed Kremenek                QualType retType, ObjCMethodDecl *mproto,
1126db611d556f71f98b66b69514d45958d76e5727abSteve Naroff                SourceLocation LBrac, SourceLocation RBrac,
112749f109c786f99eb7468dac3976db083a65493444Steve Naroff                Expr **ArgExprs, unsigned nargs)
1128db611d556f71f98b66b69514d45958d76e5727abSteve Naroff  : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
1129ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted Kremenek    MethodProto(mproto) {
113049f109c786f99eb7468dac3976db083a65493444Steve Naroff  NumArgs = nargs;
11315549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  SubExprs = new Stmt*[NumArgs+1];
11324df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  SubExprs[RECEIVER] = (Expr*) ((uintptr_t) clsName | IsClsMethDeclUnknown);
113349f109c786f99eb7468dac3976db083a65493444Steve Naroff  if (NumArgs) {
113449f109c786f99eb7468dac3976db083a65493444Steve Naroff    for (unsigned i = 0; i != NumArgs; ++i)
113568d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff      SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
113668d331a78e655d97294e94fcfa63f92cc1f40578Steve Naroff  }
1137563477da25f824e37c535131695dc4dc9b68c465Steve Naroff  LBracloc = LBrac;
1138563477da25f824e37c535131695dc4dc9b68c465Steve Naroff  RBracloc = RBrac;
1139563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
1140563477da25f824e37c535131695dc4dc9b68c465Steve Naroff
11414df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek// constructor for class messages.
11424df728e368fa1f65ffc57572fed613dcca5b4fe8Ted KremenekObjCMessageExpr::ObjCMessageExpr(ObjCInterfaceDecl *cls, Selector selInfo,
11434df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek                                 QualType retType, ObjCMethodDecl *mproto,
11444df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek                                 SourceLocation LBrac, SourceLocation RBrac,
11454df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek                                 Expr **ArgExprs, unsigned nargs)
11464df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek: Expr(ObjCMessageExprClass, retType), SelName(selInfo),
11474df728e368fa1f65ffc57572fed613dcca5b4fe8Ted KremenekMethodProto(mproto) {
11484df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  NumArgs = nargs;
11494df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  SubExprs = new Stmt*[NumArgs+1];
11504df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  SubExprs[RECEIVER] = (Expr*) ((uintptr_t) cls | IsClsMethDeclKnown);
11514df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  if (NumArgs) {
11524df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek    for (unsigned i = 0; i != NumArgs; ++i)
11534df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek      SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
11544df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  }
11554df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  LBracloc = LBrac;
11564df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  RBracloc = RBrac;
11574df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek}
11584df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek
11594df728e368fa1f65ffc57572fed613dcca5b4fe8Ted KremenekObjCMessageExpr::ClassInfo ObjCMessageExpr::getClassInfo() const {
11604df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  uintptr_t x = (uintptr_t) SubExprs[RECEIVER];
11614df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  switch (x & Flags) {
11624df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek    default:
11634df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek      assert(false && "Invalid ObjCMessageExpr.");
11644df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek    case IsInstMeth:
11654df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek      return ClassInfo(0, 0);
11664df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek    case IsClsMethDeclUnknown:
11674df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek      return ClassInfo(0, (IdentifierInfo*) (x & ~Flags));
11684df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek    case IsClsMethDeclKnown: {
11694df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek      ObjCInterfaceDecl* D = (ObjCInterfaceDecl*) (x & ~Flags);
11704df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek      return ClassInfo(D, D->getIdentifier());
11714df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek    }
11724df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek  }
11734df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek}
11744df728e368fa1f65ffc57572fed613dcca5b4fe8Ted Kremenek
117527437caadea35f84d550cd29f024fcf3ea240eecChris Lattnerbool ChooseExpr::isConditionTrue(ASTContext &C) const {
117632442bbc98bafa512fa42d46fedf60ed7d79f574Daniel Dunbar  return getCond()->getIntegerConstantExprValue(C) != 0;
117727437caadea35f84d550cd29f024fcf3ea240eecChris Lattner}
117827437caadea35f84d550cd29f024fcf3ea240eecChris Lattner
11795a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlssonstatic int64_t evaluateOffsetOf(ASTContext& C, const Expr *E)
11805a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson{
11815a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
11825a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    QualType Ty = ME->getBase()->getType();
11835a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
11845a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    RecordDecl *RD = Ty->getAsRecordType()->getDecl();
118598be4943e8dc4f3905629a7102668960873cf863Chris Lattner    const ASTRecordLayout &RL = C.getASTRecordLayout(RD);
11865a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    FieldDecl *FD = ME->getMemberDecl();
11875a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
11885a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    // FIXME: This is linear time.
11895a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    unsigned i = 0, e = 0;
11905a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    for (i = 0, e = RD->getNumMembers(); i != e; i++) {
11915a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson      if (RD->getMember(i) == FD)
11925a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson        break;
11935a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    }
11945a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
11955a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    return RL.getFieldOffset(i) + evaluateOffsetOf(C, ME->getBase());
11965a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  } else if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
11975a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    const Expr *Base = ASE->getBase();
11985a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
119998be4943e8dc4f3905629a7102668960873cf863Chris Lattner    int64_t size = C.getTypeSize(ASE->getType());
120032442bbc98bafa512fa42d46fedf60ed7d79f574Daniel Dunbar    size *= ASE->getIdx()->getIntegerConstantExprValue(C).getSExtValue();
12015a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
12025a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    return size + evaluateOffsetOf(C, Base);
12035a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  } else if (isa<CompoundLiteralExpr>(E))
12045a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson    return 0;
12055a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
12065a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  assert(0 && "Unknown offsetof subexpression!");
12075a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  return 0;
12085a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson}
12095a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
12105a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlssonint64_t UnaryOperator::evaluateOffsetOf(ASTContext& C) const
12115a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson{
12125a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson  assert(Opc == OffsetOf && "Unary operator not offsetof!");
12135a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
121498be4943e8dc4f3905629a7102668960873cf863Chris Lattner  unsigned CharSize = C.Target.getCharWidth();
12155549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return ::evaluateOffsetOf(C, cast<Expr>(Val)) / CharSize;
12165a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson}
12175a1deb8d9c0722beae28d693fa137bbb942bd11fAnders Carlsson
12189048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbarvoid SizeOfAlignOfTypeExpr::Destroy(ASTContext& C) {
12199048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar  // Override default behavior of traversing children. We do not want
12209048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar  // to delete the type.
12219048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar}
12229048891ff983d0681c116c6e8f1073aa31bdd6e8Daniel Dunbar
122377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===//
122477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//  Child Iterators for iterating over subexpressions/substatements
122577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek//===----------------------------------------------------------------------===//
122677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
122777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// DeclRefExpr
12289ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); }
12299ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); }
123077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
12317779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff// ObjCIvarRefExpr
12325549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_begin() { return &Base; }
12335549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCIvarRefExpr::child_end() { return &Base+1; }
12347779db42c94405ecbd6ee45efb293483fa6cbeffSteve Naroff
1235e3e9add4fd788927df6f545570e7838db59c01d7Steve Naroff// ObjCPropertyRefExpr
12365549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_begin() { return &Base; }
12375549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ObjCPropertyRefExpr::child_end() { return &Base+1; }
1238ae7840776d6cd31b4d7a4a345b61bcbb3744df6cSteve Naroff
1239d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris Lattner// PredefinedExpr
1240d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); }
1241d9f6910f4ef37c0e8eeee2a01287d9572c3176efChris LattnerStmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); }
124277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
124377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// IntegerLiteral
12449ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); }
12459ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); }
124677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
124777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CharacterLiteral
12489ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator CharacterLiteral::child_begin() { return child_iterator(); }
12499ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); }
125077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
125177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// FloatingLiteral
12529ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); }
12539ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); }
125477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
12555d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner// ImaginaryLiteral
12565549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_begin() { return &Val; }
12575549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ImaginaryLiteral::child_end() { return &Val+1; }
12585d66145eed1c319df5a69977cb8ff74f597ea544Chris Lattner
125977ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// StringLiteral
12609ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_begin() { return child_iterator(); }
12619ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator StringLiteral::child_end() { return child_iterator(); }
126277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
126377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ParenExpr
12645549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_begin() { return &Val; }
12655549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ParenExpr::child_end() { return &Val+1; }
126677ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
126777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// UnaryOperator
12685549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_begin() { return &Val; }
12695549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator UnaryOperator::child_end() { return &Val+1; }
127077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
127177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// SizeOfAlignOfTypeExpr
12729ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() {
1273699e9fbeae34cdd651b8e6308649c8939f090cbdTed Kremenek  // If the type is a VLA type (and not a typedef), the size expression of the
1274699e9fbeae34cdd651b8e6308649c8939f090cbdTed Kremenek  // VLA needs to be treated as an executable expression.
1275699e9fbeae34cdd651b8e6308649c8939f090cbdTed Kremenek  if (VariableArrayType* T = dyn_cast<VariableArrayType>(Ty.getTypePtr()))
1276699e9fbeae34cdd651b8e6308649c8939f090cbdTed Kremenek    return child_iterator(T);
1277699e9fbeae34cdd651b8e6308649c8939f090cbdTed Kremenek  else
12788a213de1a86e5f347c6b591f52712c2fd6177cceTed Kremenek    return child_iterator();
12799ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
12809ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator SizeOfAlignOfTypeExpr::child_end() {
12818a213de1a86e5f347c6b591f52712c2fd6177cceTed Kremenek  return child_iterator();
12829ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
128377ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
128477ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// ArraySubscriptExpr
12851237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_begin() {
12865549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
128777ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
12881237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ArraySubscriptExpr::child_end() {
12895549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+END_EXPR;
129077ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
129177ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek
129277ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek// CallExpr
12931237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_begin() {
12945549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
129577ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
12961237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator CallExpr::child_end() {
12975549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+NumArgs+ARGS_START;
129877ed8e4edf6ed78c53fb20ec3210aff2a59c9d87Ted Kremenek}
12991237c673c07f9d827129ba02720108816abde562Ted Kremenek
13001237c673c07f9d827129ba02720108816abde562Ted Kremenek// MemberExpr
13015549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_begin() { return &Base; }
13025549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator MemberExpr::child_end() { return &Base+1; }
13031237c673c07f9d827129ba02720108816abde562Ted Kremenek
1304213541a68a3e137d11d2cefb612c6cdb410d7e8eNate Begeman// ExtVectorElementExpr
13055549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_begin() { return &Base; }
13065549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ExtVectorElementExpr::child_end() { return &Base+1; }
13071237c673c07f9d827129ba02720108816abde562Ted Kremenek
13081237c673c07f9d827129ba02720108816abde562Ted Kremenek// CompoundLiteralExpr
13095549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_begin() { return &Init; }
13105549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CompoundLiteralExpr::child_end() { return &Init+1; }
13111237c673c07f9d827129ba02720108816abde562Ted Kremenek
13121237c673c07f9d827129ba02720108816abde562Ted Kremenek// CastExpr
13135549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_begin() { return &Op; }
13145549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator CastExpr::child_end() { return &Op+1; }
13151237c673c07f9d827129ba02720108816abde562Ted Kremenek
13161237c673c07f9d827129ba02720108816abde562Ted Kremenek// BinaryOperator
13171237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_begin() {
13185549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
13191237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13201237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator BinaryOperator::child_end() {
13215549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+END_EXPR;
13221237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13231237c673c07f9d827129ba02720108816abde562Ted Kremenek
13241237c673c07f9d827129ba02720108816abde562Ted Kremenek// ConditionalOperator
13251237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_begin() {
13265549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
13271237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13281237c673c07f9d827129ba02720108816abde562Ted KremenekStmt::child_iterator ConditionalOperator::child_end() {
13295549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+END_EXPR;
13301237c673c07f9d827129ba02720108816abde562Ted Kremenek}
13311237c673c07f9d827129ba02720108816abde562Ted Kremenek
13321237c673c07f9d827129ba02720108816abde562Ted Kremenek// AddrLabelExpr
13339ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); }
13349ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); }
13351237c673c07f9d827129ba02720108816abde562Ted Kremenek
13361237c673c07f9d827129ba02720108816abde562Ted Kremenek// StmtExpr
13375549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_begin() { return &SubStmt; }
13385549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator StmtExpr::child_end() { return &SubStmt+1; }
13391237c673c07f9d827129ba02720108816abde562Ted Kremenek
13401237c673c07f9d827129ba02720108816abde562Ted Kremenek// TypesCompatibleExpr
13419ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_begin() {
13429ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
13439ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
13449ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek
13459ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator TypesCompatibleExpr::child_end() {
13469ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
13479ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
13481237c673c07f9d827129ba02720108816abde562Ted Kremenek
13491237c673c07f9d827129ba02720108816abde562Ted Kremenek// ChooseExpr
13505549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_begin() { return &SubExprs[0]; }
13515549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator ChooseExpr::child_end() { return &SubExprs[0]+END_EXPR; }
13521237c673c07f9d827129ba02720108816abde562Ted Kremenek
1353e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman// OverloadExpr
13545549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator OverloadExpr::child_begin() { return &SubExprs[0]; }
13555549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator OverloadExpr::child_end() { return &SubExprs[0]+NumExprs; }
1356e2ce1d9440186cf3332368291cd884a6e3ae8946Nate Begeman
1357d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman// ShuffleVectorExpr
1358d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_begin() {
13595549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0];
1360d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}
1361d38617c8a50f9729c254ab76cd359af797c6739bEli FriedmanStmt::child_iterator ShuffleVectorExpr::child_end() {
13625549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+NumExprs;
1363d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman}
1364d38617c8a50f9729c254ab76cd359af797c6739bEli Friedman
13657c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson// VAArgExpr
13665549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_begin() { return &Val; }
13675549976193e34417d4474a5f4a514268ef6666c7Ted KremenekStmt::child_iterator VAArgExpr::child_end() { return &Val+1; }
13687c50aca2fe36f6daa9bf1c8c428f30e72f96470aAnders Carlsson
136966b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson// InitListExpr
137066b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonStmt::child_iterator InitListExpr::child_begin() {
13715549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return InitExprs.size() ? &InitExprs[0] : 0;
137266b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}
137366b5a8a39088598c01a9fa6f032dc908612dc8ecAnders CarlssonStmt::child_iterator InitListExpr::child_end() {
13745549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return InitExprs.size() ? &InitExprs[0] + InitExprs.size() : 0;
137566b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson}
137666b5a8a39088598c01a9fa6f032dc908612dc8ecAnders Carlsson
13771237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCStringLiteral
13789ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCStringLiteral::child_begin() {
13799ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
13809ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
13819ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCStringLiteral::child_end() {
13829ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
13839ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
13841237c673c07f9d827129ba02720108816abde562Ted Kremenek
13851237c673c07f9d827129ba02720108816abde562Ted Kremenek// ObjCEncodeExpr
13869ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); }
13879ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); }
13881237c673c07f9d827129ba02720108816abde562Ted Kremenek
1389b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian// ObjCSelectorExpr
13909ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCSelectorExpr::child_begin() {
13919ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
13929ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
13939ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCSelectorExpr::child_end() {
13949ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
13959ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
1396b62f6813406a03bf8a371c4e46c9fad51d102121Fariborz Jahanian
1397390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian// ObjCProtocolExpr
13989ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_begin() {
13999ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
14009ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
14019ac5928abeb3a47592201e1c30fe2930c20a507eTed KremenekStmt::child_iterator ObjCProtocolExpr::child_end() {
14029ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek  return child_iterator();
14039ac5928abeb3a47592201e1c30fe2930c20a507eTed Kremenek}
1404390d50a725497e99247dc104a7d2c2a255d3af14Fariborz Jahanian
1405563477da25f824e37c535131695dc4dc9b68c465Steve Naroff// ObjCMessageExpr
1406ea958e57a370b641c5a69347b75e9f8e3b5a41a2Ted KremenekStmt::child_iterator ObjCMessageExpr::child_begin() {
14075549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return getReceiver() ? &SubExprs[0] : &SubExprs[0] + ARGS_START;
1408563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
1409563477da25f824e37c535131695dc4dc9b68c465Steve NaroffStmt::child_iterator ObjCMessageExpr::child_end() {
14105549976193e34417d4474a5f4a514268ef6666c7Ted Kremenek  return &SubExprs[0]+ARGS_START+getNumArgs();
1411563477da25f824e37c535131695dc4dc9b68c465Steve Naroff}
1412563477da25f824e37c535131695dc4dc9b68c465Steve Naroff
14134eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff// Blocks
141456ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_begin() { return child_iterator(); }
141556ee6896f2efebffb4a2cce5a7610cdf1eddbbbeSteve NaroffStmt::child_iterator BlockExpr::child_end() { return child_iterator(); }
14164eb206bebcdab28ababe8df55c6185cec2cdc071Steve Naroff
14179da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_begin() { return child_iterator();}
14189da13f9ddb2567e36f4bbee7b3c32f54aeb76d5bTed KremenekStmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator(); }
1419