public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/32854]  New: Type cast between const and non-const multi-dim-arrays ignored during inlining
@ 2007-07-22 16:20 ch at dot-heine dot de
  2007-07-22 19:32 ` [Bug c/32854] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: ch at dot-heine dot de @ 2007-07-22 16:20 UTC (permalink / raw)
  To: gcc-bugs

Warnings when passing non-const multi-dimensional arrays to inline functions
expecting const multi-dimensional arrays cannot be shut-up by a type cast.

This is for vanilla gcc-4.2.1 configured with

./configure   --enable-languages=c

uname -a:
Linux anaxagoras 2.6.21.3 #1 SMP PREEMPT Thu Jun 7 00:36:20 CEST 2007 x86_64
AMD Athlon(tm) 64 X2 Dual Core Processor 3800+ AuthenticAMD GNU/Linux

Let's call the following exmaple program blah.c, then

> cd gcc-4.2.1/host-x86_64-unknown-linux-gnu/gcc
> ./xgcc -B./ -S -o blah.s blah.c -O1
blah.c: In function 'blah':
blah.c:16: warning: passing argument 1 of 'MAXPY_DOW' from incompatible pointer
type
> ./xgcc -B./ -S -o blah.s blah.c -O1 -fno-inline
[no output]

While it may be a stupid idea to use multi-dimensional "const" arrays in C at
all, because the compiler always would complain about mis-matching
pointer-types, all previous versions of gcc could be shut-up by an appropriate
type-cast, but gcc-4.2.1 cannot if inlining is enabled. This is at best very
annoying.

I was able to track down the problem to the point that the argument passed to
c_convert_parm_for_inlining() is indeed missing the read-only flag. The change
between 4.1.2 and 4.2.1 is that the previous version did not compare the
TYPE_MAIN_VARIANT() of "parm" and "value" in
c_convert_parm_for_inlining(parm,value,fn,...) if TYPE_ARG_TYPES(TREE_TYPE(fn)
was not 0. So propably already in 4.1.2 the saved argument list was missing the
type-casts to the const variant of the respective types. I gave up tracking the
sources when I reached the line 2124 in expand_call_inline() in tree-inline.c:

  /* Initialize the parameters.  */
  args = TREE_OPERAND (t, 1);

So args seems to be a list of parameters for the function to be expanded
inline, but missing the type-casts. Same warning persists when playing around
with casts to "void *" or "const void *", if that matters.

Example program blah.c, and preprocessed blah.i
############################ blah.c ###########################################
#define DIM_OF_WORLD 3

typedef double REAL;
typedef REAL REAL_D[DIM_OF_WORLD];
typedef REAL_D REAL_DD[DIM_OF_WORLD];

static inline REAL_D *MAXPY_DOW(const REAL_DD x)
{
  return (REAL_D *)x;
}

REAL_D *blah(REAL_DD a)
{
        REAL_DD val;

        return MAXPY_DOW((const REAL_D *)val);
}

REAL_D *blub(REAL_DD a)
{
        REAL_DD val;
        const REAL_D *dummy;

        return MAXPY_DOW(dummy = (const REAL_D *)val);
}
############################# blah.i ##########################################
 1 "blah.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "blah.c"


typedef double REAL;
typedef REAL REAL_D[3];
typedef REAL_D REAL_DD[3];

static inline REAL_D *MAXPY_DOW(const REAL_DD x)
{
  return (REAL_D *)x;
}

REAL_D *blah(REAL_DD a)
{
 REAL_DD val;

 return MAXPY_DOW((const REAL_D *)val);
}

REAL_D *blub(REAL_DD a)
{
 REAL_DD val;
 const REAL_D *dummy;

 return MAXPY_DOW(dummy = (const REAL_D *)val);
}
###############################################################################


-- 
           Summary: Type cast between const and non-const multi-dim-arrays
                    ignored during inlining
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ch at dot-heine dot de
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32854


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/32854] Type cast between const and non-const multi-dim-arrays ignored during inlining
  2007-07-22 16:20 [Bug c/32854] New: Type cast between const and non-const multi-dim-arrays ignored during inlining ch at dot-heine dot de
@ 2007-07-22 19:32 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-22 19:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-07-22 19:31 -------
This has been fixed on the trunk already.

*** This bug has been marked as a duplicate of 29478 ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32854


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-07-22 19:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-22 16:20 [Bug c/32854] New: Type cast between const and non-const multi-dim-arrays ignored during inlining ch at dot-heine dot de
2007-07-22 19:32 ` [Bug c/32854] " pinskia at gcc dot gnu dot org

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).