summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-05-14 04:31:50 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-05-14 04:31:50 +0000
commit3439ed6324f437fdafaf5a4afe1a0f59b3807c04 (patch)
treed80a7d9bdf48e3214432aa749b9e134d51785d34
parentceb5a7ada2ed49e8de8ad9429b6ce98be6a99749 (diff)
downloadbcm5719-llvm-3439ed6324f437fdafaf5a4afe1a0f59b3807c04.tar.gz
bcm5719-llvm-3439ed6324f437fdafaf5a4afe1a0f59b3807c04.zip
Inline Asm: Ensure buffer is newline terminated to match how the text is printed.
- This is a hack, but I can't decide the best place to handle this. Chris? llvm-svn: 103765
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp14
-rw-r--r--llvm/test/Other/inline-asm-newline-terminator.ll6
2 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
index 37d10e5c4cc..ba6fed2a78b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -53,6 +53,17 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, unsigned LocCookie) const {
}
SourceMgr SrcMgr;
+
+ // Ensure the buffer is newline terminated.
+ char *TmpString = 0;
+ if (Str.back() != '\n') {
+ TmpString = new char[Str.size() + 2];
+ memcpy(TmpString, Str.data(), Str.size());
+ TmpString[Str.size()] = '\n';
+ TmpString[Str.size() + 1] = 0;
+ isNullTerminated = true;
+ Str = TmpString;
+ }
// If the current LLVMContext has an inline asm handler, set it in SourceMgr.
LLVMContext &LLVMCtx = MMI->getModule()->getContext();
@@ -84,6 +95,9 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, unsigned LocCookie) const {
/*NoFinalize*/ true);
if (Res && !HasDiagHandler)
report_fatal_error("Error parsing inline asm\n");
+
+ if (TmpString)
+ delete[] TmpString;
}
diff --git a/llvm/test/Other/inline-asm-newline-terminator.ll b/llvm/test/Other/inline-asm-newline-terminator.ll
new file mode 100644
index 00000000000..af93cc0dd2a
--- /dev/null
+++ b/llvm/test/Other/inline-asm-newline-terminator.ll
@@ -0,0 +1,6 @@
+; RUN: llc -filetype=obj -o - < %s
+
+; ModuleID = 't.c'
+target triple = "x86_64-apple-darwin10.0.0"
+
+module asm ".desc _f0, 0x10"
OpenPOWER on IntegriCloud