DrTimothyAldenDavis / SuiteSparse

The official SuiteSparse library: a suite of sparse matrix algorithms authored or co-authored by Tim Davis, Texas A&M University.
https://people.engr.tamu.edu/davis/suitesparse.html
Other
1.11k stars 256 forks source link

GraphBLAS uses `_Generic` selections with potentially compatible types #753

Closed mmuetzel closed 5 months ago

mmuetzel commented 5 months ago

Describe the bug When trying to build LAGraph with clang-cl, it fails with errors like the following:

D:\repo\SuiteSparse\SuiteSparse\LAGraph\src\utility\LAGr_Init.c(195,18): error: type 'GxB_Option_Field' in generic association compatible with previously specified type 'int'
        GRB_TRY (GxB_set (GxB_NTHREADS, LG_nthreads_inner)) ;
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\repo\SuiteSparse\SuiteSparse\GraphBLAS\Include\GraphBLAS.h(3969,13): note: expanded from macro 'GxB_set'
            GxB_Option_Field : GxB_Global_Option_set ,          \
            ^~~~~~~~~~~~~~~~
D:\repo\SuiteSparse\SuiteSparse\LAGraph\include\LAGraph.h(366,28): note: expanded from macro 'GRB_TRY'
    GrB_Info LG_GrB_Info = GrB_method ;         \
                           ^~~~~~~~~~
D:\repo\SuiteSparse\SuiteSparse\LAGraph\src\utility\LAGr_Init.c(195,18): note: compatible type 'int' specified here
        GRB_TRY (GxB_set (GxB_NTHREADS, LG_nthreads_inner)) ;
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
D:\repo\SuiteSparse\SuiteSparse\GraphBLAS\Include\GraphBLAS.h(3968,13): note: expanded from macro 'GxB_set'
            int              : GxB_Global_Option_set ,          \
            ^~~
D:\repo\SuiteSparse\SuiteSparse\LAGraph\include\LAGraph.h(366,28): note: expanded from macro 'GRB_TRY'
    GrB_Info LG_GrB_Info = GrB_method ;         \
                           ^~~~~~~~~~
1 error generated.

To Reproduce Configure with the following using a MSVC build environment:

cmake.exe -G"Ninja" -DCMAKE_BUILD_TYPE="Release" -DSUITESPARSE_ENABLE_PROJECTS="lagraph" -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DSUITESPARSE_USE_CUDA=OFF ..

Alternatively, configure and build with:

cmake.exe -TClangCL -DCMAKE_BUILD_TYPE="Release" -DSUITESPARSE_ENABLE_PROJECTS="lagraph" -DSUITESPARSE_USE_CUDA=OFF -DCMAKE_GENERATOR_PLATFORM=x64 --fresh ..
cmake --build . --config Release

Expected behavior LAGraph builds without error

Desktop (please complete the following information):

Additional context cppreference.com says the following: https://en.cppreference.com/w/c/language/generic

No two type-names in the association-list may specify compatible types.

https://en.cppreference.com/w/c/language/type#Compatible_types

The types T and U are compatible, if [...]

  • one is an enumerated type and the other is that enumeration's underlying type

IIUC, the following _Generic selection is invalid C11 code if int is the underlying type for enumerations: https://github.com/DrTimothyAldenDavis/SuiteSparse/blob/9706d509e4d3058653247b1030da46a16f2ea41e/GraphBLAS/Include/GraphBLAS.h#L3965-L3975

chengts95 commented 5 months ago

I think -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ is not clang-cl.

mmuetzel commented 5 months ago

I think -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ is not clang-cl.

Oops. Copy-paste error. Should be fixed now.

chengts95 commented 5 months ago

by the way, how do you get clang-cl work with ninja?

mmuetzel commented 5 months ago

by the way, how do you get clang-cl work with ninja?

I'm opening the "x64 Native Tools Command Prompt for VS 2022", cd to the build directory and run the command as shown above.

DrTimothyAldenDavis commented 5 months ago

This is fixed now in the dev2 branch, correct?

mmuetzel commented 5 months ago

Yes, this is now fixed and covered in CI.