Skip to content

Commit c0693bc

Browse files
committed
rdar://7119244 - globals with an explicit section specified don't get
common linkage. llvm-svn: 78158
1 parent 13b8609 commit c0693bc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
883883
else if (D->hasAttr<WeakAttr>())
884884
GV->setLinkage(llvm::GlobalVariable::WeakAnyLinkage);
885885
else if (!CompileOpts.NoCommon &&
886-
(!D->hasExternalStorage() && !D->getInit()))
886+
!D->hasExternalStorage() && !D->getInit() &&
887+
!D->getAttr<SectionAttr>())
887888
GV->setLinkage(llvm::GlobalVariable::CommonLinkage);
888889
else
889890
GV->setLinkage(llvm::GlobalVariable::ExternalLinkage);

clang/test/CodeGen/global-init.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
// RUN: clang-cc -emit-llvm -o - %s | not grep "common"
1+
// RUN: clang-cc -emit-llvm -o - %s | FileCheck %s
22

33
// This checks that the global won't be marked as common.
44
// (It shouldn't because it's being initialized).
55

66
int a;
77
int a = 242;
8+
// CHECK: @a = global i32 242
9+
10+
// This shouldn't be emitted as common because it has an explicit section.
11+
// rdar://7119244
12+
int b __attribute__((section("foo")));
13+
14+
// CHECK: @b = global i32 0, section "foo"

0 commit comments

Comments
 (0)