r216259 - MS ABI: Don't use the Itanium scheme for numbering lambdas
David Majnemer
david.majnemer at gmail.com
Thu Aug 21 21:22:51 PDT 2014
Author: majnemer
Date: Thu Aug 21 23:22:50 2014
New Revision: 216259
URL: http://llvm.org/viewvc/llvm-project?rev=216259&view=rev
Log:
MS ABI: Don't use the Itanium scheme for numbering lambdas
The Itanium ABI will give out the same mangling number for two different
lambdas if their call operators have different types. The MS ABI cannot
do the same because it does not mangle the return type into it's
lambdas.
This fixes PR20719.
Added:
cfe/trunk/test/CodeGenCXX/pr20719.cpp
Removed:
cfe/trunk/lib/AST/MangleNumberingContext.cpp
Modified:
cfe/trunk/include/clang/AST/MangleNumberingContext.h
cfe/trunk/lib/AST/CMakeLists.txt
cfe/trunk/lib/AST/ItaniumCXXABI.cpp
cfe/trunk/lib/AST/MicrosoftCXXABI.cpp
Modified: cfe/trunk/include/clang/AST/MangleNumberingContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/MangleNumberingContext.h?rev=216259&r1=216258&r2=216259&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/MangleNumberingContext.h (original)
+++ cfe/trunk/include/clang/AST/MangleNumberingContext.h Thu Aug 21 23:22:50 2014
@@ -30,23 +30,20 @@ class VarDecl;
/// \brief Keeps track of the mangled names of lambda expressions and block
/// literals within a particular context.
-class MangleNumberingContext
- : public RefCountedBase<MangleNumberingContext> {
- llvm::DenseMap<const Type *, unsigned> ManglingNumbers;
-
+class MangleNumberingContext : public RefCountedBase<MangleNumberingContext> {
public:
virtual ~MangleNumberingContext() {}
/// \brief Retrieve the mangling number of a new lambda expression with the
/// given call operator within this context.
- unsigned getManglingNumber(const CXXMethodDecl *CallOperator);
+ virtual unsigned getManglingNumber(const CXXMethodDecl *CallOperator) = 0;
/// \brief Retrieve the mangling number of a new block literal within this
/// context.
- unsigned getManglingNumber(const BlockDecl *BD);
+ virtual unsigned getManglingNumber(const BlockDecl *BD) = 0;
/// Static locals are numbered by source order.
- unsigned getStaticLocalNumber(const VarDecl *VD);
+ virtual unsigned getStaticLocalNumber(const VarDecl *VD) = 0;
/// \brief Retrieve the mangling number of a static local variable within
/// this context.
@@ -58,6 +55,6 @@ public:
virtual unsigned getManglingNumber(const TagDecl *TD,
unsigned MSLocalManglingNumber) = 0;
};
-
+
} // end namespace clang
#endif
Modified: cfe/trunk/lib/AST/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CMakeLists.txt?rev=216259&r1=216258&r2=216259&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CMakeLists.txt (original)
+++ cfe/trunk/lib/AST/CMakeLists.txt Thu Aug 21 23:22:50 2014
@@ -35,7 +35,6 @@ add_clang_library(clangAST
ItaniumCXXABI.cpp
ItaniumMangle.cpp
Mangle.cpp
- MangleNumberingContext.cpp
MicrosoftCXXABI.cpp
MicrosoftMangle.cpp
NestedNameSpecifier.cpp
Modified: cfe/trunk/lib/AST/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumCXXABI.cpp?rev=216259&r1=216258&r2=216259&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumCXXABI.cpp Thu Aug 21 23:22:50 2014
@@ -32,10 +32,32 @@ namespace {
/// \brief Keeps track of the mangled names of lambda expressions and block
/// literals within a particular context.
class ItaniumNumberingContext : public MangleNumberingContext {
- llvm::DenseMap<IdentifierInfo*, unsigned> VarManglingNumbers;
- llvm::DenseMap<IdentifierInfo*, unsigned> TagManglingNumbers;
+ llvm::DenseMap<const Type *, unsigned> ManglingNumbers;
+ llvm::DenseMap<IdentifierInfo *, unsigned> VarManglingNumbers;
+ llvm::DenseMap<IdentifierInfo *, unsigned> TagManglingNumbers;
public:
+ unsigned getManglingNumber(const CXXMethodDecl *CallOperator) override {
+ const FunctionProtoType *Proto =
+ CallOperator->getType()->getAs<FunctionProtoType>();
+ ASTContext &Context = CallOperator->getASTContext();
+
+ QualType Key =
+ Context.getFunctionType(Context.VoidTy, Proto->getParamTypes(),
+ FunctionProtoType::ExtProtoInfo());
+ Key = Context.getCanonicalType(Key);
+ return ++ManglingNumbers[Key->castAs<FunctionProtoType>()];
+ }
+
+ unsigned getManglingNumber(const BlockDecl *BD) {
+ const Type *Ty = nullptr;
+ return ++ManglingNumbers[Ty];
+ }
+
+ unsigned getStaticLocalNumber(const VarDecl *VD) override {
+ return 0;
+ }
+
/// Variable decls are numbered by identifier.
unsigned getManglingNumber(const VarDecl *VD, unsigned) override {
return ++VarManglingNumbers[VD->getIdentifier()];
Removed: cfe/trunk/lib/AST/MangleNumberingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MangleNumberingContext.cpp?rev=216258&view=auto
==============================================================================
--- cfe/trunk/lib/AST/MangleNumberingContext.cpp (original)
+++ cfe/trunk/lib/AST/MangleNumberingContext.cpp (removed)
@@ -1,45 +0,0 @@
-//===--- MangleNumberingContext.cpp - Context for mangling numbers --------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the LambdaMangleContext class, which keeps track of
-// the Itanium C++ ABI mangling numbers for lambda expressions.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/AST/MangleNumberingContext.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/DeclCXX.h"
-
-using namespace clang;
-
-unsigned
-MangleNumberingContext::getManglingNumber(const CXXMethodDecl *CallOperator) {
- const FunctionProtoType *Proto
- = CallOperator->getType()->getAs<FunctionProtoType>();
- ASTContext &Context = CallOperator->getASTContext();
-
- QualType Key = Context.getFunctionType(Context.VoidTy, Proto->getParamTypes(),
- FunctionProtoType::ExtProtoInfo());
- Key = Context.getCanonicalType(Key);
- return ++ManglingNumbers[Key->castAs<FunctionProtoType>()];
-}
-
-unsigned
-MangleNumberingContext::getManglingNumber(const BlockDecl *BD) {
- // FIXME: Compute a BlockPointerType? Not obvious how.
- const Type *Ty = nullptr;
- return ++ManglingNumbers[Ty];
-}
-
-unsigned
-MangleNumberingContext::getStaticLocalNumber(const VarDecl *VD) {
- // FIXME: Compute a BlockPointerType? Not obvious how.
- const Type *Ty = nullptr;
- return ++ManglingNumbers[Ty];
-}
Modified: cfe/trunk/lib/AST/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftCXXABI.cpp?rev=216259&r1=216258&r2=216259&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftCXXABI.cpp Thu Aug 21 23:22:50 2014
@@ -28,7 +28,28 @@ namespace {
/// \brief Numbers things which need to correspond across multiple TUs.
/// Typically these are things like static locals, lambdas, or blocks.
class MicrosoftNumberingContext : public MangleNumberingContext {
+ llvm::DenseMap<const Type *, unsigned> ManglingNumbers;
+ unsigned LambdaManglingNumber;
+ unsigned StaticLocalNumber;
+
public:
+ MicrosoftNumberingContext()
+ : MangleNumberingContext(), LambdaManglingNumber(0),
+ StaticLocalNumber(0) {}
+
+ unsigned getManglingNumber(const CXXMethodDecl *CallOperator) override {
+ return ++LambdaManglingNumber;
+ }
+
+ unsigned getManglingNumber(const BlockDecl *BD) {
+ const Type *Ty = nullptr;
+ return ++ManglingNumbers[Ty];
+ }
+
+ unsigned getStaticLocalNumber(const VarDecl *VD) override {
+ return ++StaticLocalNumber;
+ }
+
unsigned getManglingNumber(const VarDecl *VD,
unsigned MSLocalManglingNumber) override {
return MSLocalManglingNumber;
Added: cfe/trunk/test/CodeGenCXX/pr20719.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/pr20719.cpp?rev=216259&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/pr20719.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/pr20719.cpp Thu Aug 21 23:22:50 2014
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++11 -o - %s | FileCheck %s
+
+// Make sure that we emit H's constructor twice: once with the first lambda
+// inside of 'lep' and again with the second lambda inside of 'lep'.
+// CHECK-DAG: @"\01??0?$H at V<lambda_1>@??$lep at X@@YAXXZ@@@QAE at XZ"
+// CHECK-DAG: @"\01??0?$H at V<lambda_2>@??$lep at X@@YAXXZ@@@QAE at XZ"
+
+template <typename>
+struct H {
+ H() {}
+};
+
+template <typename Fx>
+int K_void(const Fx &) {
+ H<Fx> callee;
+ return 0;
+}
+template <typename Fx>
+int K_int(const Fx &) {
+ H<Fx> callee;
+ return 0;
+}
+
+struct pair {
+ pair(int, int);
+};
+
+struct E1;
+
+template <typename>
+void lep() {
+ pair x(K_void([] {}), K_int([] {}));
+}
+
+auto z = lep<void>;
More information about the cfe-commits
mailing list