]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Fix undefinedness while testing the J constraint [PR100204]
authorAndrew Pinski <quic_apinski@quicinc.com>
Thu, 25 Jan 2024 16:30:36 +0000 (08:30 -0800)
committerAndrew Pinski <quic_apinski@quicinc.com>
Thu, 25 Jan 2024 19:57:48 +0000 (11:57 -0800)
The J constraint can invoke undefined behavior due to it taking the
negative of the ival if ival was HWI_MIN. The fix is simple as casting
to `unsigned HOST_WIDE_INT` before doing the negative of it. This
does that.

Committed as obvious after build/test for aarch64-linux-gnu.

gcc/ChangeLog:

PR target/100204
* config/aarch64/constraints.md (J): Cast to `unsigned HOST_WIDE_INT`
before taking the negative of it.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/config/aarch64/constraints.md

index 8566befd72716283faea437f412abdf448440cbf..a2569cea51022a1e6f7a95dc9a59b0005dcb52b5 100644 (file)
 (define_constraint "J"
  "A constant that can be used with a SUB operation (once negated)."
  (and (match_code "const_int")
-      (match_test "aarch64_uimm12_shift (-ival)")))
+      (match_test "aarch64_uimm12_shift (- (unsigned HOST_WIDE_INT) ival)")))
 
 ;; We can't use the mode of a CONST_INT to determine the context in
 ;; which it is being used, so we must have a separate constraint for