Skip to content

Commit

Permalink
[runtime] Fix -Wcast-qual warnings
Browse files Browse the repository at this point in the history
Since upgrading to Clang/LLVM 17, the Classic Flang build now fails with a
large number of errors with this message:

error: cast from 'const char *' to 'char *' drops const qualifier [-Werror,-Wcast-qual]

This patch fixes all such warnings in runtime/.
  • Loading branch information
bryanpkc committed Oct 4, 2023
1 parent 167af1d commit 6cc5275
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 58 deletions.
14 changes: 6 additions & 8 deletions runtime/flang/eoshift.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
static void I8(eoshift_scalar)(char *rb, /* result base */
char *ab, /* array base */
__INT_T shift_amt, /* shift amount */
char *bb, /* boundary base */
const char *bb, /* boundary base */
__INT_T shift_dim, /* shift dimension */
F90_Desc *rs, /* result descriptor */
F90_Desc *as, /* array descriptor */
Expand Down Expand Up @@ -237,7 +237,7 @@ static void I8(eoshift_scalar)(char *rb, /* result base */
static void I8(eoshift_loop)(char *rb, /* result base */
char *ab, /* array base */
__INT_T *sb, /* shift base */
char *bb, /* boundary base */
const char *bb, /* boundary base */
__INT_T shift_dim, /* dimension to shift */
F90_Desc *rs, /* result descriptor */
F90_Desc *as, /* array descriptor */
Expand Down Expand Up @@ -342,7 +342,7 @@ void ENTFTN(EOSHIFTSZ, eoshiftsz)(char *rb, /* result base */
F90_Desc *ss, /* shift descriptor */
F90_Desc *ds) /* dim descriptor */
{
char *bb;
const char *bb;
DECL_HDR_VARS(ac);
DECL_HDR_VARS(rc);
DECL_DIM_PTRS(asd);
Expand All @@ -351,8 +351,7 @@ void ENTFTN(EOSHIFTSZ, eoshiftsz)(char *rb, /* result base */

shift = *sb;
dim = *db;
/* FIXME: bb is passed to many non-const parameters; just cast it for now. */
bb = (F90_KIND_G(rs) == __STR) ? (char *)" " : (char *)GET_DIST_ZED;
bb = (F90_KIND_G(rs) == __STR) ? " " : (const char *)GET_DIST_ZED;

#if defined(DEBUG)
if (__fort_test & DEBUG_EOSH) {
Expand Down Expand Up @@ -597,12 +596,11 @@ void ENTFTN(EOSHIFTZ, eoshiftz)(char *rb, /* result base */
DECL_HDR_PTRS(bs);
DECL_HDR_VARS(ac);
DECL_HDR_VARS(rc);
char *bb;
const char *bb;
__INT_T dim;

dim = *db;
/* FIXME: bb is passed to many non-const parameters; just cast it for now. */
bb = (F90_KIND_G(rs) == __STR) ? (char *)" " : (char *)GET_DIST_ZED;
bb = (F90_KIND_G(rs) == __STR) ? " " : (const char *)GET_DIST_ZED;
bs = (F90_Desc *)&F90_KIND_G(rs);

#if defined(DEBUG)
Expand Down
2 changes: 1 addition & 1 deletion runtime/flang/fill.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "fioMacros.h"

#include "fort_vars.h"
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, void *sp, int size);
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, const void *sp, int size);

static void I8(fills_loop)(char *ab, F90_Desc *as, void *fb, __INT_T off0,
__INT_T dim)
Expand Down
2 changes: 1 addition & 1 deletion runtime/flang/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
static int
compar_tids(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
return *(const int *)a - *(const int *)b;
}

/* Verify the logical to physical processor map */
Expand Down
2 changes: 1 addition & 1 deletion runtime/flang/mget.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define QTREE

#include "fort_vars.h"
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, void *sp, int size);
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, const void *sp, int size);

static int _1 = 1;

Expand Down
2 changes: 1 addition & 1 deletion runtime/flang/mmul.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
typedef void (*mmul_fn)(void *, int, void *, int, int, void *, int, int);

extern void (*I8(__fort_g_sum)[__NTYPES])();
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, void *sp, int len);
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, const void *sp, int len);

void ENTFTN(QOPY_IN, qopy_in)(char **dptr, __POINT_T *doff, char *dbase,
F90_Desc *dd, char *ab, F90_Desc *ad,
Expand Down
2 changes: 1 addition & 1 deletion runtime/flang/olap.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "fioMacros.h"

#include "fort_vars.h"
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, void *sp, int size);
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, const void *sp, int size);

/* overlap shift communication schedule */

Expand Down
2 changes: 1 addition & 1 deletion runtime/flang/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "stdioInterf.h"
#include "fioMacros.h"

extern void (*__fort_scalar_copy[__NTYPES])(void *rp, void *sp, int len);
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, const void *sp, int len);

static int I8(next_index)(__INT_T *index, F90_Desc *s)
{
Expand Down
2 changes: 1 addition & 1 deletion runtime/flang/red.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "fioMacros.h"
#include "red.h"

extern void (*__fort_scalar_copy[__NTYPES])(void *rp, void *sp, int len);
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, const void *sp, int len);

