[llvm-commits] [llvm] r151250 - in /llvm/trunk: lib/CodeGen/TargetLoweringObjectFileImpl.cpp test/CodeGen/ARM/odr_comdat.ll test/CodeGen/X86/odr_comdat.ll

Anton Korobeynikov asl at math.spbu.ru
Thu Feb 23 02:36:05 PST 2012


Author: asl
Date: Thu Feb 23 04:36:04 2012
New Revision: 151250

URL: http://llvm.org/viewvc/llvm-project?rev=151250&view=rev
Log:
Fix to make sure that a comdat group gets generated correctly for a static member
of instantiated C++ templates.

Patch by Kristof Beyls!

Added:
    llvm/trunk/test/CodeGen/ARM/odr_comdat.ll
    llvm/trunk/test/CodeGen/X86/odr_comdat.ll
Modified:
    llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=151250&r1=151249&r2=151250&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Thu Feb 23 04:36:04 2012
@@ -188,6 +188,7 @@
 static const char *getSectionPrefixForGlobal(SectionKind Kind) {
   if (Kind.isText())                 return ".text.";
   if (Kind.isReadOnly())             return ".rodata.";
+  if (Kind.isBSS())                  return ".bss.";
 
   if (Kind.isThreadData())           return ".tdata.";
   if (Kind.isThreadBSS())            return ".tbss.";
@@ -216,7 +217,7 @@
   // If this global is linkonce/weak and the target handles this by emitting it
   // into a 'uniqued' section name, create and return the section now.
   if ((GV->isWeakForLinker() || EmitUniquedSection) &&
-      !Kind.isCommon() && !Kind.isBSS()) {
+      !Kind.isCommon()) {
     const char *Prefix;
     Prefix = getSectionPrefixForGlobal(Kind);
 

Added: llvm/trunk/test/CodeGen/ARM/odr_comdat.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/odr_comdat.ll?rev=151250&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/odr_comdat.ll (added)
+++ llvm/trunk/test/CodeGen/ARM/odr_comdat.ll Thu Feb 23 04:36:04 2012
@@ -0,0 +1,16 @@
+; RUN: llc < %s -mtriple=arm-linux-gnueabi        | FileCheck %s -check-prefix=ARMGNUEABI
+
+; Checking that a comdat group gets generated correctly for a static member 
+; of instantiated C++ templates.
+; see http://sourcery.mentor.com/public/cxx-abi/abi.html#vague-itemplate
+; section 5.2.6 Instantiated templates
+; "Any static member data object is emitted in a COMDAT identified by its mangled 
+;  name, in any object file with a reference to its name symbol."
+
+; Case 1: variable is not explicitly initialized, and ends up in a .bss section
+; ARMGNUEABI: .section        .bss._ZN1CIiE1iE,"aGw",%nobits,_ZN1CIiE1iE,comdat
+ at _ZN1CIiE1iE = weak_odr global i32 0, align 4
+
+; Case 2: variable is explicitly initialized, and ends up in a .data section
+; ARMGNUEABI: .section        .data._ZN1CIiE1jE,"aGw",%progbits,_ZN1CIiE1jE,comdat
+ at _ZN1CIiE1jE = weak_odr global i32 12, align 4

Added: llvm/trunk/test/CodeGen/X86/odr_comdat.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/odr_comdat.ll?rev=151250&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/odr_comdat.ll (added)
+++ llvm/trunk/test/CodeGen/X86/odr_comdat.ll Thu Feb 23 04:36:04 2012
@@ -0,0 +1,16 @@
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s -check-prefix=X86LINUX
+
+; Checking that a comdat group gets generated correctly for a static member 
+; of instantiated C++ templates.
+; see http://sourcery.mentor.com/public/cxx-abi/abi.html#vague-itemplate
+; section 5.2.6 Instantiated templates
+; "Any static member data object is emitted in a COMDAT identified by its mangled 
+;  name, in any object file with a reference to its name symbol."
+
+; Case 1: variable is not explicitly initialized, and ends up in a .bss section
+; X86LINUX:   .section        .bss._ZN1CIiE1iE,"aGw", at nobits,_ZN1CIiE1iE,comdat
+ at _ZN1CIiE1iE = weak_odr global i32 0, align 4
+
+; Case 2: variable is explicitly initialized, and ends up in a .data section
+; X86LINUX:   .section        .data._ZN1CIiE1jE,"aGw", at progbits,_ZN1CIiE1jE,comdat
+ at _ZN1CIiE1jE = weak_odr global i32 12, align 4





More information about the llvm-commits mailing list