[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
Eric Christopher
echristo at apple.com
Wed Dec 1 18:45:55 PST 2010
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));
+}
+
static void HandleNoReturnAttr(Decl *d, const AttributeList &Attr, Sema &S) {
/* Diagnostics (if any) was emitted by Sema::ProcessFnAttr(). */
assert(Attr.isInvalid() == false);
@@ -2474,6 +2484,7 @@
case AttributeList::AT_base_check: HandleBaseCheckAttr (D, Attr, S); break;
case AttributeList::AT_carries_dependency:
HandleDependencyAttr (D, Attr, S); break;
+ case AttributeList::AT_common: HandleCommonAttr (D, Attr, S); break;
case AttributeList::AT_constant: HandleConstantAttr (D, Attr, S); break;
case AttributeList::AT_constructor: HandleConstructorAttr (D, Attr, S); break;
case AttributeList::AT_deprecated: HandleDeprecatedAttr (D, Attr, S); break;
@@ -2492,6 +2503,7 @@
case AttributeList::AT_mode: HandleModeAttr (D, Attr, S); break;
case AttributeList::AT_malloc: HandleMallocAttr (D, Attr, S); break;
case AttributeList::AT_may_alias: HandleMayAliasAttr (D, Attr, S); break;
+ case AttributeList::AT_nocommon: HandleNoCommonAttr (D, Attr, S); break;
case AttributeList::AT_nonnull: HandleNonNullAttr (D, Attr, S); break;
case AttributeList::AT_ownership_returns:
case AttributeList::AT_ownership_takes:
Modified: cfe/trunk/test/CodeGen/no-common.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/no-common.c?rev=120650&r1=120649&r2=120650&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/no-common.c (original)
+++ cfe/trunk/test/CodeGen/no-common.c Wed Dec 1 20:45:55 2010
@@ -4,3 +4,12 @@
// CHECK-DEFAULT: @x = common global
// CHECK-NOCOMMON: @x = global
int x;
+
+// CHECK-DEFAULT: @ABC = global
+// CHECK-NOCOMMON: @ABC = global
+typedef void* (*fn_t)(long a, long b, char *f, int c);
+fn_t ABC __attribute__ ((nocommon));
+
+// CHECK-DEFAULT: @y = common global
+// CHECK-NOCOMMON: @y = common global
+int y __attribute__((common));
\ No newline at end of file
More information about the cfe-commits
mailing list