Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] clang warning from View.MemoryView's array_cwrapper #5555

Closed
wkschwartz opened this issue Jul 22, 2023 · 0 comments
Closed

[BUG] clang warning from View.MemoryView's array_cwrapper #5555

wkschwartz opened this issue Jul 22, 2023 · 0 comments

Comments

@wkschwartz
Copy link

wkschwartz commented Jul 22, 2023

Describe the bug

Cythonizing and compiling on macOS with Apple clang version 14.0.3 (clang-1403.0.22.14.1) generates the following

compiler warning for "equality comparison with extraneous parentheses".
clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot $MACOS13SDK -I$VENV_INCLUDE -I$PYTHON311_INCLUDE -c mycode.c -o $BUILD_DIR/mycode.o
mycode.c:5898:28: warning: equality comparison with extraneous parentheses
      [-Wparentheses-equality]
  if (((__pyx_v_c_mode[0]) == 'f')) {
       ~~~~~~~~~~~~~~~~~~~~^~~~~~
mycode.c:5898:28: note: remove extraneous parentheses around the comparison to
      silence this warning
  if (((__pyx_v_c_mode[0]) == 'f')) {
      ~                    ^     ~
mycode.c:5898:28: note: use '=' to turn this equality comparison into an
      assignment
  if (((__pyx_v_c_mode[0]) == 'f')) {
                           ^~
                           =
1 warning generated.

Searching mycode.c for if (((__pyx_v_c_mode[0]) == 'f')) { takes me to the following

generated C function.
/* "View.MemoryView":268
 * 
 * @cname("__pyx_array_new")
 * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, char *c_mode, char *buf):             # <<<<<<<<<<<<<<
 *     cdef array result
 *     cdef str mode = "fortran" if c_mode[0] == b'f' else "c"  # this often comes from a constant C string.
 */

static struct __pyx_array_obj *__pyx_array_new(PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, char *__pyx_v_format, char *__pyx_v_c_mode, char *__pyx_v_buf) {
  struct __pyx_array_obj *__pyx_v_result = 0;
  PyObject *__pyx_v_mode = 0;
  struct __pyx_array_obj *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("array_cwrapper", 0);

  /* "View.MemoryView":270
 * cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, char *c_mode, char *buf):
 *     cdef array result
 *     cdef str mode = "fortran" if c_mode[0] == b'f' else "c"  # this often comes from a constant C string.             # <<<<<<<<<<<<<<
 * 
 *     if buf is NULL:
 */
  if (((__pyx_v_c_mode[0]) == 'f')) {
    __Pyx_INCREF(__pyx_n_s_fortran);
    __pyx_t_1 = __pyx_n_s_fortran;
  } else {
    __Pyx_INCREF(__pyx_n_s_c);
    __pyx_t_1 = __pyx_n_s_c;
  }
  __pyx_v_mode = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

/* ✂️ */
}

Code to reproduce the behaviour:

I don't have a minimal example, except to say that my code uses Cython memoryviews extensively as function parameters like unsigned int8_t[:, :, ::1] out not None. I build my Cython code with the following setup.py

from setuptools import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize('mycode.pyx'))

and then I ran

$ python setup.py build_ext --force --inplace

Expected behaviour

Cython's generated C code should not produce warnings on major compilers under default build setups.

OS

macOS 13.4.1

Python version

CPython 3.11.3

Cython version

3.0.0

Additional context

setuptools 67.7.2

$ clang --version
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: x86_64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants