Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang-cl.exe and constexpr depth

I'm using Clang 3.6 with Visual Studio 2015 and I'm using this CRC32 implementation to generate hashes at compile time:

#define CRC32(message) (crc32_<sizeof(message) - 2>(message) ^ 0xFFFFFFFF)

static constexpr uint32_t crc_table[256] = {
  0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
  0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
  ...
};

template<size_t idx>
constexpr uint32_t crc32_(const char * str)
{
  return (crc32_<idx - 1>(str) >> 8) ^ crc_table[(crc32_<idx - 1>(str) ^ str[idx]) & 0x000000FF];
}

#pragma warning(push)
#pragma warning(disable : 4100)

// This is the stop-recursion function
template<>
constexpr uint32_t crc32_<size_t(-1)>(const char * str)
{
  return 0xFFFFFFFF;
}

The problem is that when I use a string larger than 18 characters, clang-cl.exe complains:

constexpr evaluation hit maximum step limit; possible infinite loop?

I've seen some answers about setting -fconstexpr-depth or -fconstexpr-steps. I try to pass that options back to Clang with clang-cl.exe's parameter: -Xclang -fconstexpr-steps=10 but I get:

unknown argument: '-fconstexpr-steps=10'

The interesting thing is that I test the option with clang.exe directly and it recognizes it.

My question is: is there a way to set constexpr steps or constexpr depth with clang-cl.exe?

like image 895
karliwson Avatar asked Sep 06 '25 12:09

karliwson


2 Answers

Use -Xclang -fconstexpr-steps -Xclang 10

clang with gcc-style transforms -fconstexpr-steps=10 into -fconstexpr-steps 10, two separate arguments.

In order to transform two separate arguments from clang-cl you should prefix it with -Xclang two times

like image 112
Kukunin Avatar answered Sep 08 '25 09:09

Kukunin


/clang:-fconstexpr-steps=10

Added in this PR, the /clang flag prefix forwards the remainder of the flag text to the driver, bypassing the MSVC-style frontend. Frustratingly clang-cl does seem to be aware of the equivalent MSVC flag (/constexpr:steps10, docs), but doesn't know what to do with it! You get a "argument unused during compilation" warning and the flag is ignored.

I don't know what the difference between /clang and -Xclang is, the PR and docs listed above differ in their descriptions, but my hunch is that they mean the same thing but clang-cl only acts upon the former.

like image 33
cmannett85 Avatar answered Sep 08 '25 09:09

cmannett85