[libc++abi] demangle fails to handle SSE2 types

Hi,

I am not sure whether it is fine to discuss libc++abi here but since libc++ is welcome a subject, I boldly extrapolated…

So, abi::__cxa_demangle from libc++abi trunk fails to demangle SSE2 types such as __m128. This is demonstrated by the following snippet:

//*********************************************************************************
#include <iostream>
#include <cxxabi.h>
#include <immintrin.h>

template <class T>
void pretty_print(T const &o) {
  char const *mangled = typeid(o).name();
  int status;
  char *demangled = abi::__cxa_demangle(mangled, 0, 0, &status);
  std::cout << "Mangled: " << mangled << "\n";
  if (status) {
    std::cout << "Demangling failed with status " << status << "\n";
  }
  else {
    std::cout << "Demangled: " << demangled << "\n";
  }
  std::cout << std::endl;
}

int main() {
  double x0;
  __m128 x1;
  __m128d x2;
  pretty_print(x0);
  pretty_print(x1);
  pretty_print(x2);
}
//************************************************************************************

which prints

Mangled: d
Demangled: double

Mangled: Dv4_f
Demangling failed with status -2

Mangled: Dv2_d
Demangling failed with status -2

Best wishes,

Luc Bourhis

Hi,

I am not sure whether it is fine to discuss libc++abi here but since libc++ is welcome a subject, I boldly extrapolated…

To boldly discuss where no discussion has gone before... :slight_smile:

So, abi::__cxa_demangle from libc++abi trunk fails to demangle SSE2 types such as __m128. This is demonstrated by the following snippet:

//*********************************************************************************
#include <iostream>
#include <cxxabi.h>
#include <immintrin.h>

template <class T>
void pretty_print(T const &o) {
char const *mangled = typeid(o).name();
int status;
char *demangled = abi::__cxa_demangle(mangled, 0, 0, &status);
std::cout << "Mangled: " << mangled << "\n";
if (status) {
   std::cout << "Demangling failed with status " << status << "\n";
}
else {
   std::cout << "Demangled: " << demangled << "\n";
}
std::cout << std::endl;
}

int main() {
double x0;
__m128 x1;
__m128d x2;
pretty_print(x0);
pretty_print(x1);
pretty_print(x2);
}
//************************************************************************************

which prints

Mangled: d
Demangled: double

Mangled: Dv4_f
Demangling failed with status -2

Mangled: Dv2_d
Demangling failed with status -2

Currently libc++abi mangling is following the specification here:

http://sourcery.mentor.com/public/cxx-abi/abi.html#mangling

The section you should be interested in is: <builtin-type>. And this section currently lacks Dv4_f and Dv2_d. It does include a mangling for vendor extended types, and it is a shame that the ABI hasn't been followed for these types (prefix with 'u'), but oh well.

It shouldn't be hard to modify the demangler to include these types. If you'll tell me what string you would like to see these symbols demangle to, I'll put it on my to-do list. You should assume I know absolutely nothing about SSE2 types in your table of mappings. For example I do not know the significance of the 4 and 2 in these mangled names, nor what other values they may take (I could guess, but I don't want to).

Howard

It does include a mangling for vendor extended types, and it is a shame that the ABI hasn't been followed for these types (prefix with 'u'), but oh well.

For the record, g++ follows that ABI. The demangling is unfortunately not symmetric, at least for g++ 4.6:

Type: __m64
Mangled: U8__vectori
Demangled: int __vector

Type: __m128
Mangled: U8__vectorf
Demangled: float __vector

Type: __m128d
Mangled: U8__vectord
Demangled: double __vector

Type: __m128i
Mangled: U8__vectorx
Demangled: long long __vector

I mention that because it can become annoying in the context of C++ programs generating C++ code (an exercise I indulge into on a regular basis): it would be nice if clang/libc++abi keeps it symmetric.

If you'll tell me what string you would like to see these symbols demangle to, I'll put it on my to-do list.

Thanks! Here you are:

Type: __m64
Mangled: Dv1_x

Type: __m128
Mangled: Dv4_f

Type: __m128d
Mangled: Dv2_d

Type: __m128i
Mangled: Dv2_x

Type: __m256
Mangled: Dv8_f

Type: __m256d
Mangled: Dv4_d

Type: __m256i
Mangled: Dv4_x

The last 3 types are actually AVX types, a technology only available on Sandy Bridge platforms, and I had to run clang on a Linux machine because I don't have access to a Mac with those processors, but it should not matter as far as you are concerned.

Best wishes,

Luc Bourhis

AFAIK, you don't have to have a sandy bridge machine to compile AVX code.

Just tell clang to enable AVX extension:

clang++ -mavx -S vec.cpp

-- Jean-Daniel

It does include a mangling for vendor extended types, and it is a shame that the ABI hasn't been followed for these types (prefix with 'u'), but oh well.

For the record, g++ follows that ABI. The demangling is unfortunately not symmetric, at least for g++ 4.6:

Type: __m64
Mangled: U8__vectori
Demangled: int __vector

Type: __m128
Mangled: U8__vectorf
Demangled: float __vector

Type: __m128d
Mangled: U8__vectord
Demangled: double __vector

Type: __m128i
Mangled: U8__vectorx
Demangled: long long __vector

Ironically libc++abi can demangle these.

I mention that because it can become annoying in the context of C++ programs generating C++ code (an exercise I indulge into on a regular basis): it would be nice if clang/libc++abi keeps it symmetric.

If you'll tell me what string you would like to see these symbols demangle to, I'll put it on my to-do list.

Thanks! Here you are:

Type: __m64
Mangled: Dv1_x

Type: __m128
Mangled: Dv4_f

Type: __m128d
Mangled: Dv2_d

Type: __m128i
Mangled: Dv2_x

Type: __m256
Mangled: Dv8_f

Type: __m256d
Mangled: Dv4_d

Type: __m256i
Mangled: Dv4_x

The last 3 types are actually AVX types, a technology only available on Sandy Bridge platforms, and I had to run clang on a Linux machine because I don't have access to a Mac with those processors, but it should not matter as far as you are concerned.

Do you wish the demangled strings to be the same as the type name? Or do you wish to follow the g++ 4.6 convention? My recommendation is to have the demangled name be the same as what you would write in source code, which appears to be what you have labeled "Type:".

Howard

Yes, that is exactly what I wish, as I tried to explain in my comments about gcc’s behaviour. I indeed would like “Mangled” to be demangled into “Type”.

Luc Bourhis