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

Compiling with icpc #755

Closed
tdegeus opened this issue Sep 27, 2017 · 19 comments · Fixed by #3227
Closed

Compiling with icpc #755

tdegeus opened this issue Sep 27, 2017 · 19 comments · Fixed by #3227
Assignees
Labels
kind: bug platform: icc related to Intel compiler release item: 🔨 further change solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@tdegeus
Copy link

tdegeus commented Sep 27, 2017

I would like to compile with the Intel C++ compiler, in particular this one

$ icpc --version
icpc (ICC) 17.0.2 20170213
Copyright (C) 1985-2017 Intel Corporation.  All rights reserved.

But currently this results in

...json.hpp(67): error: #error directive: "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
          #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"

When I remove the checks, I'm able to successfully compile and run. Compiling with -Wall -Wextra -pendantic only results in the following warnings

/home/tdegeus/prog/research/avalanches_inertia/json/json.hpp(6323): warning #186: pointless comparison of unsigned integer with zero
          return ((0 <= u and u <= 127) ? 0
                     ^
          detected during:
            instantiation of "std::size_t={unsigned long} nlohmann::detail::serializer<BasicJsonType>::extra_space(const nlohmann::detail::serializer<BasicJsonType>::string_t &, bool) [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>]" at line 6500
            instantiation of "void nlohmann::detail::serializer<BasicJsonType>::dump_escaped(const nlohmann::detail::serializer<BasicJsonType>::string_t &, bool) const [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>]" at line 6154
            instantiation of "void nlohmann::detail::serializer<BasicJsonType>::dump(const BasicJsonType &, bool, bool, unsigned int, unsigned int) [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>]" at line 8995
            instantiation of "nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::string_t nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::dump(int, char, bool) const [with ObjectType=std::map, ArrayType=std::vector, StringType=std::string, BooleanType=bool,
                      NumberIntegerType=int64_t={long}, NumberUnsignedType=uint64_t={unsigned long}, NumberFloatType=double, AllocatorType=std::allocator, JSONSerializer=nlohmann::adl_serializer]" at line 14653

/home/tdegeus/prog/research/avalanches_inertia/json/json.hpp(6663): warning #186: pointless comparison of unsigned integer with zero
          const bool is_negative = x < 0;
                                     ^
          detected during:
            instantiation of "void nlohmann::detail::serializer<BasicJsonType>::dump_integer(NumberType) [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>, NumberType=uint64_t={unsigned long}, <unnamed>=0]" at line 6290
            instantiation of "void nlohmann::detail::serializer<BasicJsonType>::dump(const BasicJsonType &, bool, bool, unsigned int, unsigned int) [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>]" at line 8995
            instantiation of "nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::string_t nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::dump(int, char, bool) const [with ObjectType=std::map, ArrayType=std::vector, StringType=std::string, BooleanType=bool,
                      NumberIntegerType=int64_t={long}, NumberUnsignedType=uint64_t={unsigned long}, NumberFloatType=double, AllocatorType=std::allocator, JSONSerializer=nlohmann::adl_serializer]" at line 14653

/home/tdegeus/prog/research/avalanches_inertia/json/json.hpp(9762): warning #191: type qualifier is meaningless on cast type
          return get_impl_ptr(static_cast<const PointerType>(nullptr));
                                          ^
          detected during:
            instantiation of "void nlohmann::detail::get_arithmetic_value(const BasicJsonType &, ArithmeticType &) [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>, ArithmeticType=double, <unnamed>=0]" at line 1133
            instantiation of "void nlohmann::detail::from_json(const BasicJsonType &, BasicJsonType::number_float_t &) [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>]" at line 1368
            instantiation of "auto nlohmann::detail::from_json_fn::call(const BasicJsonType &, T &, nlohmann::detail::priority_tag<1U>) const->decltype((<expression>)) [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>, T=double]" at line 1383
            instantiation of "void nlohmann::detail::from_json_fn::operator()(const BasicJsonType &, T &) const [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>, T=double]" at line 6880
            instantiation of "void nlohmann::adl_serializer<<unnamed>, <unnamed>>::from_json(BasicJsonType &&, ValueType &) [with <unnamed>=double, <unnamed>=void, BasicJsonType=const nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer> &, ValueType=double]" at line 9592
            instantiation of "ValueType nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::get<ValueTypeCV,ValueType,<unnamed>>() const [with ObjectType=std::map, ArrayType=std::vector, StringType=std::string, BooleanType=bool, NumberIntegerType=int64_t={long}, NumberUnsignedType=uint64_t={unsigned long}, NumberFloatType=double, AllocatorType=std::allocator,
                      JSONSerializer=nlohmann::adl_serializer, ValueTypeCV=double, ValueType=double, <unnamed>=0]" at line 237 of "/home/tdegeus/prog/research/avalanches_inertia/main.cpp"

remark #11074: Inlining inhibited by limit max-size
remark #11074: Inlining inhibited by limit max-total-size
remark #11076: To get full report use -qopt-report=4 -qopt-report-phase ipo
@nlohmann
Copy link
Owner

Thanks for reporting! I shall have a look at the warnings.

Apparently, we seem to "recognize" a GCC here. Could you please post the output of the json::meta() function? If the Intel Compiler is correctly recognized there, I may have an idea how to fix the compiler detection above.

@nlohmann nlohmann self-assigned this Sep 29, 2017
@tdegeus
Copy link
Author

tdegeus commented Sep 29, 2017

Here is the output of json::meta():

{
    "compiler": {
        "c++": "201103",
        "family": "icc",
        "version": 1700
    },
    "copyright": "(C) 2013-2017 Niels Lohmann",
    "name": "JSON for Modern C++",
    "platform": "linux",
    "url": "https://github.com/nlohmann/json",
    "version": {
        "major": 2,
        "minor": 1,
        "patch": 1,
        "string": "2.1.1"
    }
}

@nlohmann
Copy link
Owner

Thanks! I shall have a look. I maybe just need to exclude ICC from the GCC version check.

By the way: do you know whether there is a free version of ICC so that I could use it in the CI test suite?

@nlohmann nlohmann added this to the Release 3.0.0 milestone Sep 29, 2017
@nlohmann nlohmann added the platform: icc related to Intel compiler label Sep 29, 2017
@tdegeus
Copy link
Author

tdegeus commented Sep 29, 2017

nlohmann added a commit that referenced this issue Sep 30, 2017
@nlohmann
Copy link
Owner

nlohmann commented Oct 2, 2017

@tdegeus All but 1 warnings should be gone now. I tried to fix the last one, but ran into a compiler issue, see #761. Could you try the latest develop version please?

@tdegeus
Copy link
Author

tdegeus commented Oct 2, 2017

@nlohmann Great, thanks! I have compiled with the latest develop version. It works. As predicted the only compiler warning that remains is

...json/json.hpp(6663): warning #186: pointless comparison of unsigned integer with zero
          const bool is_negative = x < 0;
                                     ^
          detected during:
            instantiation of "void nlohmann::detail::serializer<BasicJsonType>::dump_integer(NumberType) [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>, NumberType=uint64_t={unsigned long}, <unnamed>=0]" at line 6290
            instantiation of "void nlohmann::detail::serializer<BasicJsonType>::dump(const BasicJsonType &, bool, bool, unsigned int, unsigned int) [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>]" at line 8995
            instantiation of "nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::string_t nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::dump(int, char, bool) const [with ObjectType=std::map, ArrayType=std::vector, StringType=std::string, BooleanType=bool,
                      NumberIntegerType=int64_t={long}, NumberUnsignedType=uint64_t={unsigned long}, NumberFloatType=double, AllocatorType=std::allocator, JSONSerializer=nlohmann::adl_serializer]" at line 14655

@nlohmann
Copy link
Owner

nlohmann commented Oct 2, 2017

