[cfe-commits] r120650 - in /cfe/trunk: include/clang/Basic/Attr.td include/clang/Sema/AttributeList.h lib/CodeGen/CodeGenModule.cpp lib/Sema/AttributeList.cpp lib/Sema/SemaDeclAttr.cpp test/CodeGen/no-common.c

Douglas Gregor dgregor at apple.com
Thu Dec 2 07:38:49 PST 2010


On Dec 1, 2010, at 6:45 PM, Eric Christopher wrote:

> Author: echristo
> Date: Wed Dec  1 20:45:55 2010
> New Revision: 120650
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=120650&view=rev
> Log:
> Add support for the common and nocommon attributes.
> 
> rdar://8560647
> 
> Modified:
>    cfe/trunk/include/clang/Basic/Attr.td
>    cfe/trunk/include/clang/Sema/AttributeList.h
>    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>    cfe/trunk/lib/Sema/AttributeList.cpp
>    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>    cfe/trunk/test/CodeGen/no-common.c
> 
> Modified: cfe/trunk/include/clang/Basic/Attr.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=120650&r1=120649&r2=120650&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/Attr.td (original)
> +++ cfe/trunk/include/clang/Basic/Attr.td Wed Dec  1 20:45:55 2010
> @@ -161,6 +161,10 @@
>   let Args = [FunctionArgument<"FunctionDecl">];
> }
> 
> +def Common : Attr {
> +  let Spellings = ["common"];
> +}
> +
> def Const : Attr {
>   let Spellings = ["const"];
> }
> @@ -274,6 +278,10 @@
>   let Spellings = ["naked"];
> }
> 
> +def NoCommon : Attr {
> +  let Spellings = ["nocommon"];
> +}
> +
> def NoDebug : Attr {
>   let Spellings = ["nodebug"];
> }
> 
> Modified: cfe/trunk/include/clang/Sema/AttributeList.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/AttributeList.h?rev=120650&r1=120649&r2=120650&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Sema/AttributeList.h (original)
> +++ cfe/trunk/include/clang/Sema/AttributeList.h Wed Dec  1 20:45:55 2010
> @@ -91,6 +91,7 @@
>     AT_carries_dependency,
>     AT_cdecl,
>     AT_cleanup,
> +    AT_common,
>     AT_const,
>     AT_constant,
>     AT_constructor,
> @@ -117,6 +118,7 @@
>     AT_nodebug,
>     AT_noinline,
>     AT_no_instrument_function,
> +    AT_nocommon,
>     AT_nonnull,
>     AT_noreturn,
>     AT_nothrow,
> 
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=120650&r1=120649&r2=120650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Dec  1 20:45:55 2010
> @@ -1214,7 +1214,9 @@
>     // FIXME: It seems like we can provide more specific linkage here
>     // (LinkOnceODR, WeakODR).
>     return llvm::GlobalVariable::WeakAnyLinkage;
> -  else if (!getLangOptions().CPlusPlus && !CodeGenOpts.NoCommon &&
> +  else if (!getLangOptions().CPlusPlus && 
> +           ((!CodeGenOpts.NoCommon && !D->getAttr<NoCommonAttr>()) ||
> +             D->getAttr<CommonAttr>()) &&
>            !D->hasExternalStorage() && !D->getInit() &&
>            !D->getAttr<SectionAttr>() && !D->isThreadSpecified()) {
>     // Thread local vars aren't considered common linkage.
> 
> Modified: cfe/trunk/lib/Sema/AttributeList.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AttributeList.cpp?rev=120650&r1=120649&r2=120650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/AttributeList.cpp (original)
> +++ cfe/trunk/lib/Sema/AttributeList.cpp Wed Dec  1 20:45:55 2010
> @@ -130,5 +130,7 @@
>     .Case("global", AT_global)
>     .Case("host", AT_host)
>     .Case("shared", AT_shared)
> +    .Case("common", AT_common)
> +    .Case("nocommon", AT_nocommon)
>     .Default(UnknownAttribute);
> }
> 
> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=120650&r1=120649&r2=120650&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Dec  1 20:45:55 2010
> @@ -743,6 +743,16 @@
>   d->addAttr(::new (S.Context) MayAliasAttr(Attr.getLoc(), S.Context));
> }
> 
> +static void HandleNoCommonAttr(Decl *d, const AttributeList &Attr, Sema &S) {
> +  assert(Attr.isInvalid() == false);
> +  d->addAttr(::new (S.Context) NoCommonAttr(Attr.getLoc(), S.Context));
> +}
> +
> +static void HandleCommonAttr(Decl *d, const AttributeList &Attr, Sema &S) {
> +  assert(Attr.isInvalid() == false);
> +  d->addAttr(::new (S.Context) CommonAttr(Attr.getLoc(), S.Context));
> +}

I double that the common and nocommon attributes can go on any declaration... perhaps you want to check for linkage?

	- Doug





More information about the cfe-commits mailing list