Skip to content

Fails to compile with icc #269

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

Open
certik opened this issue Aug 19, 2020 · 4 comments · May be fixed by #271
Open

Fails to compile with icc #269

certik opened this issue Aug 19, 2020 · 4 comments · May be fixed by #271

Comments

@certik
Copy link

certik commented Aug 19, 2020

I tried to build using Intel icc version 19.1.0.20191121 and the cmake succeeds to run:

$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/builds/certik/truchas/scratch/python-install ../python-cmake-buildsystem
-- The C compiler identification is Intel 19.1.0.20191121
-- The ASM compiler identification is Intel
-- Found assembler: /opt/intel/bin/icc
-- Check for working C compiler: /opt/intel/bin/icc
-- Check for working C compiler: /opt/intel/bin/icc -- works
-- Detecting C compiler ABI info
...
-- Configuring done
-- Generating done
-- Build files have been written to: /builds/certik/truchas/scratch/python-build

But when I run make, it fails:

$ make -j8
...
[ 31%] Building C object CMakeBuild/libpython/CMakeFiles/pgen.dir/builds/certik/truchas/scratch/Python-3.6.7/Parser/grammar.c.o
/builds/certik/truchas/scratch/Python-3.6.7/Parser/grammar.c(37): error: expected an expression
          for (int j = 0; j < g->g_dfa[i].d_nstates; j++)
               ^
/builds/certik/truchas/scratch/Python-3.6.7/Parser/grammar.c(37): error: identifier "j" is undefined
          for (int j = 0; j < g->g_dfa[i].d_nstates; j++)
                          ^
compilation aborted for /builds/certik/truchas/scratch/Python-3.6.7/Parser/grammar.c (code 2)
make[2]: *** [CMakeBuild/libpython/CMakeFiles/pgen.dir/builds/certik/truchas/scratch/Python-3.6.7/Parser/grammar.c.o] Error 2

It looks like the icc compiler does not allow to define variables inside the for loop.

I don't know if icc is supported, but if not, then I would expect cmake to error out sooner. It might also be possible to fix the failures with a patch.

@dand-oss
Copy link
Contributor

The problem is in the source code

If this is python dist source code, your options include

  • patch the python source for icc compatability
  • apply some options in cmake to allow icc to handle this
  • look in python for icc support in the python build

@telamonian
Copy link

telamonian commented Sep 17, 2020

Apparently, variable-definition-in-loop was a feature added to the C language as part of the C99 standard. Whereas even the most modern version of icc for some questionable reason defaults to "C90 plus GNU extensions". See the icc docs and this SO thread.

So it looks like the fix for this will be to set the -std=c99 CFLAG for intel toolchain builds

@telamonian
Copy link

telamonian commented Sep 17, 2020

Probably will need something in a CMake file like:

if(${CMAKE_C_COMPILER_ID} MATCHES "Intel")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
endif(${CMAKE_C_COMPILER_ID} MATCHES "Intel")

relevant cmake docs

Edit:

Most of the relevant code was already in the main CMakeLists.txt:

# Set cflags used by all components
if(CMAKE_C_COMPILER_ID MATCHES GNU)
if(PY_VERSION VERSION_EQUAL "3.6" OR PY_VERSION VERSION_GREATER "3.6")
append_if_absent(CMAKE_C_FLAGS "-std=c99")
endif()
append_if_absent(CMAKE_C_FLAGS "-Wall")
append_if_absent(CMAKE_C_FLAGS "-Wstrict-prototypes")
append_if_absent(CMAKE_C_FLAGS "-fno-strict-aliasing")
append_if_absent(CMAKE_C_FLAGS "-fwrapv")
append_if_absent(CMAKE_C_FLAGS "-g")
elseif(CMAKE_C_COMPILER_ID MATCHES Clang)
append_if_absent(CMAKE_C_FLAGS "-Wall")
append_if_absent(CMAKE_C_FLAGS "-g")
elseif(CMAKE_C_COMPILER_ID MATCHES Intel)
append_if_absent(CMAKE_C_FLAGS "-Wall")
append_if_absent(CMAKE_C_FLAGS "-no-ansi-alias")
elseif(CMAKE_C_COMPILER_ID MATCHES PGI)
append_if_absent(CMAKE_C_FLAGS "-alias=traditional")
endif()

just had to go looking for it

telamonian added a commit to telamonian/python-cmake-buildsystem that referenced this issue Sep 17, 2020
The intel C compiler [defaults to `-std=gnu98`](https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/language-options/std-qstd.html#std-qstd_GUID-338F4C2A-560C-4338-8ACF-C4B022A7C865), which apparently causes problems with recent cpython source. Judging by the existing code in `CMakeLists.txt` and [this issue on the core cpython repo](python/cpython#568), somewhere around cpy3.6 cpython moved on to C99.

This PR ensures that if intel compilers are being used on cpy>=3.6 source, the `-std=C99` flag will be added
@telamonian telamonian linked a pull request Sep 17, 2020 that will close this issue
@telamonian
Copy link

@certik I did a fix PR at #271. Can you please try it out?

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

Successfully merging a pull request may close this issue.

3 participants