From: green Date: Thu, 7 Oct 1999 13:26:01 +0000 (+0000) Subject: During class file generation, generate_classfile occasionally writes X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ef723827ce2cbe0c4dec622c8d6fadd601678176;p=platform%2Fupstream%2Flinaro-gcc.git During class file generation, generate_classfile occasionally writes out a bunch of data and then skips backwards to fill in blanks. When configured with --enable-checking, this patching up will often trip the checking code. This change introduces UNSAFE_PUTx macros which never use CHECK_PUT. These should only be used in cases we know CHECK_PUT will fail. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@29854 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 18030fc..00ea759 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,11 @@ +1999-10-07 Anthony Green + + * jcf-write.c (generate_classfile): Use UNSAFE_PUTx in cases + where CHECK_PUT may fail for valid reasons. + + * jcf-write.c (UNSAFE_PUT1, UNSAFE_PUT2, UNSAFE_PUT3, + UNSAFE_PUTN): New macros. + 1999-10-04 Tom Tromey * lex.h (BUILD_OPERATOR2): Return ASSIGN_ANY_TK in `lite' case as diff --git a/gcc/java/jcf-write.c b/gcc/java/jcf-write.c index 91567d0..5918757 100644 --- a/gcc/java/jcf-write.c +++ b/gcc/java/jcf-write.c @@ -358,6 +358,13 @@ CHECK_PUT(ptr, state, i) #define PUT4(X) (PUT2((X) >> 16), PUT2((X) & 0xFFFF)) #define PUTN(P, N) (CHECK_PUT(ptr, state, N), memcpy(ptr, P, N), ptr += (N)) +/* There are some cases below where CHECK_PUT is guaranteed to fail. + Use the following macros in those specific cases. */ +#define UNSAFE_PUT1(X) (*ptr++ = (X)) +#define UNSAFE_PUT2(X) (UNSAFE_PUT1((X) >> 8), UNSAFE_PUT1((X) & 0xFF)) +#define UNSAFE_PUT4(X) (UNSAFE_PUT2((X) >> 16), UNSAFE_PUT2((X) & 0xFFFF)) +#define UNSAFE_PUTN(P, N) (memcpy(ptr, P, N), ptr += (N)) + /* Allocate a new chunk on obstack WORK, and link it in after LAST. Set the data and size fields to DATA and SIZE, respectively. @@ -2807,7 +2814,7 @@ generate_classfile (clas, state) } fields_count++; } - ptr = fields_count_ptr; PUT2 (fields_count); + ptr = fields_count_ptr; UNSAFE_PUT2 (fields_count); ptr = methods_count_ptr = append_chunk (NULL, 2, state); PUT2 (0); @@ -2873,10 +2880,10 @@ generate_classfile (clas, state) code_attributes_count++; i += 8 + 10 * state->lvar_count; } - PUT4 (i); /* attribute_length */ - PUT2 (state->code_SP_max); /* max_stack */ - PUT2 (localvar_max); /* max_locals */ - PUT4 (state->code_length); + UNSAFE_PUT4 (i); /* attribute_length */ + UNSAFE_PUT2 (state->code_SP_max); /* max_stack */ + UNSAFE_PUT2 (localvar_max); /* max_locals */ + UNSAFE_PUT4 (state->code_length); /* Emit the exception table. */ ptr = append_chunk (NULL, 2 + 8 * state->num_handlers, state); @@ -2966,7 +2973,7 @@ generate_classfile (clas, state) methods_count++; current_function_decl = save_function; } - ptr = methods_count_ptr; PUT2 (methods_count); + ptr = methods_count_ptr; UNSAFE_PUT2 (methods_count); source_file = DECL_SOURCE_FILE (TYPE_NAME (clas)); for (ptr = source_file; ; ptr++)