diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-02-23 00:26:28 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-02-23 00:26:28 +0000 |
commit | 02fb50d54042982bccc04c276ad2342827c8fcd3 (patch) | |
tree | 0f25371b407b04c83b0c0f1ca7afdea34990a5f3 | |
parent | 7728cddd7866fadd07f1191eee40985e3cdbc6bf (diff) |
Remove the hack that avoided mangling static functions in extern C contexts.
Weather we should give C language linkage to functions and variables with
internal linkage probably depends on how much code assumes it. The standard
says they should have no language linkage, but gcc and msvc assign them
C language linkage.
This commit removes the hack that was preventing the mangling on static
functions declare in extern C contexts. It is an experiment to see if we
can implement the rules in the standard.
If it turns out that many users depend on these functions and variables
having C language linkage, we should change isExternC instead and try
to convince the CWG to change the standard.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175937 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/AST/ItaniumMangle.cpp | 9 | ||||
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 8 | ||||
-rw-r--r-- | test/CodeGenCXX/c-linkage.cpp | 8 | ||||
-rw-r--r-- | test/SemaCXX/linkage2.cpp | 8 |
4 files changed, 9 insertions, 24 deletions
diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp index d427b082a4..21c499317f 100644 --- a/lib/AST/ItaniumMangle.cpp +++ b/lib/AST/ItaniumMangle.cpp @@ -385,15 +385,6 @@ bool ItaniumMangleContext::shouldMangleDeclName(const NamedDecl *D) { // C functions are not mangled. if (L == CLanguageLinkage) return false; - - // FIXME: Users assume they know the mangling of static functions - // declared in extern "C" contexts, so we cannot always mangle them. - // As an improvement, maybe we could mangle them only if they are actually - // overloaded. - const DeclContext *DC = FD->getDeclContext(); - if (!DC->isRecord() && - FD->getFirstDeclaration()->getDeclContext()->isExternCContext()) - return false; } // Otherwise, no mangling is done outside C++ mode. diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 20fb7a768b..9bba5f6c78 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -974,14 +974,6 @@ static bool canBeOverloaded(const FunctionDecl &D) { if (D.isMain()) return false; - // FIXME: Users assume they know the mangling of static functions - // declared in extern "C" contexts. For now just disallow overloading these - // functions so that we can avoid mangling them. - const DeclContext *DC = D.getDeclContext(); - if (!DC->isRecord() && - D.getFirstDeclaration()->getDeclContext()->isExternCContext()) - return false; - return true; } diff --git a/test/CodeGenCXX/c-linkage.cpp b/test/CodeGenCXX/c-linkage.cpp index cec9e282f6..f6e64d9e74 100644 --- a/test/CodeGenCXX/c-linkage.cpp +++ b/test/CodeGenCXX/c-linkage.cpp @@ -15,11 +15,13 @@ extern "C" { extern "C" { static void test2_f() { } - // This is not required by the standard, but users assume they know - // the mangling of static functions in extern "C" contexts. - // CHECK: define internal void @test2_f( + // CHECK: define internal void @_Z7test2_fv + static void test2_f(int x) { + } + // CHECK: define internal void @_Z7test2_fi void test2_use() { test2_f(); + test2_f(42); } } diff --git a/test/SemaCXX/linkage2.cpp b/test/SemaCXX/linkage2.cpp index 744741b7ca..2cee581b49 100644 --- a/test/SemaCXX/linkage2.cpp +++ b/test/SemaCXX/linkage2.cpp @@ -12,12 +12,12 @@ namespace test1 { } } -// FIXME: This should be OK. Both test2_f don't have language linkage since they -// have internal linkage. +// This is OK. Both test2_f don't have language linkage since they have +// internal linkage. extern "C" { - static void test2_f() { // expected-note {{previous definition is here}} + static void test2_f() { } - static void test2_f(int x) { // expected-error {{conflicting types for 'test2_f'}} + static void test2_f(int x) { } } |