void ENTFTN(QOPY_IN, qopy_in)(char **dptr, __POINT_T *doff, char *dbase,
F90_Desc *dd, char *ab, F90_Desc *ad,
Expand Down
2 changes: 1 addition & 1 deletion runtime/flang/reshape.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "stdioInterf.h"
#include "fioMacros.h"

extern void (*__fort_scalar_copy[__NTYPES])(void *rp, void *sp, int len);
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, const void *sp, int len);

/* advance index n elements and return the remaining extent in the
first dimension from that point. When the end of the array is
Expand Down
2 changes: 1 addition & 1 deletion runtime/flang/scal.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "fioMacros.h"

#include "fort_vars.h"
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, void *sp, int size);
extern void (*__fort_scalar_copy[__NTYPES])(void *rp, const void *sp, int size);

/* all processors get the value of the selected array element */

Expand Down
68 changes: 34 additions & 34 deletions runtime/flang/scalar_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,167 +11,167 @@
#include "fioMacros.h"

static void
copy_none(__SHORT_T *rp, __SHORT_T *sp, int size)
copy_none(__SHORT_T *rp, const __SHORT_T *sp, int size)
{
__fort_abort("scalar_copy: undefined type");
}
static void
copy_short(__SHORT_T *rp, __SHORT_T *sp, int size)
copy_short(__SHORT_T *rp, const __SHORT_T *sp, int size)
{
*rp = *sp;
}
static void
copy_ushort(__USHORT_T *rp, __USHORT_T *sp, int size)
copy_ushort(__USHORT_T *rp, const __USHORT_T *sp, int size)
{
*rp = *sp;
}
static void
copy_cint(__CINT_T *rp, __CINT_T *sp, int size)
copy_cint(__CINT_T *rp, const __CINT_T *sp, int size)
{
*rp = *sp;
}
static void
copy_uint(__UINT_T *rp, __UINT_T *sp, int size)
copy_uint(__UINT_T *rp, const __UINT_T *sp, int size)
{
*rp = *sp;
}
static void
copy_long(__LONG_T *rp, __LONG_T *sp, int size)
copy_long(__LONG_T *rp, const __LONG_T *sp, int size)
{
*rp = *sp;
}
static void
copy_ulong(__ULONG_T *rp, __ULONG_T *sp, int size)
copy_ulong(__ULONG_T *rp, const __ULONG_T *sp, int size)
{
*rp = *sp;
}
static void
copy_float(__FLOAT_T *rp, __FLOAT_T *sp, int size)
copy_float(__FLOAT_T *rp, const __FLOAT_T *sp, int size)
{
*rp = *sp;
}
static void
copy_double(__DOUBLE_T *rp, __DOUBLE_T *sp, int size)
copy_double(__DOUBLE_T *rp, const __DOUBLE_T *sp, int size)
{
*rp = *sp;
}
static void
copy_cplx8(__CPLX8_T *rp, __CPLX8_T *sp, int size)
copy_cplx8(__CPLX8_T *rp, const __CPLX8_T *sp, int size)
{
*rp = *sp;
}
static void
copy_cplx16(__CPLX16_T *rp, __CPLX16_T *sp, int size)
copy_cplx16(__CPLX16_T *rp, const __CPLX16_T *sp, int size)
{
*rp = *sp;
}
static void
copy_char(__CHAR_T *rp, __CHAR_T *sp, int size)
copy_char(__CHAR_T *rp, const __CHAR_T *sp, int size)
{
*rp = *sp;
}
static void
copy_uchar(__UCHAR_T *rp, __UCHAR_T *sp, int size)
copy_uchar(__UCHAR_T *rp, const __UCHAR_T *sp, int size)
{
*rp = *sp;
}
static void
copy_longdouble(__LONGDOUBLE_T *rp, __LONGDOUBLE_T *sp, int size)
copy_longdouble(__LONGDOUBLE_T *rp, const __LONGDOUBLE_T *sp, int size)
{
*rp = *sp;
}
static void
copy_longlong(__LONGLONG_T *rp, __LONGLONG_T *sp, int size)
copy_longlong(__LONGLONG_T *rp, const __LONGLONG_T *sp, int size)
{
*rp = *sp;
}
static void
copy_ulonglong(__ULONGLONG_T *rp, __ULONGLONG_T *sp, int size)
copy_ulonglong(__ULONGLONG_T *rp, const __ULONGLONG_T *sp, int size)
{
*rp = *sp;
}
static void
copy_log1(__LOG1_T *rp, __LOG1_T *sp, int size)
copy_log1(__LOG1_T *rp, const __LOG1_T *sp, int size)
{
*rp = *sp;
}
static void
copy_log2(__LOG2_T *rp, __LOG2_T *sp, int size)
copy_log2(__LOG2_T *rp, const __LOG2_T *sp, int size)
{
*rp = *sp;
}
static void
copy_log4(__LOG4_T *rp, __LOG4_T *sp, int size)
copy_log4(__LOG4_T *rp, const __LOG4_T *sp, int size)
{
*rp = *sp;
}
static void
copy_log8(__LOG8_T *rp, __LOG8_T *sp, int size)
copy_log8(__LOG8_T *rp, const __LOG8_T *sp, int size)
{
*rp = *sp;
}
static void
copy_word4(__WORD4_T *rp, __WORD4_T *sp, int size)
copy_word4(__WORD4_T *rp, const __WORD4_T *sp, int size)
{
*rp = *sp;
}
static void
copy_word8(__WORD8_T *rp, __WORD8_T *sp, int size)
copy_word8(__WORD8_T *rp, const __WORD8_T *sp, int size)
{
*rp = *sp;
}
static void
copy_nchar(__NCHAR_T *rp, __NCHAR_T *sp, int size)
copy_nchar(__NCHAR_T *rp, const __NCHAR_T *sp, int size)
{
*rp = *sp;
}
static void
copy_int2(__INT2_T *rp, __INT2_T *sp, int size)
copy_int2(__INT2_T *rp, const __INT2_T *sp, int size)
{
*rp = *sp;
}
static void
copy_int4(__INT4_T *rp, __INT4_T *sp, int size)
copy_int4(__INT4_T *rp, const __INT4_T *sp, int size)
{
*rp = *sp;
}
static void
copy_int8(__INT8_T *rp, __INT8_T *sp, int size)
copy_int8(__INT8_T *rp, const __INT8_T *sp, int size)
{
*rp = *sp;
}
static void
copy_real4(__REAL4_T *rp, __REAL4_T *sp, int size)
copy_real4(__REAL4_T *rp, const __REAL4_T *sp, int size)
{
*rp = *sp;
}
static void
copy_real8(__REAL8_T *rp, __REAL8_T *sp, int size)
copy_real8(__REAL8_T *rp, const __REAL8_T *sp, int size)
{
*rp = *sp;
}
static void
copy_real16(__REAL16_T *rp, __REAL16_T *sp, int size)
copy_real16(__REAL16_T *rp, const __REAL16_T *sp, int size)
{
*rp = *sp;
}
static void
copy_cplx32(__CPLX32_T *rp, __CPLX32_T *sp, int size)
copy_cplx32(__CPLX32_T *rp, const __CPLX32_T *sp, int size)
{
*rp = *sp;
}
static void
copy_word16(__WORD16_T *rp, __WORD16_T *sp, int size)
copy_word16(__WORD16_T *rp, const __WORD16_T *sp, int size)
{
*rp = *sp;
}
static void
copy_int1(__INT1_T *rp, __INT1_T *sp, int size)
copy_int1(__INT1_T *rp, const __INT1_T *sp, int size)
{
*rp = *sp;
}

static void copy_bytes(char *, char *, int);
static void copy_bytes(char *, const char *, int);

void (*__fort_scalar_copy[__NTYPES])() = {
copy_none, /* no type (absent optional argument) */
Expand Down Expand Up @@ -211,7 +211,7 @@ void (*__fort_scalar_copy[__NTYPES])() = {
};

static void
copy_bytes(char *to, char *fr, int n)
copy_bytes(char *to, const char *fr, int n)
{
memmove(to, fr, n);
}
6 changes: 3 additions & 3 deletions runtime/flang/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -1877,10 +1877,10 @@ ENTF90(INIT_FROM_DESC, init_from_desc)(void *object, const F90_Desc *desc,
int rank)
{
if (object && desc) {
OBJECT_DESC *obj_desc = (OBJECT_DESC *)desc;
const OBJECT_DESC *obj_desc = (const OBJECT_DESC *)desc;
size_t items = 1;
size_t index[MAXDIMS];
TYPE_DESC *type_desc = obj_desc->type;
const TYPE_DESC *type_desc = obj_desc->type;
int j;
size_t element_bytes = 0;
void *prototype = NULL;
Expand All @@ -1899,7 +1899,7 @@ ENTF90(INIT_FROM_DESC, init_from_desc)(void *object, const F90_Desc *desc,
if (type_desc)
obj_desc = &type_desc->obj;
else
type_desc = (TYPE_DESC *)obj_desc;
type_desc = (const TYPE_DESC *)obj_desc;
element_bytes = obj_desc->size;
prototype = obj_desc->prototype;

Expand Down
4 changes: 2 additions & 2 deletions runtime/flangrti/tempnam.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ addn(char *p, int val, int n)
/* generate a possible temp name */

static char *
gentmp(char *dir, char *pfx)
gentmp(const char *dir, const char *pfx)
{
extern long getpid(void);
extern long time(void *);
Expand Down Expand Up @@ -132,7 +132,7 @@ __io_tempnam(const char *dir, const char *pfx)
char *p;

while (1) {
p = gentmp((char *)dir, (char *)pfx);
p = gentmp(dir, pfx);
if ((access(p, 0) == -1) && (errno == ENOENT)) {
break;
}
Expand Down
Loading

0 comments on commit 6cc5275

Please sign in to comment.