gcc-python-plugin icon indicating copy to clipboard operation
gcc-python-plugin copied to clipboard

invalid flag "WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE" when using ccache

Open davidmalcolm opened this issue 8 years ago • 3 comments

When building the plugin with "make", it builds fine, but all tests immediately fail: e.g. {{{ --- Expected stderr +++ Actual stderr @@ -1,13 +1,4 @@ -tests/cpychecker/PyArg_Parse/incorrect_codes_S_and_U/input.c: In function 'incorrect_usage_of_S_and_U': -tests/cpychecker/PyArg_Parse/incorrect_codes_S_and_U/input.c:33:21: warning: Mismatching type in call to PyArg_Parse with format code "SU" [enabled by default]

  • argument 3 ("&val1") had type
  • "int *" (pointing to 32 bits)
  • but was expecting
  • one of "struct PyStringObject * *" or "struct PyObject * *"
  • for format code "S" -tests/cpychecker/PyArg_Parse/incorrect_codes_S_and_U/input.c:33:21: warning: Mismatching type in call to PyArg_Parse with format code "SU" [enabled by default]
  • argument 4 ("&val2") had type
  • "int *" (pointing to 32 bits)
  • but was expecting
  • one of "struct PyUnicodeObject * *" or "struct PyObject * *"
  • for format code "U" +tests/cpychecker/PyArg_Parse/incorrect_codes_S_and_U/input.c:1:1: error: invalid flag "WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE" in line directive +tests/cpychecker/PyArg_Parse/incorrect_codes_S_and_U/input.c:1:48: warning: extra tokens at end of ## directive [enabled by default] +/usr/include/stdio.h:35: confused by earlier errors, bailing out +Preprocessed source stored into /tmp/cclgFJfX.out file, please attach this to your bugreport. tests/cpychecker/PyArg_Parse/incorrect_codes_S_and_U: FAIL

returncode: 1 compiling: gcc -c -o tests/cpychecker/PyArg_Parse/incorrect_codes_S_and_U/output.o -fplugin=/home/tomspur/scratch/src/gcc-python-plugin.git/python.so -fplugin-arg-python-script=tests/cpychecker/PyArg_Parse/incorrect_codes_S_and_U/script.py -I/usr/include/python2.7 tests/cpychecker/PyArg_Parse/incorrect_codes_S_and_U/input.c Stdout:

Stderr: tests/cpychecker/PyArg_Parse/incorrect_codes_S_and_U/input.c:1:1: error: invalid flag "WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE" in line directive tests/cpychecker/PyArg_Parse/incorrect_codes_S_and_U/input.c:1:48: warning: extra tokens at end of ## directive [enabled by default] /usr/include/stdio.h:35: confused by earlier errors, bailing out Preprocessed source stored into /tmp/cclgFJfX.out file, please attach this to your bugreport. }}} {{{ $ rpm -q python gcc glibc-headers python-2.7.2-5.2.fc16.x86_64 gcc-4.6.3-2.fc16.x86_64 glibc-headers-2.14.90-24.fc16.6.x86_64 }}}

10 lines around line 35 in stdio.h (what you also asked for online): {{{ 23 24 #ifndef _STDIO_H 25 26 #if !defined __need_FILE && !defined __need___FILE 27 # define _STDIO_H 1 28 # include <features.h> 29 30 __BEGIN_DECLS 31 32 # define __need_size_t 33 # define __need_NULL 34 # include <stddef.h> 35 36 # include <bits/types.h> 37 # define __need_FILE 38 # define __need___FILE 39 #endif /* Don't need FILE. / 40 41 42 #if !defined __FILE_defined && defined __need_FILE 43 44 / Define outside of namespace so the C++ is happy. / 45 struct _IO_FILE; 46 47 __BEGIN_NAMESPACE_STD 48 / The opaque type of streams. This is the definition used elsewhere. */ 49 typedef struct _IO_FILE FILE; 50 __END_NAMESPACE_STD 51 #if defined __USE_LARGEFILE64 || defined __USE_SVID || defined __USE_POSIX
52 || defined __USE_BSD || defined __USE_ISOC99 || defined __USE_XOPEN
53 || defined __USE_POSIX2 54 __USING_NAMESPACE_STD(FILE) 55 #endif 56 }}}

davidmalcolm avatar Feb 09 '17 20:02 davidmalcolm

Imported from trac issue 41. Created by tomspur on 2012-04-30T13:06:24, last modified: 2013-03-21T01:50:27

davidmalcolm avatar Feb 09 '17 20:02 davidmalcolm

Trac comment by dmalcolm on 2012-05-07 12:36:03:

I started running into this on a freshly installed F17 box, and it seems to be a bad interaction between the plugin and ccache.

I was able to reproduce it with an empty source file (apart from comments) and with tests/plugin/macros/correct/script.py, when ccache is installed an active. With that reproducer, I was able to make the error go away by setting either {{{ CCACHE_DISABLE=1 }}} or by uninstalling ccache.

The error comes from: {{{ if (token->type != CPP_EOF) cpp_error (pfile, CPP_DL_ERROR, "invalid flag "%s" in line directive", cpp_token_as_text (pfile, token)); }}} within gcc's libcpp/directives.c:read_flag; this function has this comment: {{{ /* Subroutine of do_linemarker. Read possible flags after file name. LAST is the last flag seen; 0 if this is the first flag. Return the flag if it is valid, 0 at the end of the directive. Otherwise complain. */ }}}

do_linemarker has this comment: {{{ /* Interpret the # 44 "file" [flags] notation, which has slightly different syntax and semantics from #line: Flags are allowed, and we never complain about the line number being too big. */ }}} The plugin tries to inject a {{{ #define WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE }}} but gcc is trying to interpret that as the flag in such a directive, presumably injected by ccache.

I've seen other bad interactions between the plugin and ccache. It's probably best to simply require that ccache be disabled when using the python plugin, though there may be a clean way to fix this (e.g. somehow inject a CPP_EOF token before injecting the #define).

davidmalcolm avatar Feb 09 '17 20:02 davidmalcolm

Trac comment by mcepl on 2013-03-21 01:50:27:

Yes, I can reproduce with gcc-4.7.2-8.el7.x86_64 (gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)). And yes, setting CCACHE_DISABLE makes results being much better.

davidmalcolm avatar Feb 09 '17 20:02 davidmalcolm