Index: tools/libclang/CIndex.cpp
===================================================================
--- tools/libclang/CIndex.cpp	(revision 174335)
+++ tools/libclang/CIndex.cpp	(working copy)
@@ -6224,8 +6224,11 @@
 
   // FIXME: Move to llvm/Support and make it cross-platform.
 #ifdef __APPLE__
+// constants are not defined on darwin8, expected in <sys/resource.h>
+#if	defined(PRIO_DARWIN_THREAD) && defined(PRIO_DARWIN_BG)
   setpriority(PRIO_DARWIN_THREAD, 0, PRIO_DARWIN_BG);
 #endif
+#endif
 }
 
 void cxindex::printDiagsToStderr(ASTUnit *Unit) {
Index: tools/libclang/CMakeLists.txt
===================================================================
--- tools/libclang/CMakeLists.txt	(revision 174335)
+++ tools/libclang/CMakeLists.txt	(working copy)
@@ -91,8 +91,12 @@
   endif()
 
   if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+# for system gcc-4.0.1
     set(LIBCLANG_LINK_FLAGS
       "-Wl,-compatibility_version -Wl,1 -Wl,-dead_strip")
+# for gcc-fsf-4.6 only:
+#    set(LIBCLANG_LINK_FLAGS
+#      "-Wl,-dylib_compatibility_version -Wl,1 -Wl,-dead_strip -Wl,-seg1addr -Wl,0xE0000000")
     set_target_properties(libclang
       PROPERTIES
       LINK_FLAGS "${LIBCLANG_LINK_FLAGS}"
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp	(revision 174335)
+++ lib/CodeGen/CGExpr.cpp	(working copy)
@@ -1100,7 +1100,6 @@
                                         QualType Ty,
                                         llvm::MDNode *TBAAInfo,
                                         bool isInit) {
-  
   // Handle vectors differently to get better performance.
   if (Ty->isVectorType()) {
     llvm::Type *SrcTy = Value->getType();
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp	(revision 174335)
+++ lib/Frontend/CompilerInvocation.cpp	(working copy)
@@ -39,7 +39,8 @@
   : LangOpts(new LangOptions()), TargetOpts(new TargetOptions()),
     DiagnosticOpts(new DiagnosticOptions()),
     HeaderSearchOpts(new HeaderSearchOptions()),
-    PreprocessorOpts(new PreprocessorOptions()) {}
+    PreprocessorOpts(new PreprocessorOptions()) {
+}
 
 CompilerInvocationBase::CompilerInvocationBase(const CompilerInvocationBase &X)
   : RefCountedBase<CompilerInvocation>(),
@@ -47,7 +48,8 @@
     TargetOpts(new TargetOptions(X.getTargetOpts())),
     DiagnosticOpts(new DiagnosticOptions(X.getDiagnosticOpts())),
     HeaderSearchOpts(new HeaderSearchOptions(X.getHeaderSearchOpts())),
-    PreprocessorOpts(new PreprocessorOptions(X.getPreprocessorOpts())) {}
+    PreprocessorOpts(new PreprocessorOptions(X.getPreprocessorOpts())) {
+}
 
 //===----------------------------------------------------------------------===//
 // Deserialization (from args)
@@ -1450,8 +1452,9 @@
   Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
 
   // Use the default target triple if unspecified.
-  if (Opts.Triple.empty())
+  if (Opts.Triple.empty()) {
     Opts.Triple = llvm::sys::getDefaultTargetTriple();
+  }
 }
 
 //
Index: lib/Frontend/InitHeaderSearch.cpp
===================================================================
--- lib/Frontend/InitHeaderSearch.cpp	(revision 174335)
+++ lib/Frontend/InitHeaderSearch.cpp	(working copy)
@@ -347,28 +347,35 @@
 
     case llvm::Triple::ppc:
     case llvm::Triple::ppc64:
+// This is a local hack-only, do not submit or commit.
+/**
       AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
-                                  "powerpc-apple-darwin10", "", "ppc64",
+                                  "powerpc-apple-darwin8", "", "ppc64",
                                   triple);
+**/
       AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
-                                  "powerpc-apple-darwin10", "", "ppc64",
+                                  "powerpc-apple-darwin8", "", "ppc64",
                                   triple);
       break;
 
     case llvm::Triple::x86:
     case llvm::Triple::x86_64:
+/**
       AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
-                                  "i686-apple-darwin10", "", "x86_64", triple);
+                                  "i686-apple-darwin8", "", "x86_64", triple);
+**/
       AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.0.0",
                                   "i686-apple-darwin8", "", "", triple);
       break;
 
     case llvm::Triple::arm:
     case llvm::Triple::thumb:
+/**
       AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
-                                  "arm-apple-darwin10", "v7", "", triple);
+                                  "arm-apple-darwin8", "v7", "", triple);
       AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
-                                  "arm-apple-darwin10", "v6", "", triple);
+                                  "arm-apple-darwin8", "v6", "", triple);
+**/
       break;
     }
     return;
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp	(revision 174335)
+++ lib/AST/ExprConstant.cpp	(working copy)
@@ -2682,7 +2682,8 @@
     if (E->isArrow()) {
       if (!EvaluatePointer(E->getBase(), Result, this->Info))
         return false;
-      BaseTy = E->getBase()->getType()->castAs<PointerType>()->getPointeeType();
+      BaseTy = E->getBase()->getType()->template castAs<PointerType>()
+		->getPointeeType();
     } else if (E->getBase()->isRValue()) {
       assert(E->getBase()->getType()->isRecordType());
       if (!EvaluateTemporary(E->getBase(), Result, this->Info))
Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp	(revision 174335)
+++ lib/AST/ASTContext.cpp	(working copy)
@@ -4931,6 +4931,7 @@
       llvm_unreachable("invalid builtin type for @encode");
     }
     llvm_unreachable("invalid BuiltinType::Kind value");
