[cfe-commits] [libcxxabi] r169022 - in /libcxxabi/trunk: src/cxa_demangle.cpp test/test_demangle.cpp
Howard Hinnant
hhinnant at apple.com
Fri Nov 30 10:43:51 PST 2012
Author: hhinnant
Date: Fri Nov 30 12:43:50 2012
New Revision: 169022
URL: http://llvm.org/viewvc/llvm-project?rev=169022&view=rev
Log:
__list::ends_with_template was giving the wrong answer for empty lists. And __parse_unnamed_type_name wasn't properly handling the list of paramters and was not safe against incorrectly mangled lambdas (running past last).
Modified:
libcxxabi/trunk/src/cxa_demangle.cpp
libcxxabi/trunk/test/test_demangle.cpp
Modified: libcxxabi/trunk/src/cxa_demangle.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp?rev=169022&r1=169021&r2=169022&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_demangle.cpp (original)
+++ libcxxabi/trunk/src/cxa_demangle.cpp Fri Nov 30 12:43:50 2012
@@ -133,9 +133,14 @@
{
for (int i = 0; i < 2*indent; ++i)
printf(" ");
- char* buf = (char*)malloc(x->size());
+ size_t sz = x->size();
+ char* buf = (char*)calloc(sz+10, 1);
x->get_demangled_name(buf);
- printf("%s %s, %p\n", typeid(*x).name(), buf, x);
+ printf("%s [%ld] %s, %p\n", typeid(*x).name(), sz, buf, x);
+ if (strlen(buf) != sz)
+ {
+ printf("strlen(buf) = %ld and size = %ld\n", strlen(buf), sz);
+ }
free(buf);
display(x->__left_, indent+1);
display(x->__right_, indent+1);
@@ -3822,10 +3827,14 @@
}
virtual bool ends_with_template(bool parsing = false) const
{
- if (__right_ != NULL)
+ if (__right_ && __right_->size() > 0)
+ {
return __right_->ends_with_template(parsing);
- if (__left_ != NULL)
+ }
+ else if (__left_ && __left_->size() > 0)
+ {
return __left_->ends_with_template(parsing);
+ }
return false;
}
virtual bool fix_forward_references(__node** t_begin, __node** t_end)
@@ -6969,50 +6978,62 @@
{
case 't':
case 'l':
- first += 2;
-
+ {
+ const char* t = first + 2;
+ __node* params = 0;
if (type == 'l')
{
- __root_ = 0;
- if (first[0] == 'v')
+ if (*t == 'v')
{
// void lambda
- ++first;
- if (first[0] == 'E')
- ++first;
+ ++t;
+ if (t != last && *t == 'E')
+ ++t;
else
return first;
}
else
{
- while (first[0] && first[0] != 'E')
+ const char* t1 = __parse_type(t, last);
+ if (t1 == t || !__make<__list>(__root_))
+ return first;
+ params = __root_;
+ __node* prev = params;
+ t = t1;
+ while (true)
{
- const char *old = first;
- first = __parse_type(first, last);
- if (first == old)
+ t1 = __parse_type(t, last);
+ if (t1 == t)
break;
+ if (!__make<__list>(__root_))
+ return first;
+ t = t1;
+ prev->__right_ = __root_;
+ __root_->__size_ = prev->__size_ + 1;
+ prev = __root_;
}
- if (first[0] == 'E')
- ++first;
- else
+ if (t == last || *t != 'E')
return first;
+ ++t;
}
}
- const char *number_start = first;
- first = __parse_number(first, last);
- const char *number_end = first;
- if (first[0] == '_')
- {
- ++first;
- }
- else
+ const char* number_start = t;
+ const char* number_end = __parse_number(t, last);
+ if (number_end == last || *number_end != '_')
return first;
-
+ t = number_end + 1;
if (type == 'l')
- __make<__lambda_node>(__root_, number_start, static_cast<size_t>(number_end - number_start));
+ {
+ if (!__make<__lambda_node>(params, number_start, static_cast<size_t>(number_end - number_start)))
+ return first;
+ }
else
- __make<__unnamed>(number_start, static_cast<size_t>(number_end - number_start));
-
+ {
+ if (!__make<__unnamed>(number_start, static_cast<size_t>(number_end - number_start)))
+ return first;
+ }
+ first = t;
+ }
break;
}
}
Modified: libcxxabi/trunk/test/test_demangle.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_demangle.cpp?rev=169022&r1=169021&r2=169022&view=diff
==============================================================================
--- libcxxabi/trunk/test/test_demangle.cpp (original)
+++ libcxxabi/trunk/test/test_demangle.cpp Fri Nov 30 12:43:50 2012
@@ -29568,6 +29568,7 @@
{"_ZZN4NIds4NStr14TCStrAggregateINS0_13TCTCStrTraitsINS0_11TCStrTraitsIcNS0_17CDefaultStrParamsEEENS0_14TCStrImp_FixedIS5_Lx256EEEEEE21f_AddFromIteratorUTF8INS0_16CStrIteratorUTF8EEEvRxRKT_ENKSA_ISB_EUlmE0_clEm", "void NIds::NStr::TCStrAggregate<NIds::NStr::TCTCStrTraits<NIds::NStr::TCStrTraits<char, NIds::NStr::CDefaultStrParams>, NIds::NStr::TCStrImp_Fixed<NIds::NStr::TCStrTraits<char, NIds::NStr::CDefaultStrParams>, 256ll> > >::f_AddFromIteratorUTF8<NIds::NStr::CStrIteratorUTF8>(long long&, NIds::NStr::CStrIteratorUTF8 const&)::NIds::NStr::TCStrAggregate<NIds::NStr::TCTCStrTraits<NIds::NStr::TCStrTraits<char, NIds::NStr::CDefaultStrParams>, NIds::NStr::TCStrImp_Fixed<NIds::NStr::TCStrTraits<char, NIds::NStr::CDefaultStrParams>, 256ll> > >::f_AddFromIteratorUTF8<NIds::NStr::CStrIteratorUTF8>::'lambda0'(unsigned long)::operator()(unsigned long) const"},
{"_ZZN4NIds4NStr14TCStrAggregateINS0_13TCTCStrTraitsINS0_11TCStrTraitsIcNS0_17CDefaultStrParamsEEENS0_14TCStrImp_FixedIS5_Lx256EEEEEE21f_AddFromIteratorUTF8INS0_16CStrIteratorUTF8EEEvRxRKT_ENKSA_ISB_EUt0_clEm", "void NIds::NStr::TCStrAggregate<NIds::NStr::TCTCStrTraits<NIds::NStr::TCStrTraits<char, NIds::NStr::CDefaultStrParams>, NIds::NStr::TCStrImp_Fixed<NIds::NStr::TCStrTraits<char, NIds::NStr::CDefaultStrParams>, 256ll> > >::f_AddFromIteratorUTF8<NIds::NStr::CStrIteratorUTF8>(long long&, NIds::NStr::CStrIteratorUTF8 const&)::NIds::NStr::TCStrAggregate<NIds::NStr::TCTCStrTraits<NIds::NStr::TCStrTraits<char, NIds::NStr::CDefaultStrParams>, NIds::NStr::TCStrImp_Fixed<NIds::NStr::TCStrTraits<char, NIds::NStr::CDefaultStrParams>, 256ll> > >::f_AddFromIteratorUTF8<NIds::NStr::CStrIteratorUTF8>::'unnamed0'::operator()(unsigned long) const"},
{"_ZNK3com9markzware2js11cJSArgumentcvRKT_I8cMyClassEEv", "com::markzware::js::cJSArgument::operator cMyClass const &<cMyClass>() const"},
+ {"_ZNKSt3__110__function6__funcIZN4DLCL8DLFutureIP15AnalysenManagerE3setINS_8functionIFS5_vEEEJEEEvT_DpOT0_EUlvE_NS_9allocatorISF_EEFvvEE7__cloneEv", "std::__1::__function::__func<void DLCL::DLFuture<AnalysenManager*>::set<std::__1::function<AnalysenManager* ()> >(std::__1::function<AnalysenManager* ()>)::'lambda'(), std::__1::allocator<void DLCL::DLFuture<AnalysenManager*>::set<std::__1::function<AnalysenManager* ()> >(std::__1::function<AnalysenManager* ()>)::'lambda'()>, void ()>::__clone() const"},
};
const unsigned N = sizeof(cases) / sizeof(cases[0]);
@@ -29602,6 +29603,37 @@
free(buf);
}
+void test2()
+{
+ std::size_t len = 0;
+ char* buf = nullptr;
+ for (unsigned i = 0; i < N; ++i)
+ {
+ int status;
+ char* demang = __cxxabiv1::__cxa_demangle(cases[i][0], buf, &len, &status);
+ if (demang == 0 || std::strcmp(demang, cases[i][1]) != 0)
+ {
+ std::cout << cases[i][0] << " -> " << cases[i][1] << '\n';
+ if (demang)
+ {
+ std::cout << "Got instead: " << demang << '\n';
+ assert(std::strcmp(demang, cases[i][1]) == 0);
+ }
+ else
+ {
+ std::cout << "Got instead: NULL, " << status << '\n';
+ assert(demang != 0);
+ }
+ }
+ else
+ {
+ free(demang);
+ len = 0;
+ }
+ }
+ free(buf);
+}
+
int main()
{
typedef std::chrono::high_resolution_clock Clock;
@@ -29620,7 +29652,6 @@
int status;
len = 0;
char* demang = abi::__cxa_demangle(input.c_str(), 0, &len, &status);
- Clock::time_point t1 = Clock::now();
switch (status)
{
case -3:
More information about the cfe-commits
mailing list