Author: Chen Zheng Date: 2021-04-26T05:13:10-04:00 New Revision: d8dc1f20c9a86adfe31ae8df2a763e89ee5068bb
URL: https://github.com/llvm/llvm-project/commit/d8dc1f20c9a86adfe31ae8df2a763e89ee5068bb DIFF: https://github.com/llvm/llvm-project/commit/d8dc1f20c9a86adfe31ae8df2a763e89ee5068bb.diff LOG: file name - special characters. Added: llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll Modified: llvm/include/llvm/MC/MCAsmInfo.h llvm/lib/MC/MCAsmInfoXCOFF.cpp llvm/lib/MC/MCAsmStreamer.cpp Removed: ################################################################################ diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h index b674af072ed55..e48d1edd05068 100644 --- a/llvm/include/llvm/MC/MCAsmInfo.h +++ b/llvm/include/llvm/MC/MCAsmInfo.h @@ -345,6 +345,10 @@ class MCAsmInfo { /// target also needs the directory along with the basename. Default to true. bool HasBasenameOnlyForFileDirective = true; + /// Tue if the target represents string constant as mostly raw characters in + /// paired double quotation. Default to false. + bool HasPairedDoubleQuoteStringConstants = false; + // True if the target allows .align directives on functions. This is true for // most targets, so defaults to true. bool HasFunctionAlignment = true; @@ -673,6 +677,9 @@ class MCAsmInfo { bool hasBasenameOnlyForFileDirective() const { return HasBasenameOnlyForFileDirective; } + bool hasPairedDoubleQuoteStringConstants() const { + return HasPairedDoubleQuoteStringConstants; + } bool hasFunctionAlignment() const { return HasFunctionAlignment; } bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; } bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; } diff --git a/llvm/lib/MC/MCAsmInfoXCOFF.cpp b/llvm/lib/MC/MCAsmInfoXCOFF.cpp index f90fc5a8f4983..670ab30821638 100644 --- a/llvm/lib/MC/MCAsmInfoXCOFF.cpp +++ b/llvm/lib/MC/MCAsmInfoXCOFF.cpp @@ -20,6 +20,11 @@ MCAsmInfoXCOFF::MCAsmInfoXCOFF() { IsLittleEndian = false; HasVisibilityOnlyWithLinkage = true; HasBasenameOnlyForFileDirective = false; + + // For XCOFF, string constant consists of any number of characters enclosed in + // "" (double quotation marks) + HasPairedDoubleQuoteStringConstants = true; + PrivateGlobalPrefix = "L.."; PrivateLabelPrefix = "L.."; SupportsQuotedNames = false; diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index 0012c10bf83b4..432c7bb3971bd 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -60,6 +60,12 @@ class MCAsmStreamer final : public MCStreamer { unsigned UseDwarfDirectory : 1; void EmitRegisterName(int64_t Register); + void PrintQuotedString(StringRef Data, raw_ostream &OS); + void printDwarfFileDirective(unsigned FileNo, StringRef Directory, + StringRef Filename, + Optional<MD5::MD5Result> Checksum, + Optional<StringRef> Source, + bool UseDwarfDirectory, raw_svector_ostream &OS); void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override; void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override; @@ -1040,33 +1046,53 @@ static void PrintByteList(StringRef Data, raw_ostream &OS, llvm_unreachable("Invalid AsmCharLiteralSyntax value!"); } -static void PrintQuotedString(StringRef Data, raw_ostream &OS) { +void MCAsmStreamer::PrintQuotedString(StringRef Data, raw_ostream &OS) { OS << '"'; - for (unsigned i = 0, e = Data.size(); i != e; ++i) { - unsigned char C = Data[i]; - if (C == '"' || C == '\\') { - OS << '\\' << (char)C; - continue; + if (MAI->hasPairedDoubleQuoteStringConstants()) { + for (unsigned i = 0, e = Data.size(); i != e; ++i) { + unsigned char C = Data[i]; + if (C == '"') + OS << "\"\""; + else + OS << (char)C; } + } else { + for (unsigned i = 0, e = Data.size(); i != e; ++i) { + unsigned char C = Data[i]; + if (C == '"' || C == '\\') { + OS << '\\' << (char)C; + continue; + } - if (isPrint((unsigned char)C)) { - OS << (char)C; - continue; - } + if (isPrint((unsigned char)C)) { + OS << (char)C; + continue; + } - switch (C) { - case '\b': OS << "\\b"; break; - case '\f': OS << "\\f"; break; - case '\n': OS << "\\n"; break; - case '\r': OS << "\\r"; break; - case '\t': OS << "\\t"; break; + switch (C) { + case '\b': + OS << "\\b"; + break; + case '\f': + OS << "\\f"; + break; + case '\n': + OS << "\\n"; + break; + case '\r': + OS << "\\r"; + break; + case '\t': + OS << "\\t"; + break; default: OS << '\\'; OS << toOctal(C >> 6); OS << toOctal(C >> 3); OS << toOctal(C >> 0); break; + } } } @@ -1391,12 +1417,10 @@ void MCAsmStreamer::emitFileDirective(StringRef Filename) { EmitEOL(); } -static void printDwarfFileDirective(unsigned FileNo, StringRef Directory, - StringRef Filename, - Optional<MD5::MD5Result> Checksum, - Optional<StringRef> Source, - bool UseDwarfDirectory, - raw_svector_ostream &OS) { +void MCAsmStreamer::printDwarfFileDirective( + unsigned FileNo, StringRef Directory, StringRef Filename, + Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source, + bool UseDwarfDirectory, raw_svector_ostream &OS) { SmallString<128> FullPathName; if (!UseDwarfDirectory && !Directory.empty()) { diff --git a/llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll b/llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll new file mode 100644 index 0000000000000..05ef566bcf093 --- /dev/null +++ b/llvm/test/CodeGen/PowerPC/aix-filename-special-character-double-quotation.ll @@ -0,0 +1,8 @@ +; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff < %s \ +; RUN: | FileCheck %s +; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff < %s \ +; RUN: | FileCheck %s + +; CHECK: .file "1""2.c" + +source_filename = "1\222.c" diff --git a/llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll b/llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll new file mode 100644 index 0000000000000..a600494e151b4 --- /dev/null +++ b/llvm/test/CodeGen/PowerPC/aix-filename-special-character-single-quotation.ll @@ -0,0 +1,8 @@ +; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff < %s \ +; RUN: | FileCheck %s +; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff < %s \ +; RUN: | FileCheck %s + +; CHECK: .file "1'2.c" + +source_filename = "1'2.c" _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits