Index: lib/MC/MCParser/AsmParser.cpp =================================================================== --- lib/MC/MCParser/AsmParser.cpp +++ lib/MC/MCParser/AsmParser.cpp @@ -2543,8 +2543,14 @@ return TokError("unexpected token in '.file' directive"); // Usually the directory and filename together, otherwise just the directory. - StringRef Path = getTok().getString(); - Path = Path.substr(1, Path.size()-2); + // Since MCAsmStreamer replaces non-printing characters with their escape + // sequence in the form of \ooo, the integrated assembler should convert + // these escaped character literals back to their original value before + // emitting to the object file. + std::string PathData, FilenameData; + if (parseEscapedString(PathData)) + return true; + StringRef Path = PathData; Lex(); StringRef Directory; @@ -2552,8 +2558,9 @@ if (getLexer().is(AsmToken::String)) { if (FileNumber == -1) return TokError("explicit path specified, but no file number"); - Filename = getTok().getString(); - Filename = Filename.substr(1, Filename.size()-2); + if (parseEscapedString(FilenameData)) + return true; + Filename = FilenameData; Directory = Path; Lex(); } else { @@ -3488,16 +3495,18 @@ if (getLexer().isNot(AsmToken::String)) return TokError("expected string in '.include' directive"); - std::string Filename = getTok().getString(); + // To be compatible with GNU binutils behavior, the integrated assembler + // should convert an escaped octal sequence back to the original character + // literal. + std::string Filename; + if (parseEscapedString(Filename)) + return true; SMLoc IncludeLoc = getLexer().getLoc(); Lex(); if (getLexer().isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.include' directive"); - // Strip the quotes. - Filename = Filename.substr(1, Filename.size()-2); - // Attempt to switch the lexer to the included file before consuming the end // of statement to avoid losing it when we switch. if (EnterIncludeFile(Filename)) { @@ -3514,16 +3523,18 @@ if (getLexer().isNot(AsmToken::String)) return TokError("expected string in '.incbin' directive"); - std::string Filename = getTok().getString(); + // To be compatible with GNU binutils behavior, the integrated assembler + // should convert an escaped octal sequence back to the original character + // literal. + std::string Filename; + if (parseEscapedString(Filename)) + return true; SMLoc IncbinLoc = getLexer().getLoc(); Lex(); if (getLexer().isNot(AsmToken::EndOfStatement)) return TokError("unexpected token in '.incbin' directive"); - // Strip the quotes. - Filename = Filename.substr(1, Filename.size()-2); - // Attempt to process the included file. if (ProcessIncbinFile(Filename)) { Error(IncbinLoc, "Could not find incbin file '" + Filename + "'"); Index: test/MC/AsmParser/directive_file.s =================================================================== --- test/MC/AsmParser/directive_file.s +++ test/MC/AsmParser/directive_file.s @@ -1,7 +1,7 @@ # RUN: llvm-mc -triple i386-unknown-unknown %s | FileCheck %s .file "hello" - .file 1 "world" + .file 1 "worl\144" .file 2 "directory" "file" # CHECK: .file "hello" Index: test/MC/AsmParser/directive_incbin.s =================================================================== --- test/MC/AsmParser/directive_incbin.s +++ test/MC/AsmParser/directive_incbin.s @@ -1,6 +1,6 @@ # RUN: llvm-mc -triple i386-unknown-unknown %s -I %p | FileCheck %s .data -.incbin "incbin_abcd" +.incbin "incbin\137abcd" # CHECK: .ascii "abcd\n" Index: test/MC/AsmParser/directive_include.s =================================================================== --- test/MC/AsmParser/directive_include.s +++ test/MC/AsmParser/directive_include.s @@ -5,5 +5,5 @@ # CHECK: a = 0 # CHECK: TESTB: TESTA: - .include "directive_set.s" + .include "directive\137set.s" TESTB: