Index: include/clang/Frontend/StmtXML.def
===================================================================
--- include/clang/Frontend/StmtXML.def	(revisione 100962)
+++ include/clang/Frontend/StmtXML.def	(copia locale)
@@ -254,7 +254,6 @@
     ENUM_XML(UnaryOperator::Real,    "__real")
     ENUM_XML(UnaryOperator::Imag,    "__imag")
     ENUM_XML(UnaryOperator::Extension, "__extension__")
-    ENUM_XML(UnaryOperator::OffsetOf,  "__builtin_offsetof")
   END_ENUM_XML
   SUB_NODE_XML(Expr)                                    // expr
 END_NODE_XML
@@ -311,6 +310,13 @@
   SUB_NODE_XML(Expr)                                    // expr3
 END_NODE_XML
 
+NODE_XML(OffsetOfExpr, "OffsetOfExpr")                  // offsetof(basetype, components)
+  ATTRIBUTE_FILE_LOCATION_XML
+  TYPE_ATTRIBUTE_XML(getTypeSourceInfo()->getType())
+  ATTRIBUTE_XML(getNumComponents(), "num_components")
+  SUB_NODE_SEQUENCE_XML(OffsetOfExpr::OffsetOfNode)
+END_NODE_XML
+
 NODE_XML(SizeOfAlignOfExpr, "SizeOfAlignOfExpr")        // sizeof(expr) or alignof(expr)
   ATTRIBUTE_FILE_LOCATION_XML
   TYPE_ATTRIBUTE_XML(getType())
Index: include/clang/Checker/PathSensitive/GRExprEngine.h
===================================================================
--- include/clang/Checker/PathSensitive/GRExprEngine.h	(revisione 100962)
+++ include/clang/Checker/PathSensitive/GRExprEngine.h	(copia locale)
@@ -333,6 +333,10 @@
 
   /// VisitReturnStmt - Transfer function logic for return statements.
   void VisitReturnStmt(ReturnStmt* R, ExplodedNode* Pred, ExplodedNodeSet& Dst);
+  
+  /// VisitOffsetOfExpr - Transfer function for offsetof.
+  void VisitOffsetOfExpr(OffsetOfExpr* Ex, ExplodedNode* Pred,
+                         ExplodedNodeSet& Dst);
 
   /// VisitSizeOfAlignOfExpr - Transfer function for sizeof.
   void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr* Ex, ExplodedNode* Pred,
Index: include/clang/AST/StmtVisitor.h
===================================================================
--- include/clang/AST/StmtVisitor.h	(revisione 100962)
+++ include/clang/AST/StmtVisitor.h	(copia locale)
@@ -98,7 +98,6 @@
       case UnaryOperator::Real:         DISPATCH(UnaryReal,      UnaryOperator);
       case UnaryOperator::Imag:         DISPATCH(UnaryImag,      UnaryOperator);
       case UnaryOperator::Extension:    DISPATCH(UnaryExtension, UnaryOperator);
-      case UnaryOperator::OffsetOf:     DISPATCH(UnaryOffsetOf,  UnaryOperator);
       }
     }
 
@@ -163,7 +162,7 @@
   UNARYOP_FALLBACK(Plus)      UNARYOP_FALLBACK(Minus)
   UNARYOP_FALLBACK(Not)       UNARYOP_FALLBACK(LNot)
   UNARYOP_FALLBACK(Real)      UNARYOP_FALLBACK(Imag)
-  UNARYOP_FALLBACK(Extension) UNARYOP_FALLBACK(OffsetOf)
+  UNARYOP_FALLBACK(Extension)
 #undef UNARYOP_FALLBACK
 
   // Base case, ignore it. :)
Index: include/clang/AST/Expr.h
===================================================================
--- include/clang/AST/Expr.h	(revisione 100962)
+++ include/clang/AST/Expr.h	(copia locale)
@@ -211,7 +211,7 @@
   }
   /// isConstantInitializer - Returns true if this expression is a constant
   /// initializer, which can be emitted at compile-time.
