[PATCH] D38750: AMDGPU: Improve note directive verification in assembler

Konstantin Zhuravlyov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 11:32:47 PDT 2017


kzhuravl created this revision.
Herald added subscribers: dstuttard, yaxunl, nhaehnle, wdng, arsenm.

- Do not allow amd_amdgpu_isa directives on non-amdgcn architectures
- Do not allow amd_amdgpu_hsa_metadata on non-amdhsa OSes
- Do not allow amd_amdgpu_pal_metadata on non-amdpal OSes


https://reviews.llvm.org/D38750

Files:
  lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
  test/MC/AMDGPU/elf-notes-verify-amdgcn.s
  test/MC/AMDGPU/elf-notes-verify-r600.s


Index: test/MC/AMDGPU/elf-notes-verify-r600.s
===================================================================
--- /dev/null
+++ test/MC/AMDGPU/elf-notes-verify-r600.s
@@ -0,0 +1,10 @@
+// RUN: not llvm-mc -arch r600 %s 2>&1 | FileCheck --check-prefix=R600 %s
+
+// R600: error: .amd_amdgpu_isa directive is not available on non-amdgcn architectures
+.amd_amdgpu_isa "r600"
+
+// R600: error: .amd_amdgpu_hsa_metadata directive is not available on non-amdhsa OSes
+.amd_amdgpu_hsa_metadata
+
+// R600: error: .amd_amdgpu_pal_metadata directive is not available on non-amdpal OSes
+.amd_amdgpu_pal_metadata
Index: test/MC/AMDGPU/elf-notes-verify-amdgcn.s
===================================================================
--- /dev/null
+++ test/MC/AMDGPU/elf-notes-verify-amdgcn.s
@@ -0,0 +1,7 @@
+// RUN: not llvm-mc -arch amdgcn %s 2>&1 | FileCheck --check-prefix=GCN %s
+
+// GCN: error: .amd_amdgpu_hsa_metadata directive is not available on non-amdhsa OSes
+.amd_amdgpu_hsa_metadata
+
+// GCN: error: .amd_amdgpu_pal_metadata directive is not available on non-amdpal OSes
+.amd_amdgpu_pal_metadata
Index: lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
===================================================================
--- lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -2455,6 +2455,12 @@
 }
 
 bool AMDGPUAsmParser::ParseDirectiveISAVersion() {
+  if (getSTI().getTargetTriple().getArch() != Triple::amdgcn) {
+    return Error(getParser().getTok().getLoc(),
+                 ".amd_amdgpu_isa directive is not available on non-amdgcn "
+                 "architectures");
+  }
+
   auto ISAVersionFromASM = getLexer().getTok().getStringContents();
   auto ISAVersionFromSTI = IsaInfo::getIsaVersionString(&getSTI());
 
@@ -2471,6 +2477,12 @@
 }
 
 bool AMDGPUAsmParser::ParseDirectiveHSAMetadata() {
+  if (getSTI().getTargetTriple().getOS() != Triple::AMDHSA) {
+    return Error(getParser().getTok().getLoc(),
+                 (Twine(HSAMD::AssemblerDirectiveBegin) + Twine(" directive is "
+                 "not available on non-amdhsa OSes")).str());
+  }
+
   std::string HSAMetadataString;
   raw_string_ostream YamlStream(HSAMetadataString);
 
@@ -2502,7 +2514,7 @@
 
   if (getLexer().is(AsmToken::Eof) && !FoundEnd) {
     return TokError(Twine("expected directive ") +
-                    Twine(HSAMD::AssemblerDirectiveEnd) + Twine("not found"));
+                    Twine(HSAMD::AssemblerDirectiveEnd) + Twine(" not found"));
   }
 
   YamlStream.flush();
@@ -2514,6 +2526,12 @@
 }
 
 bool AMDGPUAsmParser::ParseDirectivePALMetadata() {
+  if (getSTI().getTargetTriple().getOS() != Triple::AMDPAL) {
+    return Error(getParser().getTok().getLoc(),
+                 (Twine(PALMD::AssemblerDirective) + Twine(" directive is "
+                 "not available on non-amdpal OSes")).str());
+  }
+
   PALMD::Metadata PALMetadata;
   for (;;) {
     uint32_t Value;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38750.118439.patch
Type: text/x-patch
Size: 2948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171010/566ada85/attachment.bin>


More information about the llvm-commits mailing list