From 89e0f386f3c8bafbbae05d7d32695ce571617397 Mon Sep 17 00:00:00 2001
From: Joerg Sonnenberger <joerg@bec.de>
Date: Fri, 4 Mar 2011 20:03:14 +0000
Subject: [PATCH] Be nice to Xcore and the XMOS assembler and avoid quoting
 section names that contain only letters, digits and the characters "_" and
 ".".

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127028 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/MC/MCSectionELF.cpp                       | 30 +++++++++++--------
 test/CodeGen/ARM/ctors_dtors.ll               |  8 ++---
 test/CodeGen/ARM/section.ll                   |  2 +-
 test/CodeGen/Blackfin/jumptable.ll            |  2 +-
 test/CodeGen/CellSPU/bss.ll                   |  2 +-
 .../Mips/2008-07-15-InternalConstant.ll       |  4 +--
 test/CodeGen/Mips/2008-07-22-Cstpool.ll       |  2 +-
 test/CodeGen/PowerPC/sections.ll              |  2 +-
 test/CodeGen/X86/attribute-sections.ll        |  6 ++--
 test/CodeGen/X86/bss_pagealigned.ll           |  2 +-
 test/CodeGen/X86/global-sections-tls.ll       |  2 +-
 test/CodeGen/X86/global-sections.ll           | 16 +++++-----
 test/CodeGen/X86/pic_jumptable.ll             |  2 +-
 test/CodeGen/XCore/constants.ll               |  2 +-
 test/CodeGen/XCore/globals.ll                 | 16 +++++-----
 test/CodeGen/XCore/tls.ll                     |  2 +-
 test/MC/ELF/section-quoting.s                 |  2 +-
 17 files changed, 54 insertions(+), 48 deletions(-)

diff --git a/lib/MC/MCSectionELF.cpp b/lib/MC/MCSectionELF.cpp
index b908a745b26..dfd77c3fe81 100644
--- a/lib/MC/MCSectionELF.cpp
+++ b/lib/MC/MCSectionELF.cpp
@@ -40,20 +40,26 @@ void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI,
   }
 
   StringRef name = getSectionName();
-  OS << "\t.section\t\"";
-  for (const char *b = name.begin(), *e = name.end(); b < e; ++b) {
-    if (*b == '"') // Unquoted "
-      OS << "\\\"";
-    else if (*b != '\\') // Neither " or backslash
-      OS << *b;
-    else if (b + 1 == e) // Trailing backslash
-      OS << "\\\\";
-    else {
-      OS << b[0] << b[1]; // Quoted character
-      ++b;
+  if (name.find_first_not_of("0123456789_."
+                             "abcdefghijklmnopqrstuvwxyz"
+                             "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == name.npos) {
+    OS << "\t.section\t" << name;
+  } else {
+    OS << "\t.section\t\"";
+    for (const char *b = name.begin(), *e = name.end(); b < e; ++b) {
+      if (*b == '"') // Unquoted "
+        OS << "\\\"";
+      else if (*b != '\\') // Neither " or backslash
+        OS << *b;
+      else if (b + 1 == e) // Trailing backslash
+        OS << "\\\\";
+      else {
+        OS << b[0] << b[1]; // Quoted character
+        ++b;
+      }
     }
+    OS << '"';
   }
-  OS << '"';
 
   // Handle the weird solaris syntax if desired.
   if (MAI.usesSunStyleELFSectionSwitchSyntax() && 
diff --git a/test/CodeGen/ARM/ctors_dtors.ll b/test/CodeGen/ARM/ctors_dtors.ll
index 4ed2deee333..fb94626ab7d 100644
--- a/test/CodeGen/ARM/ctors_dtors.ll
+++ b/test/CodeGen/ARM/ctors_dtors.ll
@@ -5,11 +5,11 @@
 ; DARWIN: .section	__DATA,__mod_init_func,mod_init_funcs
 ; DARWIN: .section	__DATA,__mod_term_func,mod_term_funcs
 
-; ELF: .section ".ctors","aw",%progbits
-; ELF: .section ".dtors","aw",%progbits
+; ELF: .section .ctors,"aw",%progbits
+; ELF: .section .dtors,"aw",%progbits
 
-; GNUEABI: .section ".init_array","aw",%init_array
-; GNUEABI: .section ".fini_array","aw",%fini_array
+; GNUEABI: .section .init_array,"aw",%init_array
+; GNUEABI: .section .fini_array,"aw",%fini_array
 
 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @__mf_init } ]                ; <[1 x { i32, void ()* }]*> [#uses=0]
 @llvm.global_dtors = appending global [1 x { i32, void ()* }] [ { i32, void ()* } { i32 65535, void ()* @__mf_fini } ]                ; <[1 x { i32, void ()* }]*> [#uses=0]
diff --git a/test/CodeGen/ARM/section.ll b/test/CodeGen/ARM/section.ll
index ff708d55ab3..7a566d49d32 100644
--- a/test/CodeGen/ARM/section.ll
+++ b/test/CodeGen/ARM/section.ll
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -mtriple=arm-linux | \
 ; RUN:   grep {__DTOR_END__:}
 ; RUN: llc < %s -mtriple=arm-linux | \
-; RUN:   grep {\\.section."\\.dtors","aw",.progbits}
+; RUN:   grep {\\.section.\\.dtors,"aw",.progbits}
 
 @__DTOR_END__ = internal global [1 x i32] zeroinitializer, section ".dtors"       ; <[1 x i32]*> [#uses=0]
 
diff --git a/test/CodeGen/Blackfin/jumptable.ll b/test/CodeGen/Blackfin/jumptable.ll
index 21fc1dfa6f0..263533c0009 100644
--- a/test/CodeGen/Blackfin/jumptable.ll
+++ b/test/CodeGen/Blackfin/jumptable.ll
@@ -1,6 +1,6 @@
 ; RUN: llc < %s -march=bfin -verify-machineinstrs | FileCheck %s
 
-; CHECK: .section ".rodata"
+; CHECK: .section .rodata
 ; CHECK: JTI0_0:
 ; CHECK: .long .BB0_1
 
diff --git a/test/CodeGen/CellSPU/bss.ll b/test/CodeGen/CellSPU/bss.ll
index 7731e3091b0..327800d09cb 100644
--- a/test/CodeGen/CellSPU/bss.ll
+++ b/test/CodeGen/CellSPU/bss.ll
@@ -1,7 +1,7 @@
 ; RUN: llc < %s -march=cellspu | FileCheck %s
 
 @bssVar = global i32 zeroinitializer
-; CHECK: .section ".bss"
+; CHECK: .section .bss
 ; CHECK-NEXT: .globl
 
 @localVar= internal global i32 zeroinitializer
diff --git a/test/CodeGen/Mips/2008-07-15-InternalConstant.ll b/test/CodeGen/Mips/2008-07-15-InternalConstant.ll
index df9b2ebc9e8..c3db6387aff 100644
--- a/test/CodeGen/Mips/2008-07-15-InternalConstant.ll
+++ b/test/CodeGen/Mips/2008-07-15-InternalConstant.ll
@@ -1,6 +1,6 @@
 ; RUN: llc < %s -march=mips -o %t
-; RUN: grep {rodata.str1.4","aMS",@progbits}  %t | count 1
-; RUN: grep {r.data",}  %t | count 1
+; RUN: grep {rodata.str1.4,"aMS",@progbits}  %t | count 1
+; RUN: grep {r.data,}  %t | count 1
 ; RUN: grep {\%hi} %t | count 2
 ; RUN: grep {\%lo} %t | count 2
 ; RUN: not grep {gp_rel} %t
diff --git a/test/CodeGen/Mips/2008-07-22-Cstpool.ll b/test/CodeGen/Mips/2008-07-22-Cstpool.ll
index 04574155358..94dfe35faba 100644
--- a/test/CodeGen/Mips/2008-07-22-Cstpool.ll
+++ b/test/CodeGen/Mips/2008-07-22-Cstpool.ll
@@ -1,6 +1,6 @@
 ; RUN: llc < %s -march=mips -o %t
 ; RUN: grep {CPI\[01\]_\[01\]:} %t | count 2
-; RUN: grep {".rodata.cst4","aM",@progbits} %t | count 1
+; RUN: grep {.rodata.cst4,"aM",@progbits} %t | count 1
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"
 target triple = "mipsallegrexel-unknown-psp-elf"
 
diff --git a/test/CodeGen/PowerPC/sections.ll b/test/CodeGen/PowerPC/sections.ll
index 260b91e7722..0ff4a89ff37 100644
--- a/test/CodeGen/PowerPC/sections.ll
+++ b/test/CodeGen/PowerPC/sections.ll
@@ -3,6 +3,6 @@
 
 @A = global i32 0
 
-; CHECK:  .section  ".bss","aw",@nobits
+; CHECK:  .section  .bss,"aw",@nobits
 ; CHECK:  .globl A
 
diff --git a/test/CodeGen/X86/attribute-sections.ll b/test/CodeGen/X86/attribute-sections.ll
index 19e56eeccea..30353346b5c 100644
--- a/test/CodeGen/X86/attribute-sections.ll
+++ b/test/CodeGen/X86/attribute-sections.ll
@@ -3,16 +3,16 @@
 declare i32 @foo()
 @G0 = global i32 ()* @foo, section ".init_array"
 
-; LINUX:  .section  ".init_array","aw"
+; LINUX:  .section  .init_array,"aw"
 ; LINUX:  .globl G0
 
 @G1 = global i32 ()* @foo, section ".fini_array"
 
-; LINUX:  .section  ".fini_array","aw"
+; LINUX:  .section  .fini_array,"aw"
 ; LINUX:  .globl G1
 
 @G2 = global i32 ()* @foo, section ".preinit_array"
 
-; LINUX:  .section ".preinit_array","aw"
+; LINUX:  .section .preinit_array,"aw"
 ; LINUX:  .globl G2
 
diff --git a/test/CodeGen/X86/bss_pagealigned.ll b/test/CodeGen/X86/bss_pagealigned.ll
index 746364e7277..da95aca110d 100644
--- a/test/CodeGen/X86/bss_pagealigned.ll
+++ b/test/CodeGen/X86/bss_pagealigned.ll
@@ -14,7 +14,7 @@ define void @unxlate_dev_mem_ptr(i64 %phis, i8* %addr) nounwind {
   ret void
 }
 @bm_pte = internal global [512 x %struct.kmem_cache_order_objects] zeroinitializer, section ".bss.page_aligned", align 4096
-; CHECK: .section        ".bss.page_aligned","aw",@nobits
+; CHECK: .section        .bss.page_aligned,"aw",@nobits
 ; CHECK-NEXT: .align  4096
 ; CHECK-NEXT: bm_pte:
 ; CHECK-NEXT: .zero   4096
diff --git a/test/CodeGen/X86/global-sections-tls.ll b/test/CodeGen/X86/global-sections-tls.ll
index e1e5fb3de12..d5409a579b2 100644
--- a/test/CodeGen/X86/global-sections-tls.ll
+++ b/test/CodeGen/X86/global-sections-tls.ll
@@ -2,7 +2,7 @@
 
 ; PR4639
 @G1 = internal thread_local global i32 0		; <i32*> [#uses=1]
-; LINUX: .section	".tbss","awT",@nobits
+; LINUX: .section	.tbss,"awT",@nobits
 ; LINUX: G1:
 
 
diff --git a/test/CodeGen/X86/global-sections.ll b/test/CodeGen/X86/global-sections.ll
index 7625a408294..d0a1b4d281f 100644
--- a/test/CodeGen/X86/global-sections.ll
+++ b/test/CodeGen/X86/global-sections.ll
@@ -33,10 +33,10 @@
 ; DARWIN: _G3:
 ; DARWIN:     .long _G1
 
-; LINUX:   .section        ".rodata","a",@progbits
+; LINUX:   .section        .rodata,"a",@progbits
 ; LINUX:   .globl  G3
 
-; LINUX-SECTIONS: .section        ".rodata.G3","a",@progbits
+; LINUX-SECTIONS: .section        .rodata.G3,"a",@progbits
 ; LINUX-SECTIONS: .globl  G3
 
 
@@ -66,7 +66,7 @@
 @"foo bar" = linkonce global i32 42
 
 ; LINUX: .type	foo_20_bar,@object
-; LINUX: .section ".data.foo_20_bar","aGw",@progbits,foo_20_bar,comdat
+; LINUX: .section .data.foo_20_bar,"aGw",@progbits,foo_20_bar,comdat
 ; LINUX: .weak	foo_20_bar
 ; LINUX: foo_20_bar:
 
@@ -79,7 +79,7 @@
 @G6 = weak_odr unnamed_addr constant [1 x i8] c"\01"
 
 ; LINUX:   .type	G6,@object
-; LINUX:   .section	".rodata.G6","aG",@progbits,G6,comdat
+; LINUX:   .section	.rodata.G6,"aG",@progbits,G6,comdat
 ; LINUX:   .weak	G6
 ; LINUX: G6:
 ; LINUX:   .byte	1
@@ -99,12 +99,12 @@
 ; DARWIN: _G7:
 ; DARWIN:	.asciz	"abcdefghi"
 
-; LINUX:	.section	".rodata.str1.1","aMS",@progbits,1
+; LINUX:	.section	.rodata.str1.1,"aMS",@progbits,1
 ; LINUX:	.globl G7
 ; LINUX: G7:
 ; LINUX:	.asciz	"abcdefghi"
 
-; LINUX-SECTIONS: .section        ".rodata.G7","aMS",@progbits,1
+; LINUX-SECTIONS: .section        .rodata.G7,"aMS",@progbits,1
 ; LINUX-SECTIONS:	.globl G7
 
 
@@ -114,7 +114,7 @@
 ; DARWIN:	.globl _G8
 ; DARWIN: _G8:
 
-; LINUX:	.section	".rodata.str2.2","aMS",@progbits,2
+; LINUX:	.section	.rodata.str2.2,"aMS",@progbits,2
 ; LINUX:	.globl G8
 ; LINUX:G8:
 
@@ -123,7 +123,7 @@
 ; DARWIN:	.globl _G9
 ; DARWIN: _G9:
 
-; LINUX:	.section	".rodata.str4.4","aMS",@progbits,4
+; LINUX:	.section	.rodata.str4.4,"aMS",@progbits,4
 ; LINUX:	.globl G9
 ; LINUX:G9
 
diff --git a/test/CodeGen/X86/pic_jumptable.ll b/test/CodeGen/X86/pic_jumptable.ll
index 8ddba4af72a..b6761e338aa 100644
--- a/test/CodeGen/X86/pic_jumptable.ll
+++ b/test/CodeGen/X86/pic_jumptable.ll
@@ -1,4 +1,4 @@
-; RUN: llc < %s -relocation-model=pic -mtriple=i386-linux-gnu -asm-verbose=false | grep -F .text._Z3fooILi1EEvi","axG",@progbits,_Z3fooILi1EEvi,comdat
+; RUN: llc < %s -relocation-model=pic -mtriple=i386-linux-gnu -asm-verbose=false | grep -F .text._Z3fooILi1EEvi,"axG",@progbits,_Z3fooILi1EEvi,comdat
 ; RUN: llc < %s -relocation-model=pic -mtriple=i686-apple-darwin -asm-verbose=false | FileCheck %s
 ; RUN: llc < %s                       -mtriple=x86_64-apple-darwin | not grep 'lJTI'
 ; rdar://6971437
diff --git a/test/CodeGen/XCore/constants.ll b/test/CodeGen/XCore/constants.ll
index 10cf9a75dfa..cad1a2153f4 100644
--- a/test/CodeGen/XCore/constants.ll
+++ b/test/CodeGen/XCore/constants.ll
@@ -1,6 +1,6 @@
 ; RUN: llc < %s -march=xcore -mcpu=xs1b-generic | FileCheck %s
 
-; CHECK: .section ".cp.rodata.cst4","aMc",@progbits,4
+; CHECK: .section .cp.rodata.cst4,"aMc",@progbits,4
 ; CHECK: .LCPI0_0:
 ; CHECK: .long 12345678
 ; CHECK: f:
diff --git a/test/CodeGen/XCore/globals.ll b/test/CodeGen/XCore/globals.ll
index f6ff3354ee8..7487561dec9 100644
--- a/test/CodeGen/XCore/globals.ll
+++ b/test/CodeGen/XCore/globals.ll
@@ -60,33 +60,33 @@ entry:
 }
 
 @G1 = global i32 4712
-; CHECK: .section ".dp.data","awd",@progbits
+; CHECK: .section .dp.data,"awd",@progbits
 ; CHECK: G1:
 
 @G2 = global i32 0
-; CHECK: .section ".dp.bss","awd",@nobits
+; CHECK: .section .dp.bss,"awd",@nobits
 ; CHECK: G2:
 
 @G3 = unnamed_addr constant i32 9401
-; CHECK: .section ".cp.rodata.cst4","aMc",@progbits,4
+; CHECK: .section .cp.rodata.cst4,"aMc",@progbits,4
 ; CHECK: G3:
 
 @G4 = global i32* @G1
-; CHECK: .section ".dp.data","awd",@progbits
+; CHECK: .section .dp.data,"awd",@progbits
 ; CHECK: G4:
 
 @G5 = unnamed_addr constant i32* @G1
-; CHECK: .section ".cp.rodata","ac",@progbits
+; CHECK: .section .cp.rodata,"ac",@progbits
 ; CHECK: G5:
 
 @G6 = global i32* @G8
-; CHECK: .section ".dp.data","awd",@progbits
+; CHECK: .section .dp.data,"awd",@progbits
 ; CHECK: G6:
 
 @G7 = unnamed_addr constant i32* @G8
-; CHECK: .section ".cp.rodata","ac",@progbits
+; CHECK: .section .cp.rodata,"ac",@progbits
 ; CHECK: G7:
 
 @G8 = internal global i32 9312
-; CHECK: .section ".dp.data","awd",@progbits
+; CHECK: .section .dp.data,"awd",@progbits
 ; CHECK: G8:
diff --git a/test/CodeGen/XCore/tls.ll b/test/CodeGen/XCore/tls.ll
index b4f1671796a..ed41afae099 100644
--- a/test/CodeGen/XCore/tls.ll
+++ b/test/CodeGen/XCore/tls.ll
@@ -8,7 +8,7 @@ entry:
 }
 
 @G = thread_local global i32 15
-; CHECK: .section ".dp.data","awd",@progbits
+; CHECK: .section .dp.data,"awd",@progbits
 ; CHECK: G:
 ; CHECK: .long 15
 ; CHECK: .long 15
diff --git a/test/MC/ELF/section-quoting.s b/test/MC/ELF/section-quoting.s
index 5335af16bab..3751e722952 100644
--- a/test/MC/ELF/section-quoting.s
+++ b/test/MC/ELF/section-quoting.s
@@ -6,5 +6,5 @@
 .section "foo bar"
 
 // CHECK: .section "bar-\"foo\""
-// CHECK: .section "foo"
+// CHECK: .section foo
 // CHECK: .section "foo bar"