-  bool isConstantInitializer(ASTContext &Ctx) const;
+  bool isConstantInitializer(ASTContext &Ctx) const; 
 
   /// EvalResult is a struct with detailed info about an evaluated expression.
   struct EvalResult {
@@ -900,10 +900,6 @@
 ///   applied to a non-complex value, the former returns its operand and the
 ///   later returns zero in the type of the operand.
 ///
-/// __builtin_offsetof(type, a.b[10]) is represented as a unary operator whose
-///   subexpression is a compound literal with the various MemberExpr and
-///   ArraySubscriptExpr's applied to it.
-///
 class UnaryOperator : public Expr {
 public:
   // Note that additions to this should also update the StmtVisitor class.
@@ -914,8 +910,7 @@
     Plus, Minus,      // [C99 6.5.3.3] Unary arithmetic operators.
     Not, LNot,        // [C99 6.5.3.3] Unary arithmetic operators.
     Real, Imag,       // "__real expr"/"__imag expr" Extension.
-    Extension,        // __extension__ marker.
-    OffsetOf          // __builtin_offsetof
+    Extension         // __extension__ marker.
   };
 private:
   Stmt *Val;
@@ -925,7 +920,7 @@
 
   UnaryOperator(Expr *input, Opcode opc, QualType type, SourceLocation l)
     : Expr(UnaryOperatorClass, type,
-           input->isTypeDependent() && opc != OffsetOf,
+           input->isTypeDependent(),
            input->isValueDependent()),
       Val(input), Opc(opc), Loc(l) {}
 
@@ -957,7 +952,6 @@
   bool isPostfix() const { return isPostfix(Opc); }
   bool isIncrementOp() const {return Opc==PreInc || Opc==PostInc; }
   bool isIncrementDecrementOp() const { return Opc>=PostInc && Opc<=PreDec; }
-  bool isOffsetOfOp() const { return Opc == OffsetOf; }
   static bool isArithmeticOp(Opcode Op) { return Op >= Plus && Op <= LNot; }
   bool isArithmeticOp() const { return isArithmeticOp(Opc); }
 
@@ -991,6 +985,78 @@
   virtual child_iterator child_end();
 };
 
+/// OffsetOfExpr
+class OffsetOfExpr : public Expr {
+
+public:
+  // __builtin_offsetof(type, identifier(.identifier|[expr])*)
+  // FIXME: Type-dependent case ignored.
+  struct OffsetOfNode {
+    SourceLocation LocStart, LocEnd;
+    bool isBrackets;  // true if [expr], false if .ident
+    union {
+      FieldDecl *MemberDecl;
+      Expr *IndexExpr;
+    } U;
+  };
+
+private:
+  typedef llvm::SmallVector<OffsetOfNode, 4> Components;
+  // Base type;
+  TypeSourceInfo *TSInfo;
+  SourceLocation Loc;
+  // Keep track of the various subcomponents (e.g. instance of OffsetOfNode).
+  Components Comps;
+
+public:
+
+  OffsetOfExpr(QualType type, SourceLocation l, 
+               TypeSourceInfo *tsi, const Components &comps)
+    : Expr(OffsetOfExprClass, type, false, false),
+      TSInfo(tsi), Loc(l), Comps(comps) {}
+
+  /// \brief Build an empty offsetof.
+  explicit OffsetOfExpr(EmptyShell Empty)
+    : Expr(OffsetOfExprClass, Empty), TSInfo(0), Comps(0) {}
+
+  /// getOperatorLoc - Return the location of the operator.
+  SourceLocation getOperatorLoc() const { return Loc; }
+  void setOperatorLoc(SourceLocation L) { Loc = L; }
+
+  TypeSourceInfo *getTypeSourceInfo() const {
+    return TSInfo;
+  }
+  void setTypeSourceInfo(TypeSourceInfo *tsi) {
+    TSInfo = tsi;
+  }
+  
+  const OffsetOfNode* getComponents() const {
+    return &Comps[0];
+  }
+  void setComponents(Components comps) {
+    Comps = comps;
+  }
+  
+  size_t getNumComponents() const {
+    return Comps.size();
+  }
+
+  virtual SourceRange getSourceRange() const {
+    return SourceRange(Loc, Comps.back().LocEnd);
+  }
+  virtual SourceLocation getExprLoc() const { return Loc; }
+
+  static bool classof(const Stmt *T) {
+    return T->getStmtClass() == OffsetOfExprClass;
+  }
+
+  static bool classof(const OffsetOfExpr *) { return true; }
+
+  // Iterators
+  virtual child_iterator child_begin();
+  virtual child_iterator child_end();
+};
+
 /// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of
 /// types and expressions.
 class SizeOfAlignOfExpr : public Expr {
Index: include/clang/AST/StmtNodes.def
===================================================================
--- include/clang/AST/StmtNodes.def	(revisione 100962)
+++ include/clang/AST/StmtNodes.def	(copia locale)
@@ -78,6 +78,7 @@
 EXPR(CharacterLiteral      , Expr)
 EXPR(ParenExpr             , Expr)
 EXPR(UnaryOperator         , Expr)
+EXPR(OffsetOfExpr          , Expr)
 EXPR(SizeOfAlignOfExpr     , Expr)
 EXPR(ArraySubscriptExpr    , Expr)
 EXPR(CallExpr              , Expr)
Index: tools/CIndex/CXCursor.cpp
===================================================================
--- tools/CIndex/CXCursor.cpp	(revisione 100962)
+++ tools/CIndex/CXCursor.cpp	(copia locale)
@@ -139,7 +139,8 @@
   case Stmt::StringLiteralClass:         
   case Stmt::CharacterLiteralClass:      
   case Stmt::ParenExprClass:             
-  case Stmt::UnaryOperatorClass:         
+  case Stmt::UnaryOperatorClass:
+  case Stmt::OffsetOfExprClass:         
   case Stmt::SizeOfAlignOfExprClass:     
   case Stmt::ArraySubscriptExprClass:    
   case Stmt::BinaryOperatorClass:        
Index: lib/Frontend/StmtXML.cpp
===================================================================
--- lib/Frontend/StmtXML.cpp	(revisione 100962)
+++ lib/Frontend/StmtXML.cpp	(copia locale)
@@ -125,6 +125,7 @@
     void VisitFloatingLiteral(FloatingLiteral *Node);
     void VisitStringLiteral(StringLiteral *Str);
     void VisitUnaryOperator(UnaryOperator *Node);
+    void VisitOffsetOfExpr(OffsetOfExpr *Node);
     void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node);
     void VisitMemberExpr(MemberExpr *Node);
     void VisitExtVectorElementExpr(ExtVectorElementExpr *Node);
@@ -260,7 +261,6 @@
   case UnaryOperator::Real:    return "__real";
   case UnaryOperator::Imag:    return "__imag";
   case UnaryOperator::Extension: return "__extension__";
-  case UnaryOperator::OffsetOf: return "__builtin_offsetof";
   }
 }
 
@@ -308,6 +308,10 @@
   Doc.addAttribute("op_code", getOpcodeStr(Node->getOpcode()));
 }
 
+void StmtXML::OffsetOfExpr(OffsetOfExpr *Node) {
+  DumpExpr(Node);
+}
+
 void StmtXML::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *Node) {
   DumpExpr(Node);
   Doc.addAttribute("is_sizeof", Node->isSizeOf() ? "sizeof" : "alignof");
Index: lib/Sema/TreeTransform.h
===================================================================
--- lib/Sema/TreeTransform.h	(revisione 100962)
+++ lib/Sema/TreeTransform.h	(copia locale)
@@ -3828,6 +3828,12 @@
 
 template<typename Derived>
 Sema::OwningExprResult
+TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
+  return SemaRef.Owned(new (SemaRef.Context) OffsetOfExpr(*E));
+}
+
+template<typename Derived>
+Sema::OwningExprResult
 TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
   if (E->isArgumentType()) {
     TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp	(revisione 100962)
+++ lib/Sema/SemaChecking.cpp	(copia locale)
@@ -1949,13 +1949,16 @@
     // Operations with opaque sources are black-listed.
     case UnaryOperator::Deref:
     case UnaryOperator::AddrOf: // should be impossible
-    case UnaryOperator::OffsetOf:
       return IntRange::forType(C, E->getType());
 
     default:
       return GetExprRange(C, UO->getSubExpr(), MaxWidth);
     }
   }
+  
+  if (dyn_cast<OffsetOfExpr>(E)) {
+    IntRange::forType(C, E->getType());
+  }
 
   FieldDecl *BitField = E->getBitField();
   if (BitField) {
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp	(revisione 100962)
+++ lib/Sema/SemaExpr.cpp	(copia locale)
@@ -18,6 +18,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/Basic/PartialDiagnostic.h"
@@ -6401,9 +6402,6 @@
   Expr *Input = (Expr *)InputArg.get();
   QualType resultType;
   switch (Opc) {
-  case UnaryOperator::OffsetOf:
-    assert(false && "Invalid unary operator");
-    break;
 
   case UnaryOperator::PreInc:
   case UnaryOperator::PreDec:
@@ -6571,8 +6569,8 @@
                                                   SourceLocation RPLoc) {
   // FIXME: This function leaks all expressions in the offset components on
   // error.
-  // FIXME: Preserve type source info.
-  QualType ArgTy = GetTypeFromParser(argty);
+  TypeSourceInfo *ArgTInfo;
+  QualType ArgTy = GetTypeFromParser(argty, &ArgTInfo);
   assert(!ArgTy.isNull() && "Missing type argument!");
 
   bool Dependent = ArgTy->isDependentType();
@@ -6592,6 +6590,7 @@
   Expr* Res = new (Context) ImplicitValueInitExpr(ArgTyPtr);
   Res = new (Context) UnaryOperator(Res, UnaryOperator::Deref,
                                     ArgTy, SourceLocation());
+  llvm::SmallVector<OffsetOfExpr::OffsetOfNode, 4> Comps(NumComponents);
 
   // offsetof with non-identifier designators (e.g. "offsetof(x, a.b[c])") are a
   // GCC extension, diagnose them.
@@ -6608,83 +6607,63 @@
                             diag::err_offsetof_incomplete_type))
       return ExprError();
 
-    // FIXME: Dependent case loses a lot of information here. And probably
-    // leaks like a sieve.
+    QualType CurrentType = ArgTy;
     for (unsigned i = 0; i != NumComponents; ++i) {
       const OffsetOfComponent &OC = CompPtr[i];
       if (OC.isBrackets) {
-        // Offset of an array sub-field.  TODO: Should we allow vector elements?
-        const ArrayType *AT = Context.getAsArrayType(Res->getType());
-        if (!AT) {
-          Res->Destroy(Context);
+        const ArrayType *AT = Context.getAsArrayType(CurrentType);
+        if(!AT)
           return ExprError(Diag(OC.LocEnd, diag::err_offsetof_array_type)
-            << Res->getType());
-        }
+            << CurrentType);
 
         // FIXME: C++: Verify that operator[] isn't overloaded.
 
-        // Promote the array so it looks more like a normal array subscript
-        // expression.
-        DefaultFunctionArrayLvalueConversion(Res);
-
         // C99 6.5.2.1p1
         Expr *Idx = static_cast<Expr*>(OC.U.E);
-        // FIXME: Leaks Res
         if (!Idx->isTypeDependent() && !Idx->getType()->isIntegerType())
           return ExprError(Diag(Idx->getLocStart(),
                                 diag::err_typecheck_subscript_not_integer)
-            << Idx->getSourceRange());
-
-        Res = new (Context) ArraySubscriptExpr(Res, Idx, AT->getElementType(),
-                                               OC.LocEnd);
-        continue;
+                             << Idx->getSourceRange());
+        CurrentType = AT->getElementType();
+        Comps[i].U.IndexExpr = Idx;
       }
-
-      const RecordType *RC = Res->getType()->getAs<RecordType>();
-      if (!RC) {
-        Res->Destroy(Context);
-        return ExprError(Diag(OC.LocEnd, diag::err_offsetof_record_type)
-          << Res->getType());
-      }
-
-      // Get the decl corresponding to this.
-      RecordDecl *RD = RC->getDecl();
-      if (CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(RD)) {
-        if (!CRD->isPOD() && !DidWarnAboutNonPOD &&
+      else {
+        const RecordType *RC = CurrentType->getAs<RecordType>();
+        if (!RC) 
+          return ExprError(Diag(OC.LocEnd, diag::err_offsetof_array_type)
+            << CurrentType);
+        RecordDecl *RD = RC->getDecl();
+        if (CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(RD)) {
+          if (!CRD->isPOD() && !DidWarnAboutNonPOD &&
             DiagRuntimeBehavior(BuiltinLoc,
                                 PDiag(diag::warn_offsetof_non_pod_type)
                                   << SourceRange(CompPtr[0].LocStart, OC.LocEnd)
-                                  << Res->getType()))
+                                  << CurrentType))
           DidWarnAboutNonPOD = true;
-      }
+        }
+        LookupResult R(*this, OC.U.IdentInfo, OC.LocStart, LookupMemberName);
+        LookupQualifiedName(R, RD);
+        FieldDecl *MemberDecl = R.getAsSingle<FieldDecl>();
+        if (!MemberDecl)
+          return ExprError(Diag(BuiltinLoc, diag::err_no_member)
+            << OC.U.IdentInfo << RD << SourceRange(OC.LocStart, OC.LocEnd));
 
