Index: include/llvm/CodeGen/MachineInstr.h
===================================================================
--- include/llvm/CodeGen/MachineInstr.h	(revision 173212)
+++ include/llvm/CodeGen/MachineInstr.h	(working copy)
@@ -65,6 +65,7 @@
                                         // function frame setup code.
     BundledPred  = 1 << 1,              // Instruction has bundled predecessors.
     BundledSucc  = 1 << 2               // Instruction has bundled successors.
+    , InvalidMIFlag = 1 << 3		// Sanity checking
   };
 private:
   const MCInstrDesc *MCID;              // Instruction descriptor.
@@ -147,20 +148,25 @@
 
   /// getFlags - Return the MI flags bitvector.
   uint8_t getFlags() const {
+    assert(Flags < InvalidMIFlag);
     return Flags;
   }
 
   /// getFlag - Return whether an MI flag is set.
   bool getFlag(MIFlag Flag) const {
+    assert(Flags < InvalidMIFlag);
     return Flags & Flag;
   }
 
   /// setFlag - Set a MI flag.
   void setFlag(MIFlag Flag) {
+    assert(Flag < InvalidMIFlag);
     Flags |= (uint8_t)Flag;
   }
 
   void setFlags(unsigned flags) {
+    assert(flags < InvalidMIFlag);
+    // Mask below should be "static const"
     // Filter out the automatically maintained flags.
     unsigned Mask = BundledPred | BundledSucc;
     Flags = (Flags & Mask) | (flags & ~Mask);
@@ -168,6 +174,7 @@
 
   /// clearFlag - Clear a MI flag.
   void clearFlag(MIFlag Flag) {
+    assert(Flags < InvalidMIFlag);
     Flags &= ~((uint8_t)Flag);
   }
 
Index: include/llvm/Bitcode/BitstreamReader.h
===================================================================
--- include/llvm/Bitcode/BitstreamReader.h	(revision 173212)
+++ include/llvm/Bitcode/BitstreamReader.h	(working copy)
@@ -136,7 +136,9 @@
 ///   Record   - This is a record with a specific AbbrevID.
 ///
 struct BitstreamEntry {
-  enum {
+// anonymous enum named as workaround to g++-4.0.1 bug (fixed in 4.0.2):
+// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20589
+  enum KindEnum {
     Error,
     EndBlock,
     SubBlock,
Index: include/llvm/ADT/APInt.h
===================================================================
--- include/llvm/ADT/APInt.h	(revision 173212)
+++ include/llvm/ADT/APInt.h	(working copy)
@@ -91,14 +91,24 @@
     APINT_WORD_SIZE = static_cast<unsigned int>(sizeof(uint64_t))
   };
 
+public:
+  /// @brief Sanity check for debugging BidWidth, should be disabled
+  void sane_BitWidth(void) const {
+//    assert(BitWidth <= 99999);	// disable when not debugging
+  }
+
+private:
   /// This constructor is used only internally for speed of construction of
   /// temporaries. It is unsafe for general use so it is not public.
   /// @brief Fast internal constructor
-  APInt(uint64_t* val, unsigned bits) : BitWidth(bits), pVal(val) { }
+  APInt(uint64_t* val, unsigned bits) : BitWidth(bits), pVal(val) {
+    sane_BitWidth();
+  }
 
   /// @returns true if the number of bits <= 64, false otherwise.
   /// @brief Determine if this APInt just has one word to store value.
   bool isSingleWord() const {
+    sane_BitWidth();
     return BitWidth <= APINT_BITS_PER_WORD;
   }
 
@@ -234,6 +244,7 @@
     else
       initSlowCase(numBits, val, isSigned);
     clearUnusedBits();
+    sane_BitWidth();
   }
 
   /// Note that bigVal.size() can be smaller or larger than the corresponding
@@ -272,6 +283,7 @@
       VAL = that.VAL;
     else
       initSlowCase(that);
+    sane_BitWidth();
   }
 
 #if LLVM_HAS_RVALUE_REFERENCES
@@ -283,6 +295,7 @@
 
   /// @brief Destructor.
   ~APInt() {
+    sane_BitWidth();
     if (!isSingleWord())
       delete [] pVal;
   }
@@ -595,9 +608,10 @@
     if (isSingleWord() && RHS.isSingleWord()) {
       VAL = RHS.VAL;
       BitWidth = RHS.BitWidth;
+      sane_BitWidth();
       return clearUnusedBits();
     }
-
+    sane_BitWidth();
     return AssignSlowCase(RHS);
   }
 
