From ed0ed946ab6b84814ba09a6224d1ec4bfb9447b1 Mon Sep 17 00:00:00 2001 From: Robert Lytton Date: Fri, 11 Oct 2013 10:27:13 +0000 Subject: [PATCH] XCore target fix bug in emitArrayBound() causing segmentation fault git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192434 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/XCore/XCoreAsmPrinter.cpp | 11 +++++------ test/CodeGen/XCore/globals.ll | 2 +- test/CodeGen/XCore/linkage.ll | 7 +++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/Target/XCore/XCoreAsmPrinter.cpp b/lib/Target/XCore/XCoreAsmPrinter.cpp index 35ba2998f86..61511cdb36e 100644 --- a/lib/Target/XCore/XCoreAsmPrinter.cpp +++ b/lib/Target/XCore/XCoreAsmPrinter.cpp @@ -36,6 +36,7 @@ #include "llvm/MC/MCInst.h" #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCExpr.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/raw_ostream.h" @@ -88,14 +89,12 @@ void XCoreAsmPrinter::emitArrayBound(MCSymbol *Sym, const GlobalVariable *GV) { MCSymbol *SymGlob = OutContext.GetOrCreateSymbol( Twine(Sym->getName() + StringRef(".globound"))); OutStreamer.EmitSymbolAttribute(SymGlob, MCSA_Global); - - OutStreamer.EmitRawText("\t.set\t" + Twine(Sym->getName()) + - ".globound," + Twine(ATy->getNumElements())); - + OutStreamer.EmitAssignment(SymGlob, + MCConstantExpr::Create(ATy->getNumElements(), + OutContext)); if (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage()) { // TODO Use COMDAT groups for LinkOnceLinkage - OutStreamer.EmitRawText(MAI->getWeakDefDirective() +Twine(Sym->getName())+ - ".globound"); + OutStreamer.EmitSymbolAttribute(SymGlob, MCSA_Weak); } } } diff --git a/test/CodeGen/XCore/globals.ll b/test/CodeGen/XCore/globals.ll index b1405878665..b3a872bb689 100644 --- a/test/CodeGen/XCore/globals.ll +++ b/test/CodeGen/XCore/globals.ll @@ -93,4 +93,4 @@ entry: @array = global [10 x i16] zeroinitializer, align 2 ; CHECK: .globl array.globound -; CHECK: .set array.globound,10 +; CHECK: array.globound = 10 diff --git a/test/CodeGen/XCore/linkage.ll b/test/CodeGen/XCore/linkage.ll index 659995155b7..b29b035778c 100644 --- a/test/CodeGen/XCore/linkage.ll +++ b/test/CodeGen/XCore/linkage.ll @@ -16,6 +16,13 @@ define protected void @test_protected() { unreachable } +; CHECK: .globl array.globound +; CHECK: array.globound = 2 +; CHECK: .weak array.globound +; CHECK: .globl array +; CHECK: .weak array +@array = weak global [2 x i32] zeroinitializer + ; CHECK: .weak gd @gd = weak global i32 0 -- 2.34.1