-      LookupResult R(*this, OC.U.IdentInfo, OC.LocStart, LookupMemberName);
-      LookupQualifiedName(R, RD);
-
-      FieldDecl *MemberDecl = R.getAsSingle<FieldDecl>();
-      // FIXME: Leaks Res
-      if (!MemberDecl)
-        return ExprError(Diag(BuiltinLoc, diag::err_no_member)
-         << OC.U.IdentInfo << RD << SourceRange(OC.LocStart, OC.LocEnd));
-
-      // FIXME: C++: Verify that MemberDecl isn't a static field.
-      // FIXME: Verify that MemberDecl isn't a bitfield.
-      if (cast<RecordDecl>(MemberDecl->getDeclContext())->isAnonymousStructOrUnion()) {
-        Res = BuildAnonymousStructUnionMemberReference(
-            OC.LocEnd, MemberDecl, Res, OC.LocEnd).takeAs<Expr>();
-      } else {
-        PerformObjectMemberConversion(Res, /*Qualifier=*/0,
-                                      *R.begin(), MemberDecl);
-        // MemberDecl->getType() doesn't get the right qualifiers, but it
-        // doesn't matter here.
-        Res = new (Context) MemberExpr(Res, false, MemberDecl, OC.LocEnd,
-                MemberDecl->getType().getNonReferenceType());
+        // FIXME: C++: Verify that MemberDecl isn't a static field.
+        // FIXME: Verify that MemberDecl isn't a bitfield.
+        if (cast<RecordDecl>(MemberDecl->getDeclContext())->isAnonymousStructOrUnion())
+          CurrentType = MemberDecl->getType();
+        else
+          CurrentType = MemberDecl->getType().getNonReferenceType();
+        Comps[i].U.MemberDecl = MemberDecl;
       }
+      Comps[i].LocStart = OC.LocStart;
+      Comps[i].LocEnd = OC.LocEnd;
     }
+      
   }
 
-  return Owned(new (Context) UnaryOperator(Res, UnaryOperator::OffsetOf,
-                                           Context.getSizeType(), BuiltinLoc));
+  return Owned(new (Context) OffsetOfExpr(Context.getSizeType(), BuiltinLoc, 
+                                          ArgTInfo, Comps));
 }
 
 
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp	(revisione 100962)
+++ lib/AST/ExprConstant.cpp	(copia locale)
@@ -16,7 +16,9 @@
 #include "clang/AST/CharUnits.h"
 #include "clang/AST/RecordLayout.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/AST/TypeLoc.h"
 #include "clang/AST/ASTDiagnostic.h"
+#include "clang/AST/Expr.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/SmallString.h"
@@ -221,7 +223,7 @@
   APValue VisitStmt(Stmt *S) {
     return APValue();
   }
-
+  
   APValue VisitParenExpr(ParenExpr *E) { return Visit(E->getSubExpr()); }
   APValue VisitDeclRefExpr(DeclRefExpr *E);
   APValue VisitPredefinedExpr(PredefinedExpr *E) { return APValue(E); }
@@ -821,6 +823,7 @@
 
   bool VisitCallExpr(CallExpr *E);
   bool VisitBinaryOperator(const BinaryOperator *E);
+  bool VisitOffsetOfExpr(const OffsetOfExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
   bool VisitConditionalOperator(const ConditionalOperator *E);
 
@@ -1365,20 +1368,56 @@
   return Success(Info.Ctx.getTypeSizeInChars(SrcTy).getQuantity(), E);
 }
 
+bool IntExprEvaluator::VisitOffsetOfExpr(const OffsetOfExpr *E) {
+  CharUnits Result;
+  const OffsetOfExpr::OffsetOfNode *Comps = E->getComponents();
+  unsigned n = E->getNumComponents();
+  if (n == 0)
+    return false;
+  QualType CurrentType = E->getTypeSourceInfo()->getType();
+  for (unsigned i = 0; i != n; ++i) {
+    const OffsetOfExpr::OffsetOfNode& ON = Comps[i];
+    if (ON.isBrackets) {
+      Expr *Idx = static_cast<Expr*>(ON.U.IndexExpr);
+      APSInt IdxResult;
+      if (!EvaluateInteger(Idx, IdxResult, Info))
+        return false;
+      const ArrayType *AT = Info.Ctx.getAsArrayType(CurrentType);
+      if (!AT)
+        return false;
+      CurrentType = AT->getElementType();
+      CharUnits ElementSize = Info.Ctx.getTypeSizeInChars(CurrentType);
+      Result += IdxResult.getSExtValue() * ElementSize;
+    }
+    else {
+      FieldDecl *MemberDecl = ON.U.MemberDecl;
+      const RecordType *RT = CurrentType->getAs<RecordType>();
+      if (!RT)
+        return false;
+      RecordDecl *RD = RT->getDecl();
+      const ASTRecordLayout &RL = Info.Ctx.getASTRecordLayout(RD);
+      unsigned i = 0;
+      for (RecordDecl::field_iterator Field = RD->field_begin(),
+                                      FieldEnd = RD->field_end();
+           Field != FieldEnd; (void)++Field, ++i) {
+        if (*Field == MemberDecl)
+          break;
+      }
+      if (i < RL.getFieldCount())
+        Result += CharUnits::fromQuantity(RL.getFieldOffset(i) / 8);
+      if (cast<RecordDecl>(MemberDecl->getDeclContext())->isAnonymousStructOrUnion())
+        CurrentType = MemberDecl->getType();
+      else
+        CurrentType = MemberDecl->getType().getNonReferenceType();
+    } 
+  }
+  return Success(Result.getQuantity(), E);
+}
+
 bool IntExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) {
   // Special case unary operators that do not need their subexpression
-  // evaluated.  offsetof/sizeof/alignof are all special.
-  if (E->isOffsetOfOp()) {
-    // The AST for offsetof is defined in such a way that we can just
-    // directly Evaluate it as an l-value.
-    APValue LV;
-    if (!EvaluateLValue(E->getSubExpr(), LV, Info))
-      return false;
-    if (LV.getLValueBase())
-      return false;
-    return Success(LV.getLValueOffset().getQuantity(), E);
-  }
-
+  // evaluated.  sizeof and alignof are special.
+  
   if (E->getOpcode() == UnaryOperator::LNot) {
     // LNot's operand isn't necessarily an integer, so we handle it specially.
     bool bres;
Index: lib/AST/StmtPrinter.cpp
===================================================================
--- lib/AST/StmtPrinter.cpp	(revisione 100962)
+++ lib/AST/StmtPrinter.cpp	(copia locale)
@@ -17,6 +17,7 @@
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "llvm/Support/Format.h"
+#include "clang/AST/Expr.h"
 using namespace clang;
 
 //===----------------------------------------------------------------------===//
@@ -76,8 +77,7 @@
       return OS;
     }
 
-    bool PrintOffsetOfDesignator(Expr *E);
-    void VisitUnaryOffsetOf(UnaryOperator *Node);
+    void PrintOffsetOfDesignator(OffsetOfExpr *E);
 
     void Visit(Stmt* S) {
       if (Helper && Helper->handledStmt(S,OS))
@@ -681,28 +681,31 @@
     OS << UnaryOperator::getOpcodeStr(Node->getOpcode());
 }
 
-bool StmtPrinter::PrintOffsetOfDesignator(Expr *E) {
-  if (isa<UnaryOperator>(E)) {
-    // Base case, print the type and comma.
-    OS << E->getType().getAsString() << ", ";
-    return true;
-  } else if (ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
-    PrintOffsetOfDesignator(ASE->getLHS());
-    OS << "[";
-    PrintExpr(ASE->getRHS());
-    OS << "]";
-    return false;
-  } else {
-    MemberExpr *ME = cast<MemberExpr>(E);
-    bool IsFirst = PrintOffsetOfDesignator(ME->getBase());
-    OS << (IsFirst ? "" : ".") << ME->getMemberDecl()->getNameAsString();
-    return false;
+void StmtPrinter::PrintOffsetOfDesignator(OffsetOfExpr *E) {
+  OS << E->getTypeSourceInfo()->getType().getAsString() << ", ";
+  const OffsetOfExpr::OffsetOfNode *Comps = E->getComponents();
+  size_t n = E->getNumComponents();
+  assert(n > 0 && !Comps[0].isBrackets && "Bad Vector of Components.");
+  OS << Comps[0].U.MemberDecl->getIdentifier()->getName();
+  for (unsigned i = 1; i < n; ++i) {
+    OffsetOfExpr::OffsetOfNode ON = Comps[i];
+    if (ON.isBrackets) {
+      OS << "[";
+      Expr *Idx = static_cast<Expr*>(ON.U.IndexExpr);
+      PrintExpr(Idx);
+      OS << "]";
+    }
+    else { // FIXME: Special declarations (e.g., unnamed struct) not handled.
+      IdentifierInfo *Info = ON.U.MemberDecl->getIdentifier();
+      if (Info)
+        OS << "." << Info->getName();
+    }
   }
 }
 
-void StmtPrinter::VisitUnaryOffsetOf(UnaryOperator *Node) {
+void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) {
   OS << "__builtin_offsetof(";
-  PrintOffsetOfDesignator(Node->getSubExpr());
+  PrintOffsetOfDesignator(Node);
   OS << ")";
 }
 
Index: lib/AST/StmtProfile.cpp
===================================================================
--- lib/AST/StmtProfile.cpp	(revisione 100962)
+++ lib/AST/StmtProfile.cpp	(copia locale)
@@ -261,6 +261,10 @@
   ID.AddInteger(S->getOpcode());
 }
 
+void StmtProfiler::VisitOffsetOfExpr(OffsetOfExpr *S) {
+  VisitExpr(S);
+}
+
 void StmtProfiler::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *S) {
   VisitExpr(S);
   ID.AddBoolean(S->isSizeOf());
Index: lib/AST/Expr.cpp
===================================================================
--- lib/AST/Expr.cpp	(revisione 100962)
+++ lib/AST/Expr.cpp	(copia locale)
@@ -334,7 +334,6 @@
   case Real:    return "__real";
   case Imag:    return "__imag";
   case Extension: return "__extension__";
-  case OffsetOf: return "__builtin_offsetof";
   }
 }
 
