[cfe-dev] Bug in C++ ABI mangling ?

Dmitri Rubinstein dmitri.rubinstein at googlemail.com
Fri Dec 2 15:33:37 PST 2011


While experimenting with the address_space attribute in clang 2.9 I got 
a following error message:

clang: 
/home/rubinste/proj_de3/llvm-svn/tools/clang/lib/AST/ItaniumMangle.cpp:2585: 
void<unnamed>::CXXNameMangler::addSubstitution(uintptr_t): Assertion 
`!Substitutions.count(Ptr) && "Substitution already exists!"' failed.

You can reproduce it with this C++ code snippet:

struct OpaqueType;
typedef OpaqueType __attribute__((address_space(100))) * OpaqueTypePtr;

static inline void check(OpaqueTypePtr)
{
}

After some debugging I detected a problem: addSubstitution only checks 
that qualified type does not have CVR qualifier, but there is no check 
for address space qualifier. After adding the check for address space 
qualifier problem disappeared:

void CXXNameMangler::addSubstitution(QualType T) {
   if (!T.getCVRQualifiers() && !T.getQualifiers().hasAddressSpace()) {
     if (const RecordType *RT = T->getAs<RecordType>()) {
       addSubstitution(RT->getDecl());
       return;
     }
   }

   uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
   addSubstitution(TypePtr);
}

The problem also disappear when I put a check function into extern "C" { 
  ... }, thus deactivating C++ name mangling.

Is this a bug, or is the address_space attribute generally not allowed 
in C++ code ?

Greetings

Dmitri Rubinstein



More information about the cfe-dev mailing list