Meanwhile, I tried to get ICC running on Travis (see https://travis-ci.org/nlohmann/json/jobs/282297971), but it fails to compile so far. Maybe someone has an idea how to fix this.

@gregmarr
Copy link
Contributor

gregmarr commented Oct 2, 2017

Maybe this would help:

const bool is_negative = std::is_same<NumberType, number_integer_t>::value && (x < 0);

nlohmann added a commit that referenced this issue Oct 2, 2017
@nlohmann
Copy link
Owner

nlohmann commented Oct 2, 2017

@gregmarr Thanks!

@nlohmann
Copy link
Owner

nlohmann commented Oct 4, 2017

@tdegeus Did the last change fix the last warning? If so, I would close this issue.

@tdegeus
Copy link
Author

tdegeus commented Oct 4, 2017

@nlohmann and @gregmarr Unfortunately the warning is persistent:

json.hpp(6659): warning #186: pointless comparison of unsigned integer with zero
          const bool is_negative = std::is_same<NumberType, number_integer_t>::value and (x < 0);
                                                                                            ^
          detected during:
            instantiation of "void nlohmann::detail::serializer<BasicJsonType>::dump_integer(NumberType) [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>, NumberType=uint64_t={unsigned long}, <unnamed>=0]" at line 6286
            instantiation of "void nlohmann::detail::serializer<BasicJsonType>::dump(const BasicJsonType &, bool, bool, unsigned int, unsigned int) [with BasicJsonType=nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t={long}, uint64_t={unsigned long}, double, std::allocator, nlohmann::adl_serializer>]" at line 8976
            instantiation of "nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::string_t nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::dump(int, char, bool) const [with ObjectType=std::map, ArrayType=std::vector, StringType=std::string, BooleanType=bool,
                      NumberIntegerType=int64_t={long}, NumberUnsignedType=uint64_t={unsigned long}, NumberFloatType=double, AllocatorType=std::allocator, JSONSerializer=nlohmann::adl_serializer]" at line 14636

@gregmarr
Copy link
Contributor

gregmarr commented Oct 4, 2017

Maybe we can fake it out a bit by doing the test in two parts:

const bool is_negative = (x <= 0) and (x != 0);

@tdegeus Can you try with that and see if it works?

@tdegeus
Copy link
Author

tdegeus commented Oct 4, 2017

@gregmarr I can confirms this fix.

I am now left with the following compiler warnings:

remark #11074: Inlining inhibited by limit max-size
remark #11074: Inlining inhibited by limit max-total-size
remark #11076: To get full report use -qopt-report=4 -qopt-report-phase ipo

@gregmarr
Copy link
Contributor

gregmarr commented Oct 4, 2017

Awesome. I would expect that you'll need to disable those messages on your end.

https://software.intel.com/en-us/forums/intel-c-compiler/topic/600543

@tdegeus
Copy link
Author

tdegeus commented Oct 4, 2017

Great!

(As for the Intel specific warnings. It seems that switching of the limits lets the memory usage of the compiler explode. At the moment I don't know which part of my code is most responsible. Disabling the warnings seems to be impossible in combination with keeping other compiler warnings)

nlohmann added a commit that referenced this issue Oct 4, 2017
@nlohmann
Copy link
Owner

nlohmann commented Oct 4, 2017

Thanks everybody!

@nlohmann nlohmann closed this as completed Oct 4, 2017
@kaidokert
Copy link
Contributor

kaidokert commented Jan 19, 2018

Just FYI, gcc-5.2 reports on this:

/opt/m/cbor/../ext/nlohmann _json/src/json.hpp:7047:43: error: logical 'and' of mutually exclusive tests is always false [-Werror=logical-op]
         const bool is_negative = (x <= 0) and (x != 0);  // see issue #755

@zakalibit
Copy link

I changed to this and it makes compiler happy

const bool is_negative = !(x>=0);

nlohmann added a commit that referenced this issue Sep 29, 2018
nlohmann added a commit that referenced this issue Sep 29, 2018
@TedLyngmo
Copy link
Contributor

TedLyngmo commented Nov 21, 2018

Hi! I still have this issue (although with an old unsupported clang 3.3.1 based compiler) but I managed to remove the warning by creating these templates:

    template<typename NumberType, detail::enable_if_t<
                 std::is_same<NumberType, number_unsigned_t>::value, int> = 0>
    bool is_negative_integer(NumberType x) { return false; }

    template<typename NumberType, detail::enable_if_t<
                 std::is_same<NumberType, number_integer_t>::value, int> = 0>
    bool is_negative_integer(NumberType x) { return x<0; }

and in dump_integer(NumberType x):

const bool is_negative = is_negative_integer(x); // see issue #755 

I don't know exactly where to put these templates to make a proper pull request. Right now I just put them above dump_integer() to try it out.

Would a change like this break something else? If not, can someone help me to find the proper place for the templates and I'll make a pull request out of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug platform: icc related to Intel compiler release item: 🔨 further change solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants