diff options
author | Anders Carlsson <andersca@mac.com> | 2009-04-02 05:55:18 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-04-02 05:55:18 +0000 |
commit | 91e20dd8bf1bc8980ee93839383d2bd170bce050 (patch) | |
tree | 0ccbc60a36d0d01f663750af628a7a5556609553 | |
parent | 7db0a94675a0d5f33120e39144c3827d8bc8994f (diff) |
Emit code for linkage specifications.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68300 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 22 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.h | 1 | ||||
-rw-r--r-- | test/CodeGenCXX/mangle.cpp | 15 |
3 files changed, 27 insertions, 11 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 44a045ef8a..fa475ced6e 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1236,12 +1236,25 @@ void CodeGenModule::EmitObjCPropertyImplementations(const } } +/// EmitNamespace - Emit all declarations in a namespace. void CodeGenModule::EmitNamespace(const NamespaceDecl *ND) { for (RecordDecl::decl_iterator I = ND->decls_begin(), E = ND->decls_end(); I != E; ++I) EmitTopLevelDecl(*I); } +// EmitLinkageSpec - Emit all declarations in a linkage spec. +void CodeGenModule::EmitLinkageSpec(const LinkageSpecDecl *LSD) { + if (LSD->getLanguage() != LinkageSpecDecl::lang_c) { + ErrorUnsupported(LSD, "linkage spec"); + return; + } + + for (RecordDecl::decl_iterator I = LSD->decls_begin(), E = LSD->decls_end(); + I != E; ++I) + EmitTopLevelDecl(*I); +} + /// EmitTopLevelDecl - Emit code for a single top level declaration. void CodeGenModule::EmitTopLevelDecl(Decl *D) { // If an error has occurred, stop code generation, but continue @@ -1300,14 +1313,9 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { // compatibility-alias is a directive and has no code gen. break; - case Decl::LinkageSpec: { - LinkageSpecDecl *LSD = cast<LinkageSpecDecl>(D); - if (LSD->getLanguage() == LinkageSpecDecl::lang_cxx) - ErrorUnsupported(LSD, "linkage spec"); - // FIXME: implement C++ linkage, C linkage works mostly by C - // language reuse already. + case Decl::LinkageSpec: + EmitLinkageSpec(cast<LinkageSpecDecl>(D)); break; - } case Decl::FileScopeAsm: { FileScopeAsmDecl *AD = cast<FileScopeAsmDecl>(D); diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index c0dbbf8267..8661d23caf 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -328,6 +328,7 @@ private: void EmitAliasDefinition(const ValueDecl *D); void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D); void EmitNamespace(const NamespaceDecl *D); + void EmitLinkageSpec(const LinkageSpecDecl *D); // FIXME: Hardcoding priority here is gross. void AddGlobalCtor(llvm::Function * Ctor, int Priority=65535); diff --git a/test/CodeGenCXX/mangle.cpp b/test/CodeGenCXX/mangle.cpp index 0a76dddaff..64a3b05cfa 100644 --- a/test/CodeGenCXX/mangle.cpp +++ b/test/CodeGenCXX/mangle.cpp @@ -20,15 +20,22 @@ void f(e) { } typedef union { int a; } u; void f(u) { } -// RUN: grep _Z1f1x %t | count 1 +// RUN: grep _Z1f1x %t | count 1 && typedef struct { int a; } x,y; void f(y) { } -// RUN: grep _Z1fv %t | count 1 +// RUN: grep _Z1fv %t | count 1 && void f() { } -// RUN: grep _ZN1N1fEv %t | count 1 +// RUN: grep _ZN1N1fEv %t | count 1 && namespace N { void f() { } } -// RUN: grep _ZN1N1N1fEv %t | count 1 +// RUN: grep _ZN1N1N1fEv %t | count 1 && namespace N { namespace N { void f() { } } } + +// RUN: grep unmangled_function %t | count 1 && +extern "C" { namespace N { void unmangled_function() { } } } + +// RUN: grep unmangled_variable %t | count 1 +extern "C" { namespace N { int unmangled_variable; } } + |