]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
aarch64: Add qualifier checks to aarch64-gen
authorAlice Carlotti <alice.carlotti@arm.com>
Mon, 10 Mar 2025 15:32:11 +0000 (15:32 +0000)
committerAlice Carlotti <alice.carlotti@arm.com>
Fri, 15 May 2026 14:07:20 +0000 (15:07 +0100)
Add checks to verify that all qualifier sequences have the correct
length.

opcodes/aarch64-gen.c

index 1988879da81036611c9f65e29c9ccf79fc03f6e3..d989c55752390939ae0ddcdecdf0fd7dc9628909 100644 (file)
@@ -150,6 +150,11 @@ read_table (const struct aarch64_opcode* table)
     {
       bool match = false;
 
+      unsigned int operand_count = 0;
+      while (operand_count < ARRAY_SIZE (ent->operands)
+            && ent->operands[operand_count] != AARCH64_OPND_NIL)
+       operand_count++;
+
       /* F_PSEUDO needs to be used together with F_ALIAS to indicate an alias
         opcode is a programmer friendly pseudo instruction available only in
         the assembly code (thus will not show up in the disassembly).  */
@@ -189,6 +194,47 @@ read_table (const struct aarch64_opcode* table)
          ++errors;
        }
 
+      /* Check that the qualifier sequence lengths match the number of
+        operands.  */
+      bool qlf_end = false;
+      for (unsigned int i = 0; i < ARRAY_SIZE (ent->qualifiers_list); i++)
+       {
+         for (unsigned int j = 0; j < ARRAY_SIZE (ent->qualifiers_list[0]); j++)
+           {
+             if (j >= operand_count || qlf_end)
+               {
+                 if (ent->qualifiers_list[i][j] != AARCH64_OPND_QLF_UNUSED)
+                   {
+                     fprintf (stderr,
+                              "%s (%08x,%08x): Qualifier %u for sequence %u should be UNUSED.\n",
+                              ent->name, ent->opcode, ent->mask, j, i);
+                     ++errors;
+                   }
+               }
+             else if (ent->qualifiers_list[i][j] == AARCH64_OPND_QLF_UNUSED)
+               {
+                 if (j == 0)
+                   {
+                     qlf_end = true;
+                     if (i == 0 && operand_count > 0)
+                       {
+                         fprintf (stderr,
+                                  "%s (%08x,%08x): No qualifiers specified.\n",
+                                  ent->name, ent->opcode, ent->mask);
+                         ++errors;
+                       }
+                   }
+                 else
+                   {
+                     fprintf (stderr,
+                              "%s (%08x,%08x): Qualifier %u for sequence %u is missing.\n",
+                              ent->name, ent->opcode, ent->mask, j, i);
+                     ++errors;
+                   }
+               }
+           }
+       }
+
       if (ent->flags & F_SUBCLASS)
        iclass_has_subclasses_p[ent->iclass] = true;