🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #6306

[2.7.2] opaque types and -Wcast-align

#6306
From: Andreas Schwab
Date: Wed, 13 Dec 1995 00:00
38 lines
1956 bytes
GCC warns about an alignment problem when casting from a pointer to an
unknown struct to another pointer on machines where STRICT_ALIGNMENT
is defined (eg. m68k).  I don't think this warning is usefull, since
the compiler doesn't know the actual alignment restriction of such a
type, and it is similar to a pointer to void (which doesn't generate
this warning).


--------------------
struct opaque *foo;

f ()
{
  g ((int *) foo);
}
--------------------
$ gcc -c align.c -Wcast-align
align.c: In function `f':
align.c:5: warning: cast increases required alignment of target type


--- gcc-2.7.2/c-typeck.c.~1~	Mon Nov 20 19:24:42 1995
+++ gcc-2.7.2/c-typeck.c	Tue Dec 12 18:54:14 1995
@@ -3735,6 +3735,11 @@
 	  && TREE_CODE (otype) == POINTER_TYPE
 	  && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
 	  && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
+	  /* Don't warn about opaque types, where the actual alignment
+	     restriction is unknown.  */
+	  && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE
+		|| TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE)
+	       && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode)
 	  && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
 	warning ("cast increases required alignment of target type");

-- 
Andreas Schwab                                      "And now for something
schwab@issan.informatik.uni-dortmund.de              completely different"
Technical Details
Message-ID: <9512131006.AA11810@lamothe.informatik.uni-dortmund.de>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,1d536ad335c00c5a,start
X-Google-Attributes: gid113d02,public
From: schwab@lamothe.informatik.uni-dortmund.de (Andreas Schwab)
Subject: [2.7.2] opaque types and -Wcast-align
Date: 1995/12/13
Message-ID: <9512131006.AA11810@lamothe.informatik.uni-dortmund.de>
X-Deja-AN: 121757915
distribution: gnu
sender: daemon@cis.ohio-state.edu
organization: GNUs Not Usenet
reply-to: schwab@issan.informatik.uni-dortmund.de
newsgroups: gnu.gcc.bug