This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/32854] New: Type cast between const and non-const multi-dim-arrays ignored during inlining


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]