[PATCH] Sema: Propagate the mangling number into instantiations

David Majnemer david.majnemer at gmail.com
Sun Nov 17 05:58:59 PST 2013


Hi rsmith, doug.gregor, rnk, eli.friedman, cdavis5x,

We would lose track of the mangling number assigned to the original
declaration which would cause us to create manglings that didn't match
the Itanium C++ specification.

e.g. Two static fields with the same name inside of a function template
would receive the same mangling with LLVM fixing up the second field so
they wouldn't collide.  This would create an incompatibility with other
compilers following the Itanium ABI.

I've confirmed that the new mangling is identical to the ones generated
by icc and gcc.

N.B. This was uncovered while working on Microsoft mangler.

[-cxx-abi microsoft] Implement local manglings accurately

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.

Depends on D2198

http://llvm-reviews.chandlerc.com/D2201

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Mangle.h
  include/clang/AST/MangleNumberingContext.h
  include/clang/Sema/Scope.h
  lib/AST/ASTContext.cpp
  lib/AST/ItaniumCXXABI.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/MangleNumberingContext.cpp
  lib/AST/MicrosoftCXXABI.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Parse/ParseStmt.cpp
  lib/Sema/Scope.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/CodeGenCXX/mangle-ms-abi-examples.cpp
  test/CodeGenCXX/mangle-template.cpp
  test/CodeGenCXX/microsoft-abi-static-initializers.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2201.1.patch
Type: text/x-patch
Size: 37658 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131117/c65470a3/attachment.bin>


More information about the cfe-commits mailing list