From 747836e5c79b5e12fe9cfb9b724dc4edeb115419 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 14 Feb 2013 03:31:26 +0000 Subject: [PATCH] Partially revert r175117 so that we don't break assumptions about how static functions in extern "C" contexts are mangled. Should fix the bootstrap. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175132 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ItaniumMangle.cpp | 9 +++++++++ lib/Sema/SemaOverload.cpp | 8 ++++++++ test/CodeGenCXX/c-linkage.cpp | 8 +++----- test/SemaCXX/linkage2.cpp | 8 ++++---- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp index e9a3b03483..1f95a2fee0 100644 --- a/lib/AST/ItaniumMangle.cpp +++ b/lib/AST/ItaniumMangle.cpp @@ -381,6 +381,15 @@ bool ItaniumMangleContext::shouldMangleDeclName(const NamedDecl *D) { // mangling. if (!FD->getDeclName().isIdentifier() || L == CXXLanguageLinkage) return true; + + // 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 9bba5f6c78..20fb7a768b 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -974,6 +974,14 @@ 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 a0a496d09e..c31ad43860 100644 --- a/test/CodeGenCXX/c-linkage.cpp +++ b/test/CodeGenCXX/c-linkage.cpp @@ -15,12 +15,10 @@ extern "C" { extern "C" { static void test2_f() { } - // CHECK: define internal void @_Z7test2_fv - static void test2_f(int x) { - } - // CHECK: define internal void @_Z7test2_fi + // 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( void test2_use() { test2_f(); - test2_f(42); } } diff --git a/test/SemaCXX/linkage2.cpp b/test/SemaCXX/linkage2.cpp index 2cee581b49..744741b7ca 100644 --- a/test/SemaCXX/linkage2.cpp +++ b/test/SemaCXX/linkage2.cpp @@ -12,12 +12,12 @@ namespace test1 { } } -// This is OK. Both test2_f don't have language linkage since they have -// internal linkage. +// FIXME: This should be OK. Both test2_f don't have language linkage since they +// have internal linkage. extern "C" { - static void test2_f() { + static void test2_f() { // expected-note {{previous definition is here}} } - static void test2_f(int x) { + static void test2_f(int x) { // expected-error {{conflicting types for 'test2_f'}} } } -- 2.40.0