Page MenuHomePhabricator

[-cxx-abi microsoft] Implement local manglings accurately
ClosedPublic

Authored by majnemer on Mar 4 2014, 4:51 PM.

Details

Summary

The MSVC ABI appears to mangle the lexical scope into the names of
statics. Specifically, a counter is incremented whenever a scope is
entered where things can be declared in such a way that an ambiguity can
arise. For example, a class scope inside of a class scope doesn't do
anything interesting because the nested class cannot collide with
another nested class.

There are problems with this scheme:

  • It is unreliable. The counter is only incremented when a previously never encountered scope is entered. There are cases where this will cause ambiguity amongst declarations that have the same name where one was introduced in a deep scope while the other was introduced right after in the previous lexical scope.
  • It is wasteful. Statements like: {{{{{{{ static int foo = a; }}}}}}} will make the mangling of "foo" larger than it need be because the scope counter has been incremented many times.

Because of these problems, and practical implementation concerns. We
choose not to implement this scheme if the local static or local type
isn't visible. The mangling of these declarations will look very
similar but the numbering will make far more sense, this scheme is
lifted from the Itanium ABI implementation.

Diff Detail

Event Timeline

A few minor nits; otherwise, LGTM (though, as usual, you should really wait for the others to give their LGs).

include/clang/AST/ASTContext.h
368

This should have a doc comment explaining what exactly this is for.

include/clang/AST/MangleNumberingContext.h
39

Is this really necessary?

include/clang/Parse/Parser.h
743–748

This comment needs to be updated.

lib/AST/MicrosoftMangle.cpp
743–744

You should probably update the BNF here, too.

lib/Parse/ParseStmt.cpp
1623–1624

There should be an empty line between these two lines.

rnk accepted this revision.Mar 4 2014, 5:37 PM

lgtm

include/clang/Parse/Parser.h
745

Should update ManagedScope in comments.

748

We discussed in person that two adjacent boolean optional arguments are undesirable, but never actually reached agreement on what should be done. Just pick something and go with it. :)

majnemer closed this revision.Mar 5 2014, 1:04 AM