]> granicus.if.org Git - clang/commitdiff
Honor attribute section on static block var decls.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 12 Feb 2009 23:32:54 +0000 (23:32 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 12 Feb 2009 23:32:54 +0000 (23:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64411 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
test/CodeGen/attributes.c

index dad50fcec40fa6fb48ecae373c8804ab62c55b60..a32b78dedb95f37fc780a5d0455f7ea6495daed9 100644 (file)
@@ -126,6 +126,7 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) {
   GV = GenerateStaticBlockVarDecl(D, false, ".",
                                   llvm::GlobalValue::InternalLinkage);
 
+  // FIXME: Merge attribute handling.
   if (const AnnotateAttr *AA = D.getAttr<AnnotateAttr>()) {
     SourceManager &SM = CGM.getContext().getSourceManager();
     llvm::Constant *Ann =
@@ -134,6 +135,9 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) {
     CGM.AddAnnotation(Ann);
   }
 
+  if (const SectionAttr *SA = D.getAttr<SectionAttr>())
+    GV->setSection(SA->getName());
+  
   const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(D.getType());
   const llvm::Type *LPtrTy =
     llvm::PointerType::get(LTy, D.getType().getAddressSpace());
index aa4e3efb1d50ebedae9ae34d50f0d0c3112f425c..171c81081a4ace81c0bdf5c7e7aff37abefefee0 100644 (file)
@@ -11,7 +11,8 @@
 // RUN: grep '@t10().*section "SECT"' %t &&
 // RUN: grep '@t11().*section "SECT"' %t &&
 // RUN: grep '@t12 =.*section "SECT"' %t &&
-// RUN: grep '@t13 =.*section "SECT"' %t
+// RUN: grep '@t13 =.*section "SECT"' %t &&
+// RUN: grep '@t14.x =.*section "SECT"' %t
 
 void t1() __attribute__((noreturn));
 void t1() {}
@@ -41,4 +42,8 @@ void __attribute__((section("SECT"))) t11(void) {}
 
 int t12 __attribute__((section("SECT")));
 struct s0 { int x; };
-struct s0 t13 __attribute__ ((section ("SECT"))) = { 0 };
+struct s0 t13 __attribute__((section("SECT"))) = { 0 };
+
+void t14(void) {
+  static int x __attribute__((section("SECT"))) = 0;
+}