[PATCH] PR5712: Fix for a bug in pragma redefine_extname implementation.

Aaron Ballman aaron at aaronballman.com
Tue Jun 2 08:39:19 PDT 2015


On Tue, Jun 2, 2015 at 11:31 AM, Andrey Bokhanko
<andreybokhanko at gmail.com> wrote:
> Hi theraven, rsmith,
>
> PR5712: 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.
>
> http://reviews.llvm.org/D10187
>
> Files:
>   lib/Sema/SemaDecl.cpp
>   test/CodeGen/redefine_extname.c
>
> Index: test/CodeGen/redefine_extname.c
> ===================================================================
> --- test/CodeGen/redefine_extname.c
> +++ test/CodeGen/redefine_extname.c
> @@ -3,6 +3,12 @@
>  #pragma redefine_extname fake real
>  #pragma redefine_extname name alias
>
> +struct statvfs64 {
> +  int f;
> +};
> +#pragma redefine_extname statvfs64 statvfs
> +int statvfs64(struct statvfs64 *);
> +
>  extern int fake(void);
>
>  int name;
> @@ -13,3 +19,12 @@
>  // CHECK:   call i32 @real()
>  // Check that this also works with variables names
>  // CHECK:   load i32, i32* @alias
> +
> +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. PR5712, Comment 11.
> +// CHECK:  call i32 @statvfs(%struct.statvfs64* %st)
> +}
> +
> Index: lib/Sema/SemaDecl.cpp
> ===================================================================
> --- lib/Sema/SemaDecl.cpp
> +++ lib/Sema/SemaDecl.cpp
> @@ -14199,14 +14199,20 @@
>                                        SourceLocation AliasNameLoc) {
>    Decl *PrevDecl = LookupSingleName(TUScope, Name, NameLoc,
>                                      LookupOrdinaryName);
> -  AsmLabelAttr *Attr = ::new (Context) AsmLabelAttr(AliasNameLoc, Context,
> -                                                    AliasName->getName(), 0);
> +  AsmLabelAttr *Attr;

I don't think this variable is required, you can create the implicit
attribute directly into where it belongs.

>
> -  if (PrevDecl)
> +  if (PrevDecl) {
> +    Attr = ::new (Context)
> +        AsmLabelAttr(AliasNameLoc, Context, AliasName->getName(), 0);

This should be using AsmLabelAttr::CreateImplicit, as the attribute
was not written explicitly by the user.

>      PrevDecl->addAttr(Attr);
> -  else
> -    (void)ExtnameUndeclaredIdentifiers.insert(
> -      std::pair<IdentifierInfo*,AsmLabelAttr*>(Name, Attr));
> +  }
> +
> +  // There might be additional not yet declared identifiers with Name name.
> +  // PR5172, Comment 11.
> +  Attr = ::new (Context)
> +      AsmLabelAttr(AliasNameLoc, Context, AliasName->getName(), 0);

As should this.

> +  (void)ExtnameUndeclaredIdentifiers.insert(
> +    std::pair<IdentifierInfo*,AsmLabelAttr*>(Name, Attr));

std::make_pair?

>  }
>
>  void Sema::ActOnPragmaWeakID(IdentifierInfo* Name,

~Aaron



More information about the cfe-commits mailing list