diff options
-rw-r--r-- | llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp | 2 | ||||
-rw-r--r-- | llvm/test/MC/RISCV/data-directives-invalid.s | 23 | ||||
-rw-r--r-- | llvm/test/MC/RISCV/data-directives-valid.s | 32 |
4 files changed, 61 insertions, 0 deletions
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index 487eea14b16..c51e4b3c606 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -105,6 +105,10 @@ public: RISCVAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser, const MCInstrInfo &MII, const MCTargetOptions &Options) : MCTargetAsmParser(Options, STI, MII) { + Parser.addAliasForDirective(".half", ".2byte"); + Parser.addAliasForDirective(".hword", ".2byte"); + Parser.addAliasForDirective(".word", ".4byte"); + Parser.addAliasForDirective(".dword", ".8byte"); setAvailableFeatures(ComputeAvailableFeatures(STI.getFeatureBits())); } }; diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp index d622911e92c..780dae410cd 100644 --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp @@ -22,4 +22,6 @@ RISCVMCAsmInfo::RISCVMCAsmInfo(const Triple &TT) { CommentString = "#"; AlignmentIsInBytes = false; SupportsDebugInformation = true; + Data16bitsDirective = "\t.half\t"; + Data32bitsDirective = "\t.word\t"; } diff --git a/llvm/test/MC/RISCV/data-directives-invalid.s b/llvm/test/MC/RISCV/data-directives-invalid.s new file mode 100644 index 00000000000..6618cd17fa2 --- /dev/null +++ b/llvm/test/MC/RISCV/data-directives-invalid.s @@ -0,0 +1,23 @@ +# RUN: not llvm-mc -triple riscv32 < %s 2>&1 | FileCheck %s +# RUN: not llvm-mc -triple riscv64 < %s 2>&1 | FileCheck %s + +# CHECK: [[@LINE+1]]:7: error: out of range literal value in '.byte' directive +.byte 0xffa +# CHECK: [[@LINE+1]]:7: error: out of range literal value in '.half' directive +.half 0xffffa +# CHECK: [[@LINE+1]]:8: error: out of range literal value in '.short' directive +.short 0xffffa +# CHECK: [[@LINE+1]]:8: error: out of range literal value in '.hword' directive +.hword 0xffffa +# CHECK: [[@LINE+1]]:8: error: out of range literal value in '.2byte' directive +.2byte 0xffffa +# CHECK: [[@LINE+1]]:7: error: out of range literal value in '.word' directive +.word 0xffffffffa +# CHECK: [[@LINE+1]]:7: error: out of range literal value in '.long' directive +.long 0xffffffffa +# CHECK: [[@LINE+1]]:8: error: out of range literal value in '.4byte' directive +.4byte 0xffffffffa +# CHECK: [[@LINE+1]]:8: error: literal value out of range for directive in '.dword' directive +.dword 0xffffffffffffffffa +# CHECK: [[@LINE+1]]:8: error: literal value out of range for directive in '.8byte' directive +.8byte 0xffffffffffffffffa diff --git a/llvm/test/MC/RISCV/data-directives-valid.s b/llvm/test/MC/RISCV/data-directives-valid.s new file mode 100644 index 00000000000..ece7f096f16 --- /dev/null +++ b/llvm/test/MC/RISCV/data-directives-valid.s @@ -0,0 +1,32 @@ +# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \ +# RUN: | llvm-objdump -s - | FileCheck %s +# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \ +# RUN: | llvm-objdump -s - | FileCheck %s + +# Check that data directives supported by gas are also supported by LLVM MC. +# As there was some confusion about whether .half/.word/.dword imply +# alignment (see <https://github.com/riscv/riscv-asm-manual/issues/12>), we +# are sure to check this. + +.data + +# CHECK: Contents of section .data: +# CHECK-NEXT: 0000 deadbeef badcaf11 22334455 66778800 +.byte 0xde +.half 0xbead +.word 0xafdcbaef +.dword 0x8877665544332211 +.byte 0 + +# CHECK-NEXT: 0010 deadbeef badcaf11 22334455 66778800 +.byte 0xde +.2byte 0xbead +.4byte 0xafdcbaef +.8byte 0x8877665544332211 +.byte 0 + +# CHECK-NEXT: 0020 deadbeef badcaf11 22 +.byte 0xde +.short 0xbead +.long 0xafdcbaef +.hword 0x2211 |