From c024327365be5c472f3a1afd222161f6aa4ee2d6 Mon Sep 17 00:00:00 2001 From: Alexander Musman Date: Wed, 10 Jun 2015 11:20:26 +0000 Subject: [PATCH] PR5172: Fix for a bug in pragma redefine_extname implementation: it doesn't work correctly when a structure is declared before pragma and then a function with the same name declared after pragma. Patch by Andrey Bokhanko Differential Revision: http://reviews.llvm.org/D10187 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239466 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 24 +++++++++++++++--------- test/CodeGenCXX/redefine_extname.cpp | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 test/CodeGenCXX/redefine_extname.cpp diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 89f4b3a0c1..047958e2fc 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -14197,16 +14197,22 @@ void Sema::ActOnPragmaRedefineExtname(IdentifierInfo* Name, SourceLocation PragmaLoc, SourceLocation NameLoc, SourceLocation AliasNameLoc) { - Decl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc, - LookupOrdinaryName); - AsmLabelAttr *Attr = ::new (Context) AsmLabelAttr(AliasNameLoc, Context, - AliasName->getName(), 0); - - if (PrevDecl) + NamedDecl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc, + LookupOrdinaryName); + AsmLabelAttr *Attr = + AsmLabelAttr::CreateImplicit(Context, AliasName->getName(), AliasNameLoc); + + // If a declaration that: + // 1) declares a function or a variable + // 2) has external linkage + // already exists, add a label attribute to it. + if (PrevDecl && + (isa(PrevDecl) || isa(PrevDecl)) && + PrevDecl->hasExternalFormalLinkage()) PrevDecl->addAttr(Attr); - else - (void)ExtnameUndeclaredIdentifiers.insert( - std::pair(Name, Attr)); + // Otherwise, add a label atttibute to ExtnameUndeclaredIdentifiers. + else + (void)ExtnameUndeclaredIdentifiers.insert(std::make_pair(Name, Attr)); } void Sema::ActOnPragmaWeakID(IdentifierInfo* Name, diff --git a/test/CodeGenCXX/redefine_extname.cpp b/test/CodeGenCXX/redefine_extname.cpp new file mode 100644 index 0000000000..2b6b703a1b --- /dev/null +++ b/test/CodeGenCXX/redefine_extname.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -triple=i386-pc-solaris2.11 -w -emit-llvm %s -o - | FileCheck %s + +extern "C" { + struct statvfs64 { + int f; + }; +#pragma redefine_extname statvfs64 statvfs + int statvfs64(struct statvfs64 *); +} + +void foo() { + struct statvfs64 st; + statvfs64(&st); +// Check that even if there is a structure with redefined name before the +// pragma, subsequent function name redefined properly. PR5172, Comment 11. +// CHECK: call i32 @statvfs(%struct.statvfs64* %st) +} + -- 2.40.0