[cfe-commits] r66353 - in /cfe/trunk: lib/CodeGen/Mangle.cpp test/CodeGenCXX/mangle.cpp

Douglas Gregor dgregor at apple.com
Tue Mar 10 08:54:31 PDT 2009


On Mar 7, 2009, at 3:57 PM, Anders Carlsson wrote:

> Author: andersca
> Date: Sat Mar  7 17:57:03 2009
> New Revision: 66353
>
> URL: http://llvm.org/viewvc/llvm-project?rev=66353&view=rev
> Log:
> Make mangling work with anonymous tag types. Doug, please review
>
> Modified:
>    cfe/trunk/lib/CodeGen/Mangle.cpp
>    cfe/trunk/test/CodeGenCXX/mangle.cpp
>
> Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=66353&r1=66352&r2=66353&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
> +++ cfe/trunk/lib/CodeGen/Mangle.cpp Sat Mar  7 17:57:03 2009
> @@ -43,6 +43,7 @@
>     void mangleOperatorName(OverloadedOperatorKind OO, unsigned  
> Arity);
>     void mangleCVQualifiers(unsigned Quals);
>     void mangleType(QualType T);
> +    void mangleType(const TypedefType *T);
>     void mangleType(const BuiltinType *T);
>     void mangleType(const FunctionType *T);
>     void mangleBareFunctionType(const FunctionType *T, bool  
> MangleReturnType);
> @@ -329,16 +330,15 @@
> }
>
> void CXXNameMangler::mangleType(QualType T) {
> -  // Only operate on the canonical type!
> -  T = Context.getCanonicalType(T);
> -

This is going to make mangling a bit harder to get right. We really  
want name mangling to work on the canonical types, lest we  
accidentally forget to map part of a type down to a canonical type.

> +void CXXNameMangler::mangleType(const TypedefType *T) {
> +  QualType DeclTy = T->getDecl()->getUnderlyingType();
> +
> +  if (const TagType *TT = dyn_cast<TagType>(DeclTy)) {
> +    // If the tag type is anonymous, use the name of the typedef.
> +    if (!TT->getDecl()->getIdentifier()) {
> +      mangleName(T->getDecl());
> +      return;
> +    }
> +  }
> +
> +  mangleType(DeclTy);
> +}

This isn't go to work in cases where we end up with a TagType for an  
unnamed tag declaration, but never actually see the typedef because,  
e.g., something outside of name-mangling already mapped to the  
canonical type.

I think the best approach here would be to augment the AST for unnamed  
TagDecls, giving them a pointer to the typedef used for their  
mangling. We also might want to use this name for printing types in  
error messages. I think it'll simplify things a bit, and deal with the  
case Eli found.

	- Doug



More information about the cfe-commits mailing list