Index: include/llvm/ADT/DenseMap.h
===================================================================
--- include/llvm/ADT/DenseMap.h	(revision 173212)
+++ include/llvm/ADT/DenseMap.h	(working copy)
@@ -714,7 +714,7 @@
     init(NumInitBuckets);
   }
 
-  SmallDenseMap(const SmallDenseMap &other) {
+  SmallDenseMap(const SmallDenseMap &other) : BaseT() {
     init(0);
     copyFrom(other);
   }
Index: include/llvm/Support/cppcat.h
===================================================================
--- include/llvm/Support/cppcat.h	(revision 0)
+++ include/llvm/Support/cppcat.h	(revision 0)
@@ -0,0 +1,48 @@
+/**
+	\file "util/cppcat.h"
+	Tricks for concatenating strings with the C-preprocessor.  
+	I learned this trick from:
+		http://www.slack.net/~ant/cpp/unqiue_name.html
+	$Id: cppcat.h,v 1.1 2010/03/14 22:25:16 fang Exp $
+ */
+
+#ifndef	__UTIL_CPPCAT_H__
+#define	__UTIL_CPPCAT_H__
+
+/**
+	Description also copied from the same web-site.
+
+	Sometimes one needs to supply an identifier for something that will 
+	never be referenced again. The most common occurrence is a local 
+	object of some type whose construction and destruction side-effects 
+	are wanted at the beginning and end of the scope it exists in, 
+	respectively. Having to come up with a name is both tedious and 
+	unclear, since the name will serve no purpose in the code. 
+	If it were possible, providing no name would make the intent clearer.
+
+	In the CONCAT macro, the seemingly-redundant helper macros 
+	(CONCAT_2_ and CONCAT_3_) are needed due to particulars of the 
+	preprocessor.
+
+	Generally, this construct will only be needed in a source file 
+	(and not a header). This makes it unlikely for it to clash with 
+	anything else. If it's needed in a header file, care must be 
+	taken that the name can't clash with any other identifier, 
+	because a clash may not show up until the header is integrated 
+	with another header file that happens to have an identical UNIQUE_NAME.
+ */
+
+#define	CONCAT_3_(x, y)		x##y
+#define	CONCAT_2_(x, y)		CONCAT_3_(x,y)
+#define	CONCAT(x, y)		CONCAT_2_(x,y)
+#define	UNIQUIFY(str)		CONCAT(str,__LINE__)
+
+/**
+	To try to protect macros with commas inside, without
+	requiring extra parentheses.  
+ */
+#define	CPPWRAP(x)		x
+
+
+#endif	// __UTIL_CPPCAT_H__
+
Index: include/llvm/Support/Compiler.h
===================================================================
--- include/llvm/Support/Compiler.h	(revision 173212)
+++ include/llvm/Support/Compiler.h	(working copy)
@@ -172,7 +172,10 @@
 #define LLVM_READNONE
 #endif
 
-#ifdef __GNUC__  // aka 'PURE' but following LLVM Conventions.
+// this attribute may be buggy for older gcc-4.0.1 (apple)
+// removing this fixes bug #14244
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
+// aka 'PURE' but following LLVM Conventions.
 #define LLVM_READONLY __attribute__((__pure__))
 #else
 #define LLVM_READONLY
Index: include/llvm/Support/Endian.h
===================================================================
--- include/llvm/Support/Endian.h	(revision 173212)
+++ include/llvm/Support/Endian.h	(working copy)
@@ -27,6 +27,31 @@
 enum {aligned = 0, unaligned = 1};
 
 namespace detail {
+#if 0
+template<typename value_type, alignment align>
+struct alignment_access_helper;
+
+template<typename value_type>
+struct alignment_access_helper<value_type, aligned>
+{
+  value_type val;
+};
+
+// Provides unaligned loads and stores.
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
+#pragma pack(push)
+#pragma pack(1)
+#endif
+template<typename value_type>
+struct alignment_access_helper<value_type, unaligned>
+{
+  value_type val;
+};
+#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
+#pragma pack(pop)
+#endif
+#endif
+
   /// \brief ::value is either alignment, or alignof(T) if alignment is 0.
   template<class T, int alignment>
   struct PickAlignment {
Index: include/llvm/Support/stacktrace.h
===================================================================
--- include/llvm/Support/stacktrace.h	(revision 0)
+++ include/llvm/Support/stacktrace.h	(revision 0)
@@ -0,0 +1,249 @@
+/**
+	\file "util/stacktrace.h"
+	Utility macros and header for convenient stack-trace debugging.
+	$Id: stacktrace.h,v 1.1 2010/03/14 22:25:18 fang Exp $
+ */
+
+#ifndef	__UTIL_STACKTRACE_H__
+#define	__UTIL_STACKTRACE_H__
+
+// macros for enabling/disabling stacktrace code
+/**
+	Strongly recommend using these macros to be able to 
+	turn everything off at compile time.  
+	Predefine this to 0 at compile time to turn-off.  
+ */
+#ifndef	ENABLE_STACKTRACE
+#define	ENABLE_STACKTRACE	0	// on (1) or off (0) by default
+#endif
+
+#include <cassert>
+#include <iosfwd>		// needed for std::ostream forward declaration
+
+//=============================================================================
+// This is the macro interface intended for the programmer.  
+#if ENABLE_STACKTRACE
+#include "llvm/Support/cppcat.h"		// for the UNIQUIFY macros
+#include "llvm/Support/Compiler.h"	// for LLVM_ATTRIBUTE_UNUSED
+
+#define	__ATTRIBUTE_UNUSED__		LLVM_ATTRIBUTE_UNUSED
+
+/**
+	The macro that keeps track of scope and call stacks.  
+	\param str the string to be printed.  
+ */
+#define	STACKTRACE(str)							\
+	const util::stacktrace UNIQUIFY(__stacktrace_) (str)
+/**
+	No user-supplied string required, uses __PRETTY_FUNCTION__
+	built-in internal string.  Is this gcc-only?
+	There's always __func__ for brevity.
+ */
+#define	STACKTRACE_BRIEF						\
+	const util::stacktrace UNIQUIFY(__stacktrace_) (__func__)
+#define	STACKTRACE_VERBOSE						\
+	const util::stacktrace UNIQUIFY(__stacktrace__) (__PRETTY_FUNCTION__)
+/**
+	This enables echoing each time trace stack is updated, i.e., 
+	upon entering and leaving function call stack 
+	or lexical scopes.  
+ */
+#define STACKTRACE_ECHO_ON						\
+	const util::stacktrace::echo UNIQUIFY(__echo_stacktrace__) (1)
+#define STACKTRACE_ECHO_OFF						\
+	const util::stacktrace::echo UNIQUIFY(__echo_stacktrace__) (0)
+#define	STACKTRACE_STREAM						\
+		util::stacktrace::stream()
+/**
+	Indents and returns the current stream used by stacktrace.  
+ */
+#define STACKTRACE_INDENT						\
+		STACKTRACE_STREAM << util::stacktrace_auto_indent
+/**
+	ostream << style printing.  
+	This interface is preferable when compiler isn't smart enough
+	to optimize away no-ops with the null_stacktrace_stream.  
+	\param x may be a set of <<-cascaded arguments.  
+ */
+#define	STACKTRACE_INDENT_PRINT(x)	STACKTRACE_INDENT << x
+#define REDIRECT_STACKTRACE(os)						\
+	const util::stacktrace::redirect UNIQUIFY(__redir_stacktrace__) (os)
+#define	ASSERT_STACKTRACE(expr)						\
+	if (!(expr)) { util::stacktrace::full_dump(); assert(expr); }
+
+#else	// ENABLE_STACKTRACE --------------------------------------------------
+
+#define	STACKTRACE(str)
+#define	STACKTRACE_BRIEF
+#define	STACKTRACE_VERBOSE
+#define STACKTRACE_ECHO_ON
+#define STACKTRACE_ECHO_OFF
+#define	STACKTRACE_STREAM		NULL_STACKTRACE_STREAM
+#define STACKTRACE_INDENT		NULL_STACKTRACE_STREAM
+#define	STACKTRACE_INDENT_PRINT(x)
+#define REDIRECT_STACKTRACE(os)
+#define	ASSERT_STACKTRACE(expr)		assert(expr)
+#endif	// ENABLE_STACKTRACE --------------------------------------------------
+
+//=============================================================================
+// additional macros for general purpose use
+// we provide these macro layers for ease controlling
+// certain subsets of debugging
+
+#ifndef	STACKTRACE_DESTRUCTORS
+#define	STACKTRACE_DESTRUCTORS		(0 && ENABLE_STACKTRACE)
+#endif
+#ifndef	STACKTRACE_CONSTRUCTORS
+#define	STACKTRACE_CONSTRUCTORS		(0 && ENABLE_STACKTRACE)
+#endif
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+/**
+	STACKTRACE_DTOR is intended for use with destructors
+ */
+#ifndef	STACKTRACE_DTOR
+#if STACKTRACE_DESTRUCTORS
+	#define	STACKTRACE_DTOR(x)	STACKTRACE(x)
+	#define	STACKTRACE_DTOR_BRIEF	STACKTRACE_BRIEF
+	#define	STACKTRACE_DTOR_VERBOSE	STACKTRACE_VERBOSE
+	#define	STACKTRACE_DTOR_PRINT(x)	STACKTRACE_INDENT_PRINT(x)
+#else
+	#define	STACKTRACE_DTOR(x)
+	#define	STACKTRACE_DTOR_BRIEF
+	#define	STACKTRACE_DTOR_VERBOSE
+	#define	STACKTRACE_DTOR_PRINT(x)
+#endif	// STACKTRACE_DESTRUCTORS
+#endif	// STACKTRACE_DTOR
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+/**
+	STACKTRACE_CTOR is intended for use with constructors
+ */
+#ifndef	STACKTRACE_CTOR
+#if STACKTRACE_CONSTRUCTORS
+	#define	STACKTRACE_CTOR(x)	STACKTRACE(x)
+	#define	STACKTRACE_CTOR_BRIEF	STACKTRACE_BRIEF
+	#define	STACKTRACE_CTOR_VERBOSE	STACKTRACE_VERBOSE
+	#define	STACKTRACE_CTOR_PRINT(x)	STACKTRACE_INDENT_PRINT(x)
+#else
+	#define	STACKTRACE_CTOR(x)
+	#define	STACKTRACE_CTOR_BRIEF
+	#define	STACKTRACE_CTOR_VERBOSE
+	#define	STACKTRACE_CTOR_PRINT(x)
+#endif	// STACKTRACE_CONSTRUCTORS
+#endif	// STACKTRACE_CTOR
+
+//=============================================================================
+
+#if ENABLE_STACKTRACE
+
+#include <iosfwd>
+#include <string>
+#include <list>
+#include <stack>	// needed
+
+namespace util {
+using std::list;
+using std::string;
+using std::stack;
+
+//=============================================================================
+/**
+	Nothing is inlined because when you're debugging you shouldn't be
+	varing about performance.  
+	Can use for function scopes or any conditional statement scopes.  
+	Two mechanisms for controlling behavior, 
+	compile-time macros and public static variables.  
+	TODO: make one entry per thread, mapped by thread ID.
+ */
+class stacktrace {
+public:
+	/// the type of stack used to hold feedback text
+	typedef list<string>			stack_text_type;
+	/// the type of stack used to track on/off mode
+	typedef stack<int>			stack_echo_type;
+	/// the type of stack used to track stream redirections
+	typedef stack<std::ostream*>		stack_streams_type;
+
+public:
+	class manager;
+	struct echo;
+	struct redirect;
+	struct indent { };
+
+public:
+//	stacktrace(const char*);
+	stacktrace(const string&);
+	~stacktrace();
+public:
+	static
+	std::ostream&
+	stream(void);
+
+	/**
+		Explicit request by user to dump the stack trace.
+		Useful in assertion failures.  
+	 */
+	static
+	void
+	full_dump(void);
+
+private:
+	// and undefined
+	// non-copy-able
+	explicit
+	stacktrace(const stacktrace&);
+
+	// non-assignable
+	stacktrace&
+	operator = (const stacktrace&);
+
+	// non-heap allocatable
+	static void* operator new (size_t);
+	static void operator delete (void*);
+	static void* operator new (size_t, void*);
+	static void operator delete (void*, void*);
+	static void* operator new [] (size_t);
+	static void operator delete [] (void*);
+	static void* operator new [] (size_t, void*);
+	static void operator delete [] (void*, void*);
+
+} __ATTRIBUTE_UNUSED__ ;	// end class stacktrace
+
+//-----------------------------------------------------------------------------
+extern const stacktrace::indent	stacktrace_auto_indent;
+
+std::ostream&
+operator << (std::ostream&, const stacktrace::indent&);
+
+//-----------------------------------------------------------------------------
+/**
+	Whether or not to print upon entering and exiting.
+	Pass in 0 to disable.  
+	Enabling/disable lasts for the duration of the scope.  
+ */
+struct stacktrace::echo {
+	echo(const int i = 1);
+	~echo();
+} __ATTRIBUTE_UNUSED__ ;	// end struct echo
+
+//-----------------------------------------------------------------------------
+/**
+	Redirect all stack dumps to this ostream until changed otherwise.
+	Lasts for the duration of the scope where this is called.  
+ */
+struct stacktrace::redirect {
+	redirect(std::ostream&);
+	~redirect();
+} __ATTRIBUTE_UNUSED__ ;	// end struct redirect
+
+//=============================================================================
+
+}	// end namespace util
+
+#else	// ENABLE_STACKTRACE
+	// don't even bother processing class declaration!
+#endif	// ENABLE_STACKTRACE
+
+#endif	// __UTIL_STACKTRACE_H__
+
Index: utils/lit/lit/TestRunner.py
===================================================================
--- utils/lit/lit/TestRunner.py	(revision 173212)
+++ utils/lit/lit/TestRunner.py	(working copy)
@@ -383,7 +383,8 @@
             if script and script[-1][-1] == '\\':
                 script[-1] = script[-1][:-1] + ln
             else:
-                script.append(ln)
+                script.append('gtimeout 5m ' +ln)
+		# do not commit this patch
         elif 'XFAIL:' in ln:
             items = ln[ln.index('XFAIL:') + 6:].split(',')
             xfails.extend([s.strip() for s in items])
Index: utils/lit/lit/LitConfig.py
===================================================================
--- utils/lit/lit/LitConfig.py	(revision 173212)
+++ utils/lit/lit/LitConfig.py	(working copy)
@@ -34,7 +34,8 @@
         self.debug = debug
         self.isWindows = bool(isWindows)
         self.params = dict(params)
-        self.bashPath = None
+	# local hack only, don't commit this patch
+        self.bashPath = '/sw/bin/bash'
 
         self.numErrors = 0
         self.numWarnings = 0
Index: tools/bugpoint-passes/CMakeLists.txt
===================================================================
--- tools/bugpoint-passes/CMakeLists.txt	(revision 173212)
+++ tools/bugpoint-passes/CMakeLists.txt	(working copy)
@@ -1,3 +1,6 @@
+# patch: this should be built as a bundle/module/plug-in
+set(MODULE TRUE)
+
 if( NOT LLVM_BUILD_TOOLS )
   set(EXCLUDE_FROM_ALL ON)
 endif()
Index: lib/Support/CMakeLists.txt
===================================================================
--- lib/Support/CMakeLists.txt	(revision 173212)
+++ lib/Support/CMakeLists.txt	(working copy)
@@ -106,4 +106,7 @@
   Windows/system_error.inc
   Windows/ThreadLocal.inc
   Windows/TimeValue.inc
+
+# fang's debugging tools
+  stacktrace.cc
   )
Index: lib/Support/Atomic.cpp
===================================================================
--- lib/Support/Atomic.cpp	(revision 173212)
+++ lib/Support/Atomic.cpp	(working copy)
@@ -21,6 +21,16 @@
 #undef MemoryFence
 #endif
 
+#if defined(__APPLE__) && 0
+#include <libkern/OSAtomic.h>
+// __APPLE__ should take precedence over __GNUC__
+// sys::cas_flag is int32_t from Support/Atomic.h, so use '32' variants
+// prototypes lack the 'volatile' qualifier, so we need to cast them away
+template <class T>
+static inline
+T* vcast(volatile T* ptr) { return const_cast<T*>(ptr); }
+#endif
+
 #if defined(__GNUC__) || (defined(__IBMCPP__) && __IBMCPP__ >= 1210)
 #define GNU_ATOMICS
 #endif
@@ -28,14 +38,16 @@
 void sys::MemoryFence() {
 #if LLVM_HAS_ATOMICS == 0
   return;
-#else
-#  if defined(GNU_ATOMICS)
+/**
+#elif defined(__APPLE__)
+  OSMemoryBarrier();
+**/
+#elif defined(GNU_ATOMICS)
   __sync_synchronize();
-#  elif defined(_MSC_VER)
+#elif defined(_MSC_VER)
   MemoryBarrier();
-#  else
+#else
 # error No memory fence implementation for your platform!
-#  endif
 #endif
 }
 
@@ -47,6 +59,10 @@
   if (result == old_value)
     *ptr = new_value;
   return result;
+/**
+#elif defined(__APPLE__)
+  return OSAtomicCompareAndSwap32(old_value, new_value, vcast(ptr));
+**/
 #elif defined(GNU_ATOMICS)
   return __sync_val_compare_and_swap(ptr, old_value, new_value);
 #elif defined(_MSC_VER)
@@ -60,6 +76,10 @@
 #if LLVM_HAS_ATOMICS == 0
   ++(*ptr);
   return *ptr;
+/**
+#elif defined(__APPLE__)
+  return OSAtomicIncrement32(vcast(ptr));
+**/
 #elif defined(GNU_ATOMICS)
   return __sync_add_and_fetch(ptr, 1);
 #elif defined(_MSC_VER)
@@ -73,6 +93,10 @@
 #if LLVM_HAS_ATOMICS == 0
   --(*ptr);
   return *ptr;
+/**
+#elif defined(__APPLE__)
+  return OSAtomicDecrement32(vcast(ptr));
+**/
 #elif defined(GNU_ATOMICS)
   return __sync_sub_and_fetch(ptr, 1);
 #elif defined(_MSC_VER)
@@ -86,6 +110,10 @@
 #if LLVM_HAS_ATOMICS == 0
   *ptr += val;
   return *ptr;
+/**
+#elif defined(__APPLE__)
+  return OSAtomicAdd32(val, vcast(ptr));
+**/
 #elif defined(GNU_ATOMICS)
   return __sync_add_and_fetch(ptr, val);
 #elif defined(_MSC_VER)
Index: lib/Support/stacktrace.cc
===================================================================
--- lib/Support/stacktrace.cc	(revision 0)
+++ lib/Support/stacktrace.cc	(revision 0)
@@ -0,0 +1,183 @@
+/**
+	\file "util/stacktrace.cc"
+	Implementation of stacktrace class.
+	$Id: stacktrace.cc,v 1.1 2010/03/14 22:25:17 fang Exp $
+ */
+
+// ENABLE_STACKTRACE is forced for this module, regardless of pre-definitions!
+#define	ENABLE_STACKTRACE	1
+
+#include "llvm/Support/stacktrace.h"
+#include <iostream>
+#include <iterator>
+
+namespace util {
+using std::list;
+using std::ostream;
+using std::stack;
+using std::ostream_iterator;
+using std::cout;
+using std::cerr;
+using std::endl;
+
+/**
+	Guarantee that ios is initialized.  
+ */
+static const std::ios_base::Init ios_init;
+
+//=============================================================================
+/**
+	Private implementation class, not visible to other modules.  
+	Only written as a class for convenient static initialization.  
+	To be able to trace function calls that occur during static 
+	initialization, we must guarantee that the manager's static 
+	objects are initialized first!  Global initialization ordering is
+	generally non-trivial, so resort to the techinique of 
+	interfacing through reference functions which will guarantee 
+	a one-time initialization upon first invocation.  
+	(This technique is also used in util::persistent_object_manager.)
+ */
+class stacktrace::manager {
+public:
+	typedef	stacktrace::stack_text_type	stack_text_type;
+	typedef	stacktrace::stack_echo_type	stack_echo_type;
+	typedef	stacktrace::stack_streams_type	stack_streams_type;
+
+	static stack_text_type		stack_text;
+	static stack_text_type		stack_indent;
+	static stack_echo_type		stack_echo;
+	static stack_streams_type	stack_streams;
+
+private:
+	manager() {
+		// initialization moved to static initialization below.
+	}
+
+	~manager() { }
+
+public:
+	static
+	ostream&
+	print_auto_indent(ostream& o) {
+		// guarantee iostream initialized before first used.  
+		static const std::ios_base::Init ios_init;
+		static const stack_text_type& si(manager::stack_indent);
+		// INVARIANT(o.good());
+		ostream_iterator<string> osi(o);
+		copy(si.begin(), si.end(), osi);
+		return o;
+	}
+
+};	// end class stacktrace::manager
+
+//-----------------------------------------------------------------------------
+// static construction
+
+stacktrace::manager::stack_text_type
+stacktrace::manager::stack_text;
+
+stacktrace::manager::stack_text_type
+stacktrace::manager::stack_indent;
+
+stacktrace::manager::stack_echo_type
+stacktrace::manager::stack_echo;
+
+stacktrace::manager::stack_streams_type
+stacktrace::manager::stack_streams;
+
+static const int stack_echo_init =
+(stacktrace::manager::stack_echo.push(1), 1);
+
+static const int stack_stream_init =
+(stacktrace::manager::stack_streams.push(&cerr), 1);
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+/**
+	Stacktrace stream manipulator.  
+ */
+const stacktrace::indent
+stacktrace_auto_indent = stacktrace::indent();
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+/**
+	Uses the stacktrace's position to automatically indent.  
+ */
+ostream&
+operator << (ostream& o, const stacktrace::indent&) {
+	// need static initializers?
+	return stacktrace::manager::print_auto_indent(o) << ":  ";
+}
+
+//=============================================================================
+// class stacktrace method definitions
+
+stacktrace::stacktrace(const string& s) {
+	// cannot use string (without ref-count) because it may be destroyed
+	// prematurely during static destruction, char* is robust and permanent.
+	static const char* const
+		default_stack_indent_string = "| ";	// permanent
+	// must be static or else, new ref_counts will be locally released
+	manager::stack_text.push_back(s);
+	if (manager::stack_echo.top()) {
+		ostream& os(*manager::stack_streams.top());
+			manager::print_auto_indent(os) << "\\-{ " <<
+				manager::stack_text.back() << endl;
+	}
+	manager::stack_indent.push_back(default_stack_indent_string);
+}
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+stacktrace::~stacktrace() {
+	manager::stack_indent.pop_back();
+	if (manager::stack_echo.top()) {
+		ostream& os(*manager::stack_streams.top());
+			manager::print_auto_indent(os) << "/-} " <<
+				manager::stack_text.back() << endl;
+	}
+	manager::stack_text.pop_back();
+}
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+/**
+	Returns reference to the current stacktrace output stream.
+ */
+ostream&
+stacktrace::stream(void) {
+	return *manager::stack_streams.top();
+}
+
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+void
+stacktrace::full_dump(void) {
+	ostream& current_stream(stream());
+	ostream_iterator<string> osi(current_stream, "\n");
+	copy(manager::stack_text.begin(), manager::stack_text.end(), osi);
+	current_stream << endl;
+}
+
+//=============================================================================
+// struct stacktrace::echo method definitions
+
+stacktrace::echo::echo(const int i) {
+	manager::stack_echo.push(i);
+}
+
+stacktrace::echo::~echo() {
+	manager::stack_echo.pop();
+}
+
+//=============================================================================
+// struct redirect_stacktrace method definitions
+
+stacktrace::redirect::redirect(ostream& o) {
+	manager::stack_streams.push(&o);
+}
+
+stacktrace::redirect::~redirect() {
+	manager::stack_streams.pop();
+}
+
+//=============================================================================
+}	// end namespace util
+
+
Index: lib/Support/Unix/Signals.inc
===================================================================
--- lib/Support/Unix/Signals.inc	(revision 173212)
+++ lib/Support/Unix/Signals.inc	(working copy)
@@ -314,7 +314,7 @@
 void llvm::sys::PrintStackTraceOnErrorSignal() {
   AddSignalHandler(PrintStackTraceSignalHandler, 0);
 
-#if defined(__APPLE__)
+#if defined(__APPLE__) && defined(MACH_EXCEPTION_CODES) && defined(EXC_MASK_CRASH)
   // Environment variable to disable any kind of crash dialog.
   if (getenv("LLVM_DISABLE_CRASH_REPORT")) {
     mach_port_t self = mach_task_self();
Index: lib/Support/Unix/Memory.inc
===================================================================
--- lib/Support/Unix/Memory.inc	(revision 173212)
+++ lib/Support/Unix/Memory.inc	(working copy)
@@ -51,7 +51,7 @@
 	 llvm::sys::Memory::MF_EXEC:
     return PROT_READ | PROT_WRITE | PROT_EXEC;
   case llvm::sys::Memory::MF_EXEC:
-    return PROT_EXEC;
+    return PROT_EXEC | PROT_READ;	// patch from Roman Divacky, bug 14278
   default:
     llvm_unreachable("Illegal memory protection flag specified!");
   }
Index: lib/Support/APInt.cpp
===================================================================
--- lib/Support/APInt.cpp	(revision 173212)
+++ lib/Support/APInt.cpp	(working copy)
@@ -79,6 +79,7 @@
   if (isSigned && int64_t(val) < 0)
     for (unsigned i = 1; i < getNumWords(); ++i)
       pVal[i] = -1ULL;
+  sane_BitWidth();
 }
 
 void APInt::initSlowCase(const APInt& that) {
@@ -158,6 +159,7 @@
     pVal[0] = RHS;
     memset(pVal+1, 0, (getNumWords() - 1) * APINT_WORD_SIZE);
   }
+  sane_BitWidth();
   return clearUnusedBits();
 }
 
Index: lib/Target/CMakeLists.txt
===================================================================
--- lib/Target/CMakeLists.txt	(revision 173212)
+++ lib/Target/CMakeLists.txt	(working copy)
@@ -14,3 +14,7 @@
   message(STATUS "Targeting ${t}")
   add_subdirectory(${t})
 endforeach()
+
+# needed for symbol: llvm::MachineInstr::hasPropertyInBundle(unsigned int, llvm::MachineInstr::QueryType) const
+# but creates cyclic dependency
+# target_link_libraries(LLVMTarget LLVMCodeGen)
Index: lib/Transforms/Hello/CMakeLists.txt
===================================================================
--- lib/Transforms/Hello/CMakeLists.txt	(revision 173212)
+++ lib/Transforms/Hello/CMakeLists.txt	(working copy)
@@ -1,3 +1,5 @@
+# patch: this should be built as a bundle/module/plug-in
+set(MODULE TRUE)
 add_llvm_loadable_module( LLVMHello
   Hello.cpp
   )
Index: lib/Transforms/Instrumentation/MemorySanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/MemorySanitizer.cpp	(revision 173212)
+++ lib/Transforms/Instrumentation/MemorySanitizer.cpp	(working copy)
@@ -174,8 +174,15 @@
  private:
   void initializeCallbacks(Module &M);
 
+// workaround accessibility bug in g++-4.0
+#if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
+ public:
+#endif
   /// \brief Track origins (allocation points) of uninitialized values.
   bool TrackOrigins;
+#if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ < 2)
+ private:
+#endif
 
   DataLayout *TD;
   LLVMContext *C;
Index: lib/MC/MCDisassembler/CMakeLists.txt
===================================================================
--- lib/MC/MCDisassembler/CMakeLists.txt	(revision 173212)
+++ lib/MC/MCDisassembler/CMakeLists.txt	(working copy)
@@ -1,3 +1,27 @@
 add_llvm_library(LLVMMCDisassembler
   Disassembler.cpp
   )
+
+target_link_libraries(LLVMMCDisassembler
+  LLVMMC
+  LLVMMCParser
+  LLVMSupport
+  LLVMTarget
+  )
+
+foreach(t ${LLVM_TARGETS_TO_BUILD})
+  set(td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t})
+  if(EXISTS ${td}/TargetInfo/CMakeLists.txt)
+    target_link_libraries(LLVMMCDisassembler "LLVM${t}Info")
+  endif()
+  if(EXISTS ${td}/MCTargetDesc/CMakeLists.txt)
+    target_link_libraries(LLVMMCDisassembler "LLVM${t}Desc")
+  endif()
+  if(EXISTS ${td}/AsmParser/CMakeLists.txt)
+    target_link_libraries(LLVMMCDisassembler "LLVM${t}AsmParser")
+  endif()
+  if(EXISTS ${td}/Disassembler/CMakeLists.txt)
+    target_link_libraries(LLVMMCDisassembler "LLVM${t}Disassembler")
+  endif()
+endforeach(t)
+
Index: lib/CodeGen/MachineFunction.cpp
===================================================================
--- lib/CodeGen/MachineFunction.cpp	(revision 173212)
+++ lib/CodeGen/MachineFunction.cpp	(working copy)
@@ -166,8 +166,10 @@
 MachineInstr *
 MachineFunction::CreateMachineInstr(const MCInstrDesc &MCID,
                                     DebugLoc DL, bool NoImp) {
-  return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
-    MachineInstr(*this, MCID, DL, NoImp);
+  MachineInstr * ret = InstructionRecycler.Allocate<MachineInstr>(Allocator);
+    new (ret) MachineInstr(*this, MCID, DL, NoImp);
+  ret->getFlags();	// assertion check
+  return ret;
 }
 
 /// CloneMachineInstr - Create a new MachineInstr which is a copy of the
@@ -176,8 +178,10 @@
 ///
 MachineInstr *
 MachineFunction::CloneMachineInstr(const MachineInstr *Orig) {
-  return new (InstructionRecycler.Allocate<MachineInstr>(Allocator))
-             MachineInstr(*this, *Orig);
+  MachineInstr * ret = InstructionRecycler.Allocate<MachineInstr>(Allocator);
+    new (ret) MachineInstr(*this, *Orig);
+  ret->getFlags();	// assertion check
+  return ret;
 }
 
 /// DeleteMachineInstr - Delete the given MachineInstr.
@@ -186,6 +190,7 @@
 /// ~MachineInstr() destructor must be empty.
 void
 MachineFunction::DeleteMachineInstr(MachineInstr *MI) {
+  MI->getFlags();	// assertion check
   // Strip it for parts. The operand array and the MI object itself are
   // independently recyclable.
   if (MI->Operands)
Index: autoconf/configure.ac
===================================================================
--- autoconf/configure.ac	(revision 173212)
+++ autoconf/configure.ac	(working copy)
@@ -1617,9 +1617,9 @@
     ]]),
   AC_LANG_POP([C++])
   AC_MSG_RESULT(yes)
-  AC_DEFINE(LLVM_HAS_ATOMICS, 1, Has gcc/MSVC atomic intrinsics),
+  AC_DEFINE(LLVM_HAS_ATOMICS, 1, Has gcc/MSVC/Apple atomic intrinsics),
   AC_MSG_RESULT(no)
-  AC_DEFINE(LLVM_HAS_ATOMICS, 0, Has gcc/MSVC atomic intrinsics)
+  AC_DEFINE(LLVM_HAS_ATOMICS, 0, Has gcc/MSVC/Apple atomic intrinsics)
   AC_MSG_WARN([LLVM will be built thread-unsafe because atomic builtins are missing]))
 
 dnl===-----------------------------------------------------------------------===