@@ -1835,7 +1834,9 @@
     case UnaryOperator::Real:
     case UnaryOperator::Imag:
       return CheckICE(Exp->getSubExpr(), Ctx);
-    case UnaryOperator::OffsetOf:
+    }
+  }
+  case Expr::OffsetOfExprClass: {
       // Note that per C99, offsetof must be an ICE. And AFAIK, using
       // Evaluate matches the proposed gcc behavior for cases like
       // "offsetof(struct s{int x[4];}, x[!.0])".  This doesn't affect
@@ -1843,7 +1844,6 @@
       // array subscripts that aren't ICEs, and if the array subscripts
       // are ICEs, the value of the offsetof must be an integer constant.
       return CheckEvalInICE(E, Ctx);
-    }
   }
   case Expr::SizeOfAlignOfExprClass: {
     const SizeOfAlignOfExpr *Exp = cast<SizeOfAlignOfExpr>(E);
@@ -2582,6 +2582,15 @@
 Stmt::child_iterator UnaryOperator::child_begin() { return &Val; }
 Stmt::child_iterator UnaryOperator::child_end() { return &Val+1; }
 
+// OffsetOfExpr
+Stmt::child_iterator OffsetOfExpr::child_begin() {
+  return child_iterator();
+}
+
+Stmt::child_iterator OffsetOfExpr::child_end() {
+  return child_iterator();
+}
+
 // SizeOfAlignOfExpr
 Stmt::child_iterator SizeOfAlignOfExpr::child_begin() {
   // If this is of a type and the type is a VLA type (and not a typedef), the
Index: lib/Checker/GRExprEngine.cpp
===================================================================
--- lib/Checker/GRExprEngine.cpp	(revisione 100962)
+++ lib/Checker/GRExprEngine.cpp	(copia locale)
@@ -769,6 +769,10 @@
       VisitReturnStmt(cast<ReturnStmt>(S), Pred, Dst);
       break;
 
+    case Stmt::OffsetOfExprClass:
+      VisitOffsetOfExpr(cast<OffsetOfExpr>(S), Pred, Dst);
+      break;
+
     case Stmt::SizeOfAlignOfExprClass:
       VisitSizeOfAlignOfExpr(cast<SizeOfAlignOfExpr>(S), Pred, Dst);
       break;
@@ -2573,6 +2577,21 @@
               ValMgr.makeIntVal(amt.getQuantity(), Ex->getType())));
 }
 
