eandrews updated this revision to Diff 111064. eandrews added a comment. As per review comments, removed extra RUNS in lit test.
https://reviews.llvm.org/D36487 Files: lib/CodeGen/CodeGenModule.cpp test/CodeGenCXX/extern-section-attribute.cpp Index: test/CodeGenCXX/extern-section-attribute.cpp =================================================================== --- /dev/null +++ test/CodeGenCXX/extern-section-attribute.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=x86_64-pc-linux-gnu | FileCheck %s + +extern int aa __attribute__((section(".sdata"))); +// CHECK-DAG: @aa = external global i32, section ".sdata", align 4 + +extern int bb __attribute__((section(".sdata"))) = 1; +// CHECK-DAG: @bb = global i32 1, section ".sdata", align 4 + +int foo() { + return aa + bb; +} Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -2430,6 +2430,12 @@ EmitGlobalVarDefinition(D); } + // Emit section information for extern variables. + if (D->hasExternalStorage() && !D->isThisDeclarationADefinition()) { + if (const SectionAttr *SA = D->getAttr<SectionAttr>()) + GV->setSection(SA->getName()); + } + // Handle XCore specific ABI requirements. if (getTriple().getArch() == llvm::Triple::xcore && D->getLanguageLinkage() == CLanguageLinkage &&
Index: test/CodeGenCXX/extern-section-attribute.cpp =================================================================== --- /dev/null +++ test/CodeGenCXX/extern-section-attribute.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -emit-llvm %s -o - -ffreestanding -triple=x86_64-pc-linux-gnu | FileCheck %s + +extern int aa __attribute__((section(".sdata"))); +// CHECK-DAG: @aa = external global i32, section ".sdata", align 4 + +extern int bb __attribute__((section(".sdata"))) = 1; +// CHECK-DAG: @bb = global i32 1, section ".sdata", align 4 + +int foo() { + return aa + bb; +} Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -2430,6 +2430,12 @@ EmitGlobalVarDefinition(D); } + // Emit section information for extern variables. + if (D->hasExternalStorage() && !D->isThisDeclarationADefinition()) { + if (const SectionAttr *SA = D->getAttr<SectionAttr>()) + GV->setSection(SA->getName()); + } + // Handle XCore specific ABI requirements. if (getTriple().getArch() == llvm::Triple::xcore && D->getLanguageLinkage() == CLanguageLinkage &&
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits