* Re: [patch] read-rtx.c: validate constants
2001-11-13 15:03 ` Richard Henderson
@ 2001-11-13 15:03 ` DJ Delorie
0 siblings, 0 replies; 5+ messages in thread
From: DJ Delorie @ 2001-11-13 15:03 UTC (permalink / raw)
To: rth; +Cc: gcc-patches
> On Mon, Nov 19, 2001 at 01:19:00AM -0500, DJ Delorie wrote:
> > + fprintf (stderr, "invalid decimal constant \"%s\"\n", string);
> > + abort();
>
> Use fatal_with_file_and_line. Otherwise ok.
Thanks! Applied.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] read-rtx.c: validate constants
2001-11-13 15:03 [patch] read-rtx.c: validate constants DJ Delorie
@ 2001-11-13 15:03 ` Richard Henderson
2001-11-13 15:03 ` DJ Delorie
0 siblings, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2001-11-13 15:03 UTC (permalink / raw)
To: DJ Delorie; +Cc: gcc-patches
On Mon, Nov 19, 2001 at 01:19:00AM -0500, DJ Delorie wrote:
> + fprintf (stderr, "invalid decimal constant \"%s\"\n", string);
> + abort();
Use fatal_with_file_and_line. Otherwise ok.
r~
^ permalink raw reply [flat|nested] 5+ messages in thread
* [patch] read-rtx.c: validate constants
@ 2001-11-13 15:03 DJ Delorie
2001-11-13 15:03 ` Richard Henderson
0 siblings, 1 reply; 5+ messages in thread
From: DJ Delorie @ 2001-11-13 15:03 UTC (permalink / raw)
To: gcc-patches; +Cc: dj
It would be better to allow hex constants (which is a task unto
itself), but we'd still need to validate that the given string is a
valid constant. Bootstrapped on ix86-linux.
2001-11-19 DJ Delorie <dj@redhat.com>
* read-rtl.c (ISDIGIT, ISSPACE): Make sure we have these.
(validate_const_int): New.
(read_rtx): Validate constant integers.
* config/i386/i386.md (pmulhrwv4hi3): Use decimal constants.
Index: read-rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/read-rtl.c,v
retrieving revision 1.6
diff -p -3 -r1.6 read-rtl.c
*** read-rtl.c 2001/10/11 03:15:55 1.6
--- read-rtl.c 2001/11/19 05:51:49
*************** Software Foundation, 59 Temple Place - S
*** 25,30 ****
--- 25,36 ----
#include "obstack.h"
#include "hashtab.h"
+ #ifndef ISDIGIT
+ #include <ctype.h>
+ #define ISDIGIT isdigit
+ #define ISSPACE isspace
+ #endif
+
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
*************** static void read_escape PARAMS ((struct
*** 41,46 ****
--- 47,53 ----
static unsigned def_hash PARAMS ((const void *));
static int def_name_eq_p PARAMS ((const void *, const void *));
static void read_constants PARAMS ((FILE *infile, char *tmp_char));
+ static void validate_const_int PARAMS ((const char *));
/* Subroutines of read_rtx. */
*************** traverse_md_constants (callback, info)
*** 494,499 ****
--- 501,530 ----
htab_traverse (md_constants, callback, info);
}
+ static void
+ validate_const_int (string)
+ const char *string;
+ {
+ const char *cp;
+ int valid = 1;
+
+ cp = string;
+ while (*cp && ISSPACE(*cp))
+ cp++;
+ if (*cp == '-' || *cp == '+')
+ cp++;
+ if (*cp == 0)
+ valid = 0;
+ for (; *cp; cp++)
+ if (! ISDIGIT (*cp))
+ valid = 0;
+ if (!valid)
+ {
+ fprintf (stderr, "invalid decimal constant \"%s\"\n", string);
+ abort();
+ }
+ }
+
/* Read an rtx in printed representation from INFILE
and return an actual rtx in core constructed accordingly.
read_rtx is not used in the compiler proper, but rather in
*************** again:
*** 699,704 ****
--- 730,736 ----
case 'w':
read_name (tmp_char, infile);
+ validate_const_int(tmp_char);
#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
tmp_wide = atoi (tmp_char);
#else
*************** again:
*** 720,725 ****
--- 752,758 ----
case 'i':
case 'n':
read_name (tmp_char, infile);
+ validate_const_int(tmp_char);
tmp_int = atoi (tmp_char);
XINT (return_rtx, i) = tmp_int;
break;
Index: config/i386/i386.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.md,v
retrieving revision 1.314
diff -p -3 -r1.314 i386.md
*** i386.md 2001/11/16 19:58:40 1.314
--- i386.md 2001/11/19 05:51:51
***************
*** 19676,19685 ****
(sign_extend:V4SI
(match_operand:V4HI 2 "nonimmediate_operand" "ym")))
(vec_const:V4SI
! (parallel [(const_int 0x8000)
! (const_int 0x8000)
! (const_int 0x8000)
! (const_int 0x8000)])))
(const_int 16))))]
"TARGET_3DNOW"
"pmulhrw\\t{%2, %0|%0, %2}"
--- 19676,19685 ----
(sign_extend:V4SI
(match_operand:V4HI 2 "nonimmediate_operand" "ym")))
(vec_const:V4SI
! (parallel [(const_int 32768)
! (const_int 32768)
! (const_int 32768)
! (const_int 32768)])))
(const_int 16))))]
"TARGET_3DNOW"
"pmulhrw\\t{%2, %0|%0, %2}"
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] read-rtx.c: validate constants
@ 2001-11-13 15:03 Kaveh R. Ghazi
2001-11-13 15:03 ` DJ Delorie
0 siblings, 1 reply; 5+ messages in thread
From: Kaveh R. Ghazi @ 2001-11-13 15:03 UTC (permalink / raw)
To: dj; +Cc: gcc-patches, rth
> 2001-11-19 DJ Delorie <dj@redhat.com>
>
> * read-rtl.c (ISDIGIT, ISSPACE): Make sure we have these.
>
> Index: read-rtl.c
> ===================================================================
> RCS file: /cvs/gcc/gcc/gcc/read-rtl.c,v
> retrieving revision 1.6
> diff -p -3 -r1.6 read-rtl.c
> *** read-rtl.c 2001/10/11 03:15:55 1.6
> --- read-rtl.c 2001/11/19 05:51:49
> *************** Software Foundation, 59 Temple Place - S
> *** 25,30 ****
> --- 25,36 ----
> #include "obstack.h"
> #include "hashtab.h"
>
> + #ifndef ISDIGIT
> + #include <ctype.h>
> + #define ISDIGIT isdigit
> + #define ISSPACE isspace
> + #endif
I'm pretty sure this hunk is not needed, you should rely on
safe-ctype.h (from system.h) here. Gcc arranges for a "build" copy of
safe-ctype.o to be linked in to the "generator" programs too.
--Kaveh
--
Kaveh R. Ghazi Engagement Manager / Project Services
ghazi@caip.rutgers.edu Qwest Internet Solutions
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] read-rtx.c: validate constants
2001-11-13 15:03 Kaveh R. Ghazi
@ 2001-11-13 15:03 ` DJ Delorie
0 siblings, 0 replies; 5+ messages in thread
From: DJ Delorie @ 2001-11-13 15:03 UTC (permalink / raw)
To: ghazi; +Cc: gcc-patches
> I'm pretty sure this hunk is not needed, you should rely on
> safe-ctype.h (from system.h) here. Gcc arranges for a "build" copy of
> safe-ctype.o to be linked in to the "generator" programs too.
Another one of those? I guess a build-libiberty should be next on my
to-do list, then ;-)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-11-20 5:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-13 15:03 [patch] read-rtx.c: validate constants DJ Delorie
2001-11-13 15:03 ` Richard Henderson
2001-11-13 15:03 ` DJ Delorie
2001-11-13 15:03 Kaveh R. Ghazi
2001-11-13 15:03 ` DJ Delorie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).