summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2003-10-22 22:28:39 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2003-10-22 22:28:39 +0000
commit129b92e3c54bdc7af2c68e0476f46822d871ea5c (patch)
tree28a0768008d74d4ffb87685f8213007c87501bc9
parent25fef833118e46c37def3c7bbb2769cf2cdd942e (diff)
downloadgcc-129b92e3c54bdc7af2c68e0476f46822d871ea5c.tar.gz
include:
* obstack.h: Merge the following change from gnulib: 2003-10-21 Paul Eggert <eggert@twinsun.com> * obstack.h (obstack_1grow_fast): Properly parenthesize arg. (obstack_ptr_grow_fast, obstack_int_grow_fast): Don't use lvalue casts, as GCC plans to remove support for them in GCC 3.5. Reported by Joseph S. Myers. This bug was also present in the non-GCC version, indicating that this code had always been buggy and had never been widely used. (obstack_1grow, obstack_ptr_grow, obstack_int_grow, obstack_blank): Use the fast variant of each macro, rather than copying the definiens of the fast variant; that way, we'll be more likely to catch future bugs in the fast variants. gcc: * c-typeck.c (pedantic_lvalue_warning): Unconditionally warn of deprecation of casts as lvalues. * fixinc/inclhack.def (obstack_lvalue_cast): New fix. * fixinc/fixincl.x: Regenerate. * fixinc/tests/base/obstack.h: New test. gcc/testsuite: * gcc.dg/cast-lvalue-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@72826 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/c-typeck.c23
-rw-r--r--gcc/fixinc/fixincl.x51
-rw-r--r--gcc/fixinc/inclhack.def25
-rw-r--r--gcc/fixinc/tests/base/obstack.h14
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/cast-lvalue-1.c12
-rw-r--r--include/ChangeLog15
-rw-r--r--include/obstack.h40
9 files changed, 162 insertions, 30 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a3df896b9c2..5cf4a4bc2bc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2003-10-22 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ * c-typeck.c (pedantic_lvalue_warning): Unconditionally warn of
+ deprecation of casts as lvalues.
+ * fixinc/inclhack.def (obstack_lvalue_cast): New fix.
+ * fixinc/fixincl.x: Regenerate.
+ * fixinc/tests/base/obstack.h: New test.
+
2003-10-22 Andreas Schwab <schwab@suse.de>
PR target/12676
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index eaad4fe9698..598e249d947 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -2585,19 +2585,20 @@ unary_complex_lvalue (enum tree_code code, tree arg, int flag)
static void
pedantic_lvalue_warning (enum tree_code code)
{
- if (pedantic)
- switch (code)
- {
- case COND_EXPR:
+ switch (code)
+ {
+ case COND_EXPR:
+ if (pedantic)
pedwarn ("ISO C forbids use of conditional expressions as lvalues");
- break;
- case COMPOUND_EXPR:
+ break;
+ case COMPOUND_EXPR:
+ if (pedantic)
pedwarn ("ISO C forbids use of compound expressions as lvalues");
- break;
- default:
- pedwarn ("ISO C forbids use of cast expressions as lvalues");
- break;
- }
+ break;
+ default:
+ pedwarn ("use of cast expressions as lvalues is deprecated");
+ break;
+ }
}
/* Warn about storing in something that is `const'. */
diff --git a/gcc/fixinc/fixincl.x b/gcc/fixinc/fixincl.x
index 609fc62f3ef..5aa85b2a310 100644
--- a/gcc/fixinc/fixincl.x
+++ b/gcc/fixinc/fixincl.x
@@ -2,11 +2,11 @@
*
* DO NOT EDIT THIS FILE (fixincl.x)
*
- * It has been AutoGen-ed Monday October 20, 2003 at 01:29:54 PM PDT
+ * It has been AutoGen-ed Wednesday October 22, 2003 at 10:23:00 PM UTC
* From the definitions inclhack.def
* and the template file fixincl
*/
-/* DO NOT CVS-MERGE THIS FILE, EITHER Mon Oct 20 13:29:54 PDT 2003
+/* DO NOT CVS-MERGE THIS FILE, EITHER Wed Oct 22 22:23:00 UTC 2003
*
* You must regenerate it. Use the ./genfixes script.
*
@@ -15,7 +15,7 @@
* certain ANSI-incompatible system header files which are fixed to work
* correctly with ANSI C and placed in a directory that GNU C will search.
*
- * This file contains 160 fixup descriptions.
+ * This file contains 161 fixup descriptions.
*
* See README for more information.
*
@@ -3571,6 +3571,41 @@ static const char* apzNodeent_SyntaxPatch[] = {
/* * * * * * * * * * * * * * * * * * * * * * * * * *
*
+ * Description of Obstack_Lvalue_Cast fix
+ */
+tSCC zObstack_Lvalue_CastName[] =
+ "obstack_lvalue_cast";
+
+/*
+ * File name selection pattern
+ */
+tSCC zObstack_Lvalue_CastList[] =
+ "|obstack.h|";
+/*
+ * Machine/OS name selection pattern
+ */
+#define apzObstack_Lvalue_CastMachs (const char**)NULL
+
+/*
+ * content selection pattern - do fix if pattern found
+ */
+tSCC zObstack_Lvalue_CastSelect0[] =
+ "\\*\\(\\(([^()]*)\\*\\)(.*)\\)\\+\\+ = \\(([^()]*)\\)";
+
+#define OBSTACK_LVALUE_CAST_TEST_CT 1
+static tTestDesc aObstack_Lvalue_CastTests[] = {
+ { TT_EGREP, zObstack_Lvalue_CastSelect0, (regex_t*)NULL }, };
+
+/*
+ * Fix Command Arguments for Obstack_Lvalue_Cast
+ */
+static const char* apzObstack_Lvalue_CastPatch[] = {
+ "format",
+ "((*((%1*)%2) = (%3)), (%2 += sizeof (%1)))",
+ (char*)NULL };
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * *
+ *
* Description of Osf_Namespace_A fix
*/
tSCC zOsf_Namespace_AName[] =
@@ -6344,9 +6379,9 @@ static const char* apzX11_SprintfPatch[] = {
*
* List of all fixes
*/
-#define REGEX_COUNT 180
+#define REGEX_COUNT 181
#define MACH_LIST_SIZE_LIMIT 261
-#define FIX_COUNT 160
+#define FIX_COUNT 161
/*
* Enumerate the fixes
@@ -6440,6 +6475,7 @@ typedef enum {
NEXT_VOLITILE_FIXIDX,
NEXT_WAIT_UNION_FIXIDX,
NODEENT_SYNTAX_FIXIDX,
+ OBSTACK_LVALUE_CAST_FIXIDX,
OSF_NAMESPACE_A_FIXIDX,
OSF_NAMESPACE_C_FIXIDX,
PTHREAD_PAGE_SIZE_FIXIDX,
@@ -6955,6 +6991,11 @@ tFixDesc fixDescList[ FIX_COUNT ] = {
NODEENT_SYNTAX_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
aNodeent_SyntaxTests, apzNodeent_SyntaxPatch, 0 },
+ { zObstack_Lvalue_CastName, zObstack_Lvalue_CastList,
+ apzObstack_Lvalue_CastMachs,
+ OBSTACK_LVALUE_CAST_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
+ aObstack_Lvalue_CastTests, apzObstack_Lvalue_CastPatch, 0 },
+
{ zOsf_Namespace_AName, zOsf_Namespace_AList,
apzOsf_Namespace_AMachs,
OSF_NAMESPACE_A_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
diff --git a/gcc/fixinc/inclhack.def b/gcc/fixinc/inclhack.def
index 45a0bb8f732..2f285f5205e 100644
--- a/gcc/fixinc/inclhack.def
+++ b/gcc/fixinc/inclhack.def
@@ -1997,6 +1997,31 @@ fix = {
/*
+ * obstack.h used casts as lvalues.
+ *
+ * We need to change postincrements of casted pointers (which are
+ * then dereferenced and assigned into) of the form
+ *
+ * *((TYPE*)PTRVAR)++ = (VALUE)
+ *
+ * into expressions like
+ *
+ * ((*((TYPE*)PTRVAR) = (VALUE)), (PTRVAR += sizeof (TYPE)))
+ *
+ * which is correct for the cases used in obstack.h since PTRVAR is
+ * of type char * and the value of the expression is not used.
+ */
+fix = {
+ hackname = obstack_lvalue_cast;
+ files = obstack.h;
+ select = '\*\(\(([^()]*)\*\)(.*)\)\+\+ = \(([^()]*)\)';
+ c_fix = format;
+ c_fix_arg = "((*((%1*)%2) = (%3)), (%2 += sizeof (%1)))";
+ test_text = "*((void **) (h)->next_free)++ = (aptr)";
+};
+
+
+/*
* sys/lc_core.h on some versions of OSF1/4.x pollutes the namespace by
* defining regex.h related types. This causes libg++ build and usage
* failures. Fixing this correctly requires checking and modifying 3 files.
diff --git a/gcc/fixinc/tests/base/obstack.h b/gcc/fixinc/tests/base/obstack.h
new file mode 100644
index 00000000000..ea8e8dd1e32
--- /dev/null
+++ b/gcc/fixinc/tests/base/obstack.h
@@ -0,0 +1,14 @@
+/* DO NOT EDIT THIS FILE.
+
+ It has been auto-edited by fixincludes from:
+
+ "fixinc/tests/inc/obstack.h"
+
+ This had to be done to correct non-standard usages in the
+ original, manufacturer supplied header file. */
+
+
+
+#if defined( OBSTACK_LVALUE_CAST_CHECK )
+((*((void **) (h)->next_free) = (aptr)), ( (h)->next_free += sizeof (void *)))
+#endif /* OBSTACK_LVALUE_CAST_CHECK */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5153e076400..d50d0fbddab 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2003-10-22 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ * gcc.dg/cast-lvalue-1.c: New test.
+
2003-10-21 Mark Mitchell <mark@codesourcery.com>
PR c++/11962
diff --git a/gcc/testsuite/gcc.dg/cast-lvalue-1.c b/gcc/testsuite/gcc.dg/cast-lvalue-1.c
new file mode 100644
index 00000000000..1e0f04a63d4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cast-lvalue-1.c
@@ -0,0 +1,12 @@
+/* Test for deprecation of casts as lvalues. */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int x;
+
+void
+foo (void)
+{
+ (char) x = 1; /* { dg-warning "lvalue" "cast as lvalue deprecated" } */
+}
diff --git a/include/ChangeLog b/include/ChangeLog
index db25adc849b..049942f4ee3 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,18 @@
+2003-10-22 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ * obstack.h: Merge the following change from gnulib:
+ 2003-10-21 Paul Eggert <eggert@twinsun.com>
+ * obstack.h (obstack_1grow_fast): Properly parenthesize arg.
+ (obstack_ptr_grow_fast, obstack_int_grow_fast):
+ Don't use lvalue casts, as GCC plans to remove support for them
+ in GCC 3.5. Reported by Joseph S. Myers. This bug
+ was also present in the non-GCC version, indicating that this
+ code had always been buggy and had never been widely used.
+ (obstack_1grow, obstack_ptr_grow, obstack_int_grow, obstack_blank):
+ Use the fast variant of each macro, rather than copying the
+ definiens of the fast variant; that way, we'll be more likely to
+ catch future bugs in the fast variants.
+
2003-09-22 Andrew Cagney <cagney@redhat.com>
* floatformat.h (struct floatformat): Add field "is_valid".
diff --git a/include/obstack.h b/include/obstack.h
index d86d9f2c426..5496ff24071 100644
--- a/include/obstack.h
+++ b/include/obstack.h
@@ -343,7 +343,7 @@ extern int obstack_exit_failure;
#endif
-#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = achar)
+#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ = (achar))
#define obstack_blank_fast(h,n) ((h)->next_free += (n))
@@ -411,7 +411,7 @@ __extension__ \
({ struct obstack *__o = (OBSTACK); \
if (__o->next_free + 1 > __o->chunk_limit) \
_obstack_newchunk (__o, 1); \
- *(__o->next_free)++ = (datum); \
+ obstack_1grow_fast (__o, datum); \
(void) 0; })
/* These assume that the obstack alignment is good enough for pointers or ints,
@@ -423,19 +423,28 @@ __extension__ \
({ struct obstack *__o = (OBSTACK); \
if (__o->next_free + sizeof (void *) > __o->chunk_limit) \
_obstack_newchunk (__o, sizeof (void *)); \
- *((void **)__o->next_free)++ = ((void *)datum); \
- (void) 0; })
+ obstack_ptr_grow_fast (__o, datum); })
# define obstack_int_grow(OBSTACK,datum) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
if (__o->next_free + sizeof (int) > __o->chunk_limit) \
_obstack_newchunk (__o, sizeof (int)); \
- *((int *)__o->next_free)++ = ((int)datum); \
+ obstack_int_grow_fast (__o, datum); })
+
+# define obstack_ptr_grow_fast(OBSTACK,aptr) \
+__extension__ \
+({ struct obstack *__o1 = (OBSTACK); \
+ *(const void **) __o1->next_free = (aptr); \
+ __o1->next_free += sizeof (const void *); \
(void) 0; })
-# define obstack_ptr_grow_fast(h,aptr) (*((void **) (h)->next_free)++ = (void *)aptr)
-# define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint)
+# define obstack_int_grow_fast(OBSTACK,aint) \
+__extension__ \
+({ struct obstack *__o1 = (OBSTACK); \
+ *(int *) __o1->next_free = (aint); \
+ __o1->next_free += sizeof (int); \
+ (void) 0; })
# define obstack_blank(OBSTACK,length) \
__extension__ \
@@ -443,7 +452,7 @@ __extension__ \
int __len = (length); \
if (__o->chunk_limit - __o->next_free < __len) \
_obstack_newchunk (__o, __len); \
- __o->next_free += __len; \
+ obstack_blank_fast (__o, __len); \
(void) 0; })
# define obstack_alloc(OBSTACK,length) \
@@ -530,26 +539,29 @@ __extension__ \
# define obstack_1grow(h,datum) \
( (((h)->next_free + 1 > (h)->chunk_limit) \
? (_obstack_newchunk ((h), 1), 0) : 0), \
- (*((h)->next_free)++ = (datum)))
+ obstack_1grow_fast (h, datum))
# define obstack_ptr_grow(h,datum) \
( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \
? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \
- (*((char **) (((h)->next_free+=sizeof(char *))-sizeof(char *))) = ((char *) datum)))
+ obstack_ptr_grow_fast (h, datum))
# define obstack_int_grow(h,datum) \
( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \
? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \
- (*((int *) (((h)->next_free+=sizeof(int))-sizeof(int))) = ((int) datum)))
+ obstack_int_grow_fast (h, datum))
+
+# define obstack_ptr_grow_fast(h,aptr) \
+ (((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr))
-# define obstack_ptr_grow_fast(h,aptr) (*((char **) (h)->next_free)++ = (char *) aptr)
-# define obstack_int_grow_fast(h,aint) (*((int *) (h)->next_free)++ = (int) aint)
+# define obstack_int_grow_fast(h,aint) \
+ (((int *) ((h)->next_free += sizeof (int)))[-1] = (aptr))
# define obstack_blank(h,length) \
( (h)->temp = (length), \
(((h)->chunk_limit - (h)->next_free < (h)->temp) \
? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \
- ((h)->next_free += (h)->temp))
+ obstack_blank_fast (h, (h)->temp))
# define obstack_alloc(h,length) \
(obstack_blank ((h), (length)), obstack_finish ((h)))