Author: hhinnant
Date: Fri Sep 16 14:52:23 2011
New Revision: 139933
URL: http://llvm.org/viewvc/llvm-project?rev=139933&view=rev
Log:
Doug Gregor pointed out some problems with debug mode enabled in one TU and not
another. This patch helps detect those situations and offers improved error
messages to help get debug mode enabled in more TU's when it is absolutely
necessary to do so. Thanks Doug.
Modified:
libcxx/trunk/include/__debug
libcxx/trunk/include/iterator
libcxx/trunk/src/debug.cpp
Modified: libcxx/trunk/include/__debug
URL:
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__debug?rev=139933&r1=139932&r2=139933&view=diff
==============================================================================
--- libcxx/trunk/include/__debug (original)
+++ libcxx/trunk/include/__debug Fri Sep 16 14:52:23 2011
@@ -148,6 +148,7 @@
::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_);
}
+ void __insert_i(void* __i);
__c_node* __insert_c(void* __c);
void __erase_c(void* __c);
Modified: libcxx/trunk/include/iterator
URL:
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/iterator?rev=139933&r1=139932&r2=139933&view=diff
==============================================================================
--- libcxx/trunk/include/iterator (original)
+++ libcxx/trunk/include/iterator Fri Sep 16 14:52:23 2011
@@ -1063,7 +1063,12 @@
private:
iterator_type __i;
public:
- _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT {}
+ _LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT
+ {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+ __get_db()->__insert_i(this);
+#endif
+ }
template <class _Up> _LIBCPP_INLINE_VISIBILITY __wrap_iter(const
__wrap_iter<_Up>& __u,
typename enable_if<is_convertible<_Up, iterator_type>::value>::type* =
0) _NOEXCEPT
: __i(__u.base())
Modified: libcxx/trunk/src/debug.cpp
URL:
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/debug.cpp?rev=139933&r1=139932&r2=139933&view=diff
==============================================================================
--- libcxx/trunk/src/debug.cpp (original)
+++ libcxx/trunk/src/debug.cpp Fri Sep 16 14:52:23 2011
@@ -110,7 +110,9 @@
{
RLock _(mut());
__i_node* i = __find_iterator(__i);
- return i != nullptr ? (i->__c_ != nullptr ? i->__c_->__c_ : nullptr) :
nullptr;
+ _LIBCPP_ASSERT(i != nullptr, "iterator constructed in translation unit
with debug mode not enabled."
+ " #define _LIBCPP_DEBUG2 1 for that translation unit.");
+ return i->__c_ != nullptr ? i->__c_->__c_ : nullptr;
}
void
@@ -118,14 +120,20 @@
{
WLock _(mut());
__i_node* i = __insert_iterator(__i);
- _LIBCPP_ASSERT(__cbeg_ != __cend_, "debug mode internal logic error
__insert_ic A");
+ _LIBCPP_ASSERT(__cbeg_ != __cend_, "Container constructed in a translation
unit with debug mode disabled."
+ " But it is being used in a translation unit with debug
mode enabled."
+ " Enable it in the other translation unit with #define
_LIBCPP_DEBUG2 1");
size_t hc = hash<const void*>()(__c) % (__cend_ - __cbeg_);
__c_node* c = __cbeg_[hc];
- _LIBCPP_ASSERT(c != nullptr, "debug mode internal logic error __insert_ic
B");
+ _LIBCPP_ASSERT(c != nullptr, "Container constructed in a translation unit
with debug mode disabled."
+ " But it is being used in a translation unit with debug
mode enabled."
+ " Enable it in the other translation unit with #define
_LIBCPP_DEBUG2 1");
while (c->__c_ != __c)
{
c = c->__next_;
- _LIBCPP_ASSERT(c != nullptr, "debug mode internal logic error
__insert_ic C");
+ _LIBCPP_ASSERT(c != nullptr, "Container constructed in a translation
unit with debug mode disabled."
+ " But it is being used in a translation unit with debug
mode enabled."
+ " Enable it in the other translation unit with #define
_LIBCPP_DEBUG2 1");
}
c->__add(i);
i->__c_ = c;
@@ -365,6 +373,13 @@
(*p)->__c_ = p2;
}
+void
+__libcpp_db::__insert_i(void* __i)
+{
+ WLock _(mut());
+ __insert_iterator(__i);
+}
+
// private api
_LIBCPP_HIDDEN
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits