chapel
chapel copied to clipboard
ICC discarded qualifier warning for const pointer to array in generated C
Summary of Problem
Description:
This issue documents a workaround in the compiler, of a known issue with const
pointers in generated C code with ICC.
After https://github.com/chapel-lang/chapel/pull/24809 caused c_ptrConst
to emit C const
pointers in generated C, (only) Intel Compiler specific nightly tests using some parts of the Sort
module began failing with the following error:
error #2332: a value of type "const void *" cannot be assigned to an entity of type "c_ptrConst__tuple_2_star_int64_t_chpl" (dropping qualifiers)
The offending line does a memcpy
where the src is a c_ptrConst
to an array element. When the c_ptrConst
gets stored into a call tmp, the compiler warns of discarding the const
qualifier. Technically we actually do discard a qualifier because the OS.POSIX.memcpy
proc takes a const c_ptr
, and I’m not sure why that isn’t warned elsewhere; however, changing that to a c_ptrConst
does not make the problem go away.
I dug into the generated C and found the call tmp has type c_ptrConst__tuple_2_star_int64_t_chpl
(which implies we should be generating it as a const pointer). It’s defined by these chained typedefs:
-
typedef const _tuple_2_star_int64_t_chpl *c_ptrConst__tuple_2_star_int64_t_chpl;
-
typedef int64_t _tuple_2_star_int64_t_chpl[2];
My conclusion is that this doesn’t result in aconst
pointer to the Intel compiler (but does for GCC). My hunch is that’s due to first typedef in the chain getting decayed to a pointer immediately, which breaks astypedef const mutableptr constptr
doesn’t give a const pointer but rather a pointer-to-const.
Manually changing to the following typedef
works:
typedef const int64_t *c_ptrConst__tuple_2_star_int64_t_chpl
However I expect it would be pretty difficult to do programmatically. Additionally, changing the original offending line to use a mutable pointer instead also works, but we shouldn’t have to do that, and really it'd be losing information to do so.
We are going to work around this by adding a warning suppression flag to ICC for discarding qualifiers in generated C code, as the principled solution of changing the typedef
s would be time consuming and specific to ICC. (PR https://github.com/chapel-lang/chapel/pull/24895)
Is this a blocking issue with no known work-arounds? Not blocking, this issue describes the workaround.
Steps to Reproduce
Source Code:
Test primer https://github.com/chapel-lang/chapel/blob/c5bc1fa172f934156c96624ed51fcfa751d1ed88/test/release/examples/primers/LinearAlgebralib.chpl
Compile command:
start_test test/release/examples/primers/LinearAlgebralib.chpl
Execution command:
(also executed with start_test
)
Associated Future Test(s): n/a
Configuration Information
- Output of
chpl --version
:
chpl version 2.1.0 pre-release (815d4be119)
Copyright 2020-2024 Hewlett Packard Enterprise Development LP
Copyright 2004-2019 Cray Inc.
(See LICENSE file for more details)
- Output of
$CHPL_HOME/util/printchplenv --anonymize
:
CHPL_TARGET_PLATFORM: cray-xc
CHPL_TARGET_COMPILER: cray-prgenv-intel
CHPL_TARGET_ARCH: x86_64
CHPL_TARGET_CPU: sandybridge
CHPL_LOCALE_MODEL: flat
CHPL_COMM: ugni
CHPL_TASKS: qthreads
CHPL_LAUNCHER: slurm-srun
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc
CHPL_ATOMICS: intrinsics
CHPL_NETWORK_ATOMICS: ugni
CHPL_GMP: bundled
CHPL_HWLOC: bundled
CHPL_RE2: bundled
CHPL_LLVM: none *
CHPL_AUX_FILESYS: none
- Back-end compiler and version, e.g.
gcc --version
orclang --version
:
gcc (SUSE Linux) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
icc: remark #10441: The Intel(R) C++ Compiler Classic (ICC) is deprecated and will be removed from product release in the second half of 2023. The Intel(R) oneAPI DPC++/C++ Compiler (ICX) is the recommended compiler moving forward. Please transition to use this compiler. Use '-diag-disable=10441' to disable this message.
icc (ICC) 2021.7.0 20220726
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.
- (For Cray systems only) Output of
module list
:
Currently Loaded Modules:
1) slurm/20.11.5-1 3) craype/2.7.21.6 5) PrgEnv-intel/6.0.10 7) cray-libsci/22.05.1 9) craype-sandybridge
2) Base-opts/2.4.142-7.0.4.0_43.5__g8f27585.ari 4) pmi/5.0.17.1 6) intel-classic/2022.2.0 8) craype-network-none 10) cray-fftw/3.3.8.13