MS ABI: Implement the MSVC 2015 scheme for scope disambiguation
authorDavid Majnemer <david.majnemer@gmail.com>
Thu, 19 Mar 2015 21:54:30 +0000 (21:54 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Thu, 19 Mar 2015 21:54:30 +0000 (21:54 +0000)
commita7f8c46439ea05c6e64ba9c6f25d3261521a05d4
tree0a90f468c7c839b9d72fe2ad8502cc0fb66cecbb
parent0a93e2db9c14fb7da613ecccf5a82cab8402a9e5
MS ABI: Implement the MSVC 2015 scheme for scope disambiguation

consider C++ that looks like:
  inline int &f(bool b) {
    if (b) {
      static int i;
      return i;
    }
    static int i;
    return i;
  }

Both 'i' variables must have distinct (and stable) names for linkage
purposes.  The MSVC 2013 ABI would number the variables using a count of
the number of scopes that have been created.  However, the final 'i'
returns to a scope that has already been created leading to a mangling
collision.

MSVC 2015 fixes this by giving the second 'i' the name it would have if
it were declared before the 'if'.  However, this results in ABI breakage
because the mangled name, in cases where there was no ambiguity, would
now be different.

We implement the new behavior and only enable it if we are targeting the
MSVC 2015 ABI, otherwise the old behavior will be used.

This fixes PR18131.

llvm-svn: 232766
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Scope.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParseStmt.cpp
clang/lib/Sema/Scope.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGenCXX/mangle-ms-abi-examples.cpp
clang/test/CodeGenCXX/mangle-ms-cxx11.cpp
clang/test/CodeGenCXX/mangle-ms-cxx14.cpp