+void GRExprEngine::VisitOffsetOfExpr(OffsetOfExpr* OOE, ExplodedNode* Pred,
+                                     ExplodedNodeSet& Dst) {
+  Expr::EvalResult Res;
+  if (OOE->Evaluate(Res, getContext()) && Res.Val.isInt()) {
+    const APSInt &IV = Res.Val.getInt();
+    assert(IV.getBitWidth() == getContext().getTypeSize(OOE->getType()));
+    assert(OOE->getType()->isIntegerType());
+    assert(IV.isSigned() == OOE->getType()->isSignedIntegerType());
+    SVal X = ValMgr.makeIntVal(IV);
+    MakeNode(Dst, OOE, Pred, GetState(Pred)->BindExpr(OOE, X));
+    return;
+  }
+  // FIXME: Handle the case where __builtin_offsetof is not a constant.
+  Dst.Add(Pred);
+}
 
 void GRExprEngine::VisitUnaryOperator(UnaryOperator* U, ExplodedNode* Pred,
                                       ExplodedNodeSet& Dst, bool asLValue) {
@@ -2651,22 +2670,6 @@
       return;
     }
 
-    case UnaryOperator::OffsetOf: {
-      Expr::EvalResult Res;
-      if (U->Evaluate(Res, getContext()) && Res.Val.isInt()) {
-        const APSInt &IV = Res.Val.getInt();
-        assert(IV.getBitWidth() == getContext().getTypeSize(U->getType()));
-        assert(U->getType()->isIntegerType());
-        assert(IV.isSigned() == U->getType()->isSignedIntegerType());
-        SVal X = ValMgr.makeIntVal(IV);
-        MakeNode(Dst, U, Pred, GetState(Pred)->BindExpr(U, X));
-        return;
-      }
-      // FIXME: Handle the case where __builtin_offsetof is not a constant.
-      Dst.Add(Pred);
-      return;
-    }
-
     case UnaryOperator::Plus: assert (!asLValue);  // FALL-THROUGH.
     case UnaryOperator::Extension: {
 
Index: lib/CodeGen/CGExprScalar.cpp
===================================================================
--- lib/CodeGen/CGExprScalar.cpp	(revisione 100962)
+++ lib/CodeGen/CGExprScalar.cpp	(copia locale)
@@ -133,6 +133,7 @@
                                   CGF.getContext().typesAreCompatible(
                                     E->getArgType1(), E->getArgType2()));
   }
+  Value *VisitOffsetOfExpr(const OffsetOfExpr *E);
   Value *VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E);
   Value *VisitAddrLabelExpr(const AddrLabelExpr *E) {
     llvm::Value *V = CGF.GetAddrOfLabel(E->getLabel());
@@ -241,7 +242,6 @@
   Value *VisitUnaryExtension(const UnaryOperator *E) {
     return Visit(E->getSubExpr());
   }
-  Value *VisitUnaryOffsetOf(const UnaryOperator *E);
 
   // C++
   Value *VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
@@ -1035,6 +1035,14 @@
   return Builder.CreateZExt(BoolVal, ConvertType(E->getType()), "lnot.ext");
 }
 
+Value *ScalarExprEmitter::VisitOffsetOfExpr(const OffsetOfExpr *E) {
+  Expr::EvalResult Result;
+  if(E->Evaluate(Result, CGF.getContext()))
+    return llvm::ConstantInt::get(VMContext, Result.Val.getInt());
+  else
+    return llvm::Constant::getNullValue(ConvertType(E->getType()));
+}
+
 /// VisitSizeOfAlignOfExpr - Return the size or alignment of the type of
 /// argument of the sizeof expression as an integer.
 Value *
@@ -1083,12 +1091,6 @@
   return llvm::Constant::getNullValue(ConvertType(E->getType()));
 }
 
-Value *ScalarExprEmitter::VisitUnaryOffsetOf(const UnaryOperator *E) {
-  Value* ResultAsPtr = EmitLValue(E->getSubExpr()).getAddress();
-  const llvm::Type* ResultType = ConvertType(E->getType());
-  return Builder.CreatePtrToInt(ResultAsPtr, ResultType, "offsetof");
-}
-
 //===----------------------------------------------------------------------===//
 //                           Binary Operators
 //===----------------------------------------------------------------------===//
