tms34010: fail loudly on non-GSPA globals
emitGlobalVariable handled only zero-initialized .bss objects and let initialized globals, string literals and constant/private data fall through to the generic ELF .data/.rodata/.asciz printer, which GSPA rejects. Reject every non-null initializer and private/constant data with a fatal error, and add m1-data/m1-string negative tests.
This commit is contained in:
1 parent
24522ce72f
commit
16a4358dd3
3 files changed
+34
-3
No files matched your search
@@ -19,6 +19,7 @@
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/MC/TargetRegistry.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
@@ -49,9 +50,18 @@ void TMS34010AsmPrinter::emitInstruction(const MachineInstr *MI) {
|
||||
}
|
||||
|
||||
void TMS34010AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
|
||||
// External declarations need no output in GSPA.
|
||||
if (GV->isDeclaration())
|
||||
return;
|
||||
|
||||
// GSPA has no .comm/.local directives; a zero-initialized object is one
|
||||
// .bss line. Sizes and alignment in GSPA are in bits.
|
||||
if (GV->hasInitializer() && GV->getInitializer()->isNullValue()) {
|
||||
// .bss line. Sizes and alignment in GSPA are in bits. Anything else
|
||||
// (initialized data, string literals, constant/private data) would fall
|
||||
// through to the generic ELF .data/.rodata/.p2align/.asciz printer, which
|
||||
// GSPA rejects; fail loudly instead.
|
||||
if (GV->hasInitializer() && GV->getInitializer()->isNullValue() &&
|
||||
!GV->isConstant() && !GV->hasPrivateLinkage() &&
|
||||
GV->getSection().empty() && !GV->isThreadLocal()) {
|
||||
const DataLayout &DL = GV->getParent()->getDataLayout();
|
||||
Align Alignment = getGVAlignment(GV, DL, GV->getAlign().valueOrOne());
|
||||
uint64_t SizeBits =
|
||||
@@ -64,7 +74,9 @@ void TMS34010AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
|
||||
return;
|
||||
}
|
||||
|
||||
AsmPrinter::emitGlobalVariable(GV);
|
||||
report_fatal_error(
|
||||
"M1 supports only zero-initialized globals; .data/string literals are M2",
|
||||
false);
|
||||
}
|
||||
|
||||
char TMS34010AsmPrinter::ID = 0;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
; RUN: not llc -march=tms34010 -O0 -filetype=asm < %s 2>&1 | FileCheck %s
|
||||
; RUN: not llc -march=tms34010 -O2 -filetype=asm < %s 2>&1 | FileCheck %s
|
||||
;
|
||||
; GSPA has no .data/.p2align directives. An initialized global used to fall
|
||||
; through to the generic ELF asm printer; it must fail loudly instead.
|
||||
; CHECK: M1 supports only zero-initialized globals; .data/string literals are M2
|
||||
@x = global i32 42
|
||||
@@ -0,0 +1,12 @@
|
||||
; RUN: not llc -march=tms34010 -O0 -filetype=asm < %s 2>&1 | FileCheck %s
|
||||
; RUN: not llc -march=tms34010 -O2 -filetype=asm < %s 2>&1 | FileCheck %s
|
||||
;
|
||||
; A string literal is a private constant with a non-null initializer. It
|
||||
; used to print .rodata/.asciz, which GSPA rejects; it must fail loudly.
|
||||
; CHECK: M1 supports only zero-initialized globals; .data/string literals are M2
|
||||
@.str = private unnamed_addr constant [6 x i8] c"hello\00", align 1
|
||||
|
||||
define ptr @str() {
|
||||
entry:
|
||||
ret ptr @.str
|
||||
}
|
||||
Reference in new issue
Block a user