[cfe-commits] MS name mangling improvements
Richard Smith
richard at metafoo.co.uk
Mon Jun 18 13:30:06 PDT 2012
On Mon, Jun 18, 2012 at 2:28 AM, João Matos <ripzonetriton at gmail.com> wrote:
> Attached patch with some improvements to the Microsoft mangling:
>
> - R-value references mangling
> - Back references (done by Timur Iskhodzhanov)
> - nullptr mangling
Comments inline below.
> --- lib/AST/MicrosoftMangle.cpp (revision 158591)
> +++ lib/AST/MicrosoftMangle.cpp (working copy)
> @@ -31,6 +31,9 @@
> MangleContext &Context;
> raw_ostream &Out;
>
> + typedef llvm::DenseMap<const IdentifierInfo*, unsigned> BackRefMap;
> + BackRefMap back_references;
Per the coding conventions, this should be named BackReferences (and
likewise for other variable and field declarations in the patch).
> +
> ASTContext &getASTContext() const { return Context.getASTContext(); }
>
> public:
> @@ -641,7 +644,14 @@
>
> void MicrosoftCXXNameMangler::mangleSourceName(const IdentifierInfo *II) {
> // <source name> ::= <identifier> @
> - Out << II->getName() << '@';
> + BackRefMap::iterator found = back_references.find(II);
> + if (found == back_references.end()) {
> + Out << II->getName() << '@';
> + if (back_references.size() < 10)
> + back_references[II] = back_references.size(); // size++
This will do different things depending on the order in which the
arguments to operator= are evaluated.
> @@ -998,17 +1010,28 @@
> if (Proto->getNumArgs() == 0 && !Proto->isVariadic()) {
> Out << 'X';
> } else {
> + typedef llvm::DenseMap<void*, unsigned> BackRef;
> + BackRef back_refs;
> if (D) {
> // If we got a decl, use the type-as-written to make sure arrays
> // get mangled right. Note that we can't rely on the TSI
> // existing if (for example) the parameter was synthesized.
> for (FunctionDecl::param_const_iterator Parm = D->param_begin(),
> ParmEnd = D->param_end(); Parm != ParmEnd; ++Parm) {
> - if (TypeSourceInfo *typeAsWritten = (*Parm)->getTypeSourceInfo())
> - mangleType(typeAsWritten->getType(),
> - typeAsWritten->getTypeLoc().getSourceRange());
> - else
> - mangleType((*Parm)->getType(), SourceRange());
> + TypeSourceInfo *typeAsWritten = (*Parm)->getTypeSourceInfo();
> + QualType type = typeAsWritten ? typeAsWritten->getType() : (*Parm)->getType();
> + CanQualType canonical = getASTContext().getCanonicalType(type);
> + void *type_ptr = canonical.getAsOpaquePtr();
> + BackRef::iterator found = back_refs.find(type_ptr);
> + if (found == back_refs.end()) {
> + SourceRange SR = typeAsWritten ? typeAsWritten->getTypeLoc().getSourceRange()
> + : (*Parm)->getSourceRange();
> + mangleType(type, SR);
> + if (back_refs.size() < 10 && canonical->getTypeClass() != Type::Builtin)
> + back_refs[type_ptr] = back_refs.size(); // size++
> + } else {
> + Out << found->second;
> + }
It looks like this will include cv-qualifiers on function parameter
types in the mangled name. That can't be right, since they're not part
of the function type. I suspect you should drop the uses of
getTypeSourceInfo() here. (This bug seems to predate your change).
> +++ test/CodeGenCXX/mangle-ms-cpp11.cpp (working copy)
We use 'cxx11' not 'cpp11' in the tests/ area to refer to C++11.
More information about the cfe-commits
mailing list