+    return '\0';	// unreachable, just to suppress warning
 }
 
 static char ObjCEncodingForEnumType(const ASTContext *C, const EnumType *ET) {
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp	(revision 174335)
+++ lib/Driver/Driver.cpp	(working copy)
@@ -1689,6 +1689,14 @@
     case llvm::Triple::IOS:
       if (Target.getArch() == llvm::Triple::x86 ||
           Target.getArch() == llvm::Triple::x86_64 ||
+#if 1
+	// uncomment this to use DarwinClang driver for ppc family
+          Target.getArch() == llvm::Triple::ppc ||
+          Target.getArch() == llvm::Triple::ppc64 ||
+	// see bugs:
+	// http://llvm.org/bugs/show_bug.cgi?id=14387
+	// http://llvm.org/bugs/show_bug.cgi?id=14275
+#endif
           Target.getArch() == llvm::Triple::arm ||
           Target.getArch() == llvm::Triple::thumb)
         TC = new toolchains::DarwinClang(*this, Target);
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 174335)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -3989,6 +3989,14 @@
 
   // Derived from darwin_arch spec.
   CmdArgs.push_back("-arch");
+#if 1
+// suggested patch from http://llvm.org/bugs/show_bug.cgi?id=3830
+  if (ArchName == "powerpc")
+    CmdArgs.push_back("ppc");
+  else if (ArchName == "powerpc64")
+    CmdArgs.push_back("ppc64");
+  else
+#endif
   CmdArgs.push_back(Args.MakeArgString(ArchName));
 
   // FIXME: Is this needed anymore?
Index: include/clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h
===================================================================
--- include/clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h	(revision 174335)
+++ include/clang/StaticAnalyzer/Core/PathSensitive/APSIntType.h	(working copy)
@@ -21,11 +21,16 @@
   bool IsUnsigned;
 
 public:
+  /// \brief Sanity check for possible unreasonable values
+  void sane_BitWidth(void) const {
+//    assert(BitWidth <= 99999);	// disable when not debugging
+  }
+
   APSIntType(uint32_t Width, bool Unsigned)
-    : BitWidth(Width), IsUnsigned(Unsigned) {}
+    : BitWidth(Width), IsUnsigned(Unsigned) { sane_BitWidth(); }
 
   /* implicit */ APSIntType(const llvm::APSInt &Value)
-    : BitWidth(Value.getBitWidth()), IsUnsigned(Value.isUnsigned()) {}
+    : BitWidth(Value.getBitWidth()), IsUnsigned(Value.isUnsigned()) { sane_BitWidth(); }
 
   uint32_t getBitWidth() const { return BitWidth; }
   bool isUnsigned() const { return IsUnsigned; }
@@ -53,6 +58,7 @@
 
   /// Returns an all-zero value for this type.
   llvm::APSInt getZeroValue() const LLVM_READONLY {
+    sane_BitWidth();
     return llvm::APSInt(BitWidth, IsUnsigned);
   }
 
Index: include/clang/Serialization/ASTReader.h
===================================================================
--- include/clang/Serialization/ASTReader.h	(revision 174335)
+++ include/clang/Serialization/ASTReader.h	(working copy)
@@ -277,10 +277,16 @@
   FileManager &FileMgr;
   DiagnosticsEngine &Diags;
 
+#if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
+public:	// workaround to grant access to classes nested within ASTDeclReader
+#endif
   /// \brief The semantic analysis object that will be processing the
   /// AST files and the translation unit that uses it.
   Sema *SemaObj;
 
+#if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
+private:
+#endif
   /// \brief The preprocessor that will be loading the source file.
   Preprocessor &PP;
 
@@ -822,6 +828,9 @@
   /// since the last time the declaration chains were linked.
   llvm::SmallPtrSet<Decl *, 16> RedeclsDeserialized;
   
+#if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
+public:	// workaround to grant access to classes nested within ASTDeclReader
+#endif
   /// \brief The list of redeclaration chains that still need to be 
   /// reconstructed.
   ///
@@ -833,6 +842,9 @@
   /// \brief Keeps track of the elements added to PendingDeclChains.
   llvm::SmallSet<serialization::DeclID, 16> PendingDeclChainsKnown;
 
+#if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
+private:
+#endif
   /// \brief The set of Objective-C categories that have been deserialized
   /// since the last time the declaration chains were linked.
   llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
Index: include/clang/Serialization/ASTBitCodes.h
===================================================================
--- include/clang/Serialization/ASTBitCodes.h	(revision 174335)
+++ include/clang/Serialization/ASTBitCodes.h	(working copy)
@@ -83,21 +83,21 @@
 
     /// \brief A type index; the type ID with the qualifier bits removed.
     class TypeIdx {
-      uint32_t Idx;
+      TypeID Idx;
     public:
       TypeIdx() : Idx(0) { }
-      explicit TypeIdx(uint32_t index) : Idx(index) { }
+      explicit TypeIdx(TypeID index) : Idx(index) { }
 
-      uint32_t getIndex() const { return Idx; }
+      TypeID getIndex() const { return Idx; }
       TypeID asTypeID(unsigned FastQuals) const {
-        if (Idx == uint32_t(-1))
+        if (Idx == TypeID(-1))
           return TypeID(-1);
         
         return (Idx << Qualifiers::FastWidth) | FastQuals;
       }
       static TypeIdx fromTypeID(TypeID ID) {
         if (ID == TypeID(-1))
-          return TypeIdx(-1);
+          return TypeIdx(TypeID(-1));
         
         return TypeIdx(ID >> Qualifiers::FastWidth);
       }
