This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][SPARC] gas: fix CBCOND diagnostics for invalid immediate operands.


This patch fixes two problems in the SPARC assembler:
    
- The diagnostic message
  
  Error: Illegal operands: Immediate value in cbcond is out of range.

  is incorrectly issued for non-CBCOND instructions that feature a simm5
  immediate field, such as MPMUL, MONTMUL, etc.
    
- When an invalid immediate operand is used in a CBCOND instruction, two
  redundant error messages are issued to the user, the second due to a
  stale fixup (this happens since commit
  85024cd8bcb93f4112470ecdbd6c10fc2aea724f).
    
Some diagnostic tests for the CBCOND instructions are also included.

Tested in both sparc64-linux-gnu and sparcv9-linux-gnu targets.
    
gas/ChangeLog:
    
2016-11-16  Jose E. Marchesi  <jose.marchesi@oracle.com>
    
    	* config/tc-sparc.c (sparc_ip): Avoid emitting a cbcond error
    	messages for non-cbcond instructions.
    	* testsuite/gas/sparc/cbcond-diag.s: New file.
    	* testsuite/gas/sparc/cbcond-diag.l: Likewise.
    	* testsuite/gas/sparc/sparc.exp (gas_64_check): Run cbcond-diag tests.

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 613833b..3847a4a 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,11 @@
+2016-11-16  Jose E. Marchesi  <jose.marchesi@oracle.com>
+
+	* config/tc-sparc.c (sparc_ip): Avoid emitting a cbcond error
+	messages for non-cbcond instructions.
+	* testsuite/gas/sparc/cbcond-diag.s: New file.
+	* testsuite/gas/sparc/cbcond-diag.l: Likewise.
+	* testsuite/gas/sparc/sparc.exp (gas_64_check): Run cbcond-diag tests.
+
 2016-11-15  Nick Clifton  <nickc@redhat.com>
 
 	PR gas/20803
diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c
index d7b9a98..4f8a89c 100644
--- a/gas/config/tc-sparc.c
+++ b/gas/config/tc-sparc.c
@@ -2945,17 +2945,18 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		     handle the R_SPARC_5 immediate directly here so that
 		     we don't need to add support for multiple relocations
 		     in one instruction just yet.  */
-		  if (the_insn.reloc == BFD_RELOC_SPARC_5)
+		  if (the_insn.reloc == BFD_RELOC_SPARC_5
+                      && ((insn->match & OP(0x3)) == 0))
 		    {
 		      valueT val = the_insn.exp.X_add_number;
 
+		      the_insn.reloc = BFD_RELOC_NONE;
 		      if (! in_bitfield_range (val, 0x1f))
 			{
 			  error_message = _(": Immediate value in cbcond is out of range.");
 			  goto error;
 			}
 		      opcode |= val & 0x1f;
-		      the_insn.reloc = BFD_RELOC_NONE;
 		    }
 		}
 
diff --git a/gas/testsuite/gas/sparc/cbcond-diag.l b/gas/testsuite/gas/sparc/cbcond-diag.l
new file mode 100644
index 0000000..070c849
--- /dev/null
+++ b/gas/testsuite/gas/sparc/cbcond-diag.l
@@ -0,0 +1,3 @@
+.*cbcond-diag.s: Assembler messages:
+.*cbcond-diag.s:3: Error: .*Immediate value in cbcond is out of range\.
+.*cbcond-diag.s:4: Error: .*Immediate value in cbcond is out of range\.
diff --git a/gas/testsuite/gas/sparc/cbcond-diag.s b/gas/testsuite/gas/sparc/cbcond-diag.s
new file mode 100644
index 0000000..c963afb
--- /dev/null
+++ b/gas/testsuite/gas/sparc/cbcond-diag.s
@@ -0,0 +1,5 @@
+# Test error conditions in CBCOND instructions
+        .text
+        cwbe	%o1, +32,1f ! Overflow in the simm5 field.
+        cwbe	%o1, -17,1f ! Likewise.
+1:      nop
diff --git a/gas/testsuite/gas/sparc/sparc.exp b/gas/testsuite/gas/sparc/sparc.exp
index 580656f..316c07d 100644
--- a/gas/testsuite/gas/sparc/sparc.exp
+++ b/gas/testsuite/gas/sparc/sparc.exp
@@ -53,6 +53,7 @@ if [istarget sparc*-*-*] {
         run_dump_test "pause"
         run_dump_test "save-args"
         run_dump_test "cbcond"
+        run_list_test "cbcond-diag"
         run_dump_test "cfr"
         run_dump_test "crypto"
         run_dump_test "edge"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]