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

Compile warning caused by Python3.12 header from -Wdeclaration-after-statement #1934

Open
yskelg opened this issue Jun 19, 2024 · 2 comments

Comments

@yskelg
Copy link
Contributor

yskelg commented Jun 19, 2024

In Makefile, We use C11.

  • 4c9117d
    But because C89 based compiler warning flag -Wdeclaration-after-statement, latest compiler (gcc version 14.1.1 20240522, clang version 18.1.6) told me that some warning.
  • 1e2a3f3
COMMON_CFLAGS := -std=gnu11 -D_GNU_SOURCE $(CFLAGS) $(CPPFLAGS)
COMMON_CFLAGS += -iquote $(srcdir) -iquote $(objdir) -iquote $(srcdir)/arch/$(ARCH)
COMMON_CFLAGS += -W -Wall -Wno-unused-parameter -Wno-missing-field-initializers
COMMON_CFLAGS += -Wdeclaration-after-statement -Wstrict-prototypes

Here is the build log.

In file included from /usr/include/python3.12/Python.h:44,
                 from /home/paran/uftrace/utils/script-python.h:20,
                 from /home/paran/uftrace/utils/script.h:13,
                 from /home/paran/uftrace/utils/script-luajit.c:9:
/usr/include/python3.12/object.h: In function ‘Py_SIZE’:
/usr/include/python3.12/object.h:233:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  233 |     PyVarObject *var_ob = _PyVarObject_CAST(ob);
      |     ^~~~~~~~~~~
In file included from /usr/include/python3.12/Python.h:53:
/usr/include/python3.12/cpython/longintrepr.h: In function ‘_PyLong_CompactValue’:
/usr/include/python3.12/cpython/longintrepr.h:121:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  121 |     Py_ssize_t sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK);
      |     ^~~~~~~~~~
  CC       utils/script-python.o
In file included from /usr/include/python3.12/Python.h:44,
                 from /home/paran/uftrace/utils/script-python.h:20,
                 from /home/paran/uftrace/utils/script-python.c:15:
/usr/include/python3.12/object.h: In function ‘Py_SIZE’:
/usr/include/python3.12/object.h:233:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  233 |     PyVarObject *var_ob = _PyVarObject_CAST(ob);
      |     ^~~~~~~~~~~
In file included from /usr/include/python3.12/Python.h:53:
/usr/include/python3.12/cpython/longintrepr.h: In function ‘_PyLong_CompactValue’:
/usr/include/python3.12/cpython/longintrepr.h:121:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
  121 |     Py_ssize_t sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK);
      |     ^~~~~~~~~~
@namhyung
Copy link
Owner

It's a matter of coding style and I feel it's better to have declarations before statements. Maybe I need to reconsider later but let's fix the external codes like python (or luajit) with pragma push/pop:

https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html

@namhyung
Copy link
Owner

In file included from /usr/include/python3.12/Python.h:44,
from /home/paran/uftrace/utils/script-python.h:20,
from /home/paran/uftrace/utils/script.h:13,
from /home/paran/uftrace/utils/script-luajit.c:9:

Also, it seems we include python headers for the luajit script. This is not needed and I think we should remove the language specific headers from the utils/script.h file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants