Make -J 8 G++: Internal Compiler Error: Killed (Program Cc1Plus)

g++ internal compiler error segmentation fault with recursive constexpr

The error comes from a stack overflow internally in g++. I was allegedly able to increase the stack (on macOS 10.11.6). However, it did not resolve the issue at hand.
I came up with another solution, to split the check into two branches, here is the code:

constexpr bool checkForPrimeNumber(const int p, const int t, const int hi)
{
return p < hi and (p <= t or (p % t and checkForPrimeNumber(p, t + 2, hi)));
}

constexpr bool checkForPrimeNumber(const int p)
{
return p == 2 or (p & 1 and (checkForPrimeNumber(p, 3, 32768) or checkForPrimeNumber(p, 3+32768, 65536)));
}

int main()
{
static_assert(checkForPrimeNumber(65521), "");
}

Thanks

Edit:

As suggested in the comments a solution may be to use C++14:

constexpr bool checkForPrimeNumber(const int p)
{
if (p < 2)
return false;
if (p == 2)
return true;
if (~p & 1)
return false;
for (int i = 3; i < p; i += 2)
{
if (p % i == 0)
return false;
}
return true;
}

How can I solve the lto1: internal compiler error: in lto_tag_to_tree_code, at lto-streamer.h:1005 that appears after 'make' command

"Internal compiler error" sounds like there's a bug in the compiler, so here are some ideas to try to work around it.

You could try compiling it with clang++ instead of g++. Install it using:

sudo apt-get install clang

Then build using something like:

CC=clang CXX=clang++ LD=clang make

Because the error mentions lto, you could also turning link-time optimization off:

LDFLAGS=-fno-lto make

g++ 4.8.1 on Ubuntu can't compile large bitsets

On my machine, g++ 4.8.1 needs a maximum of about 17 gigabytes of RAM to compile this file, as observed with top.

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
18287 nm 20 0 17.880g 0.014t 808 D 16.6 95.7 0:17.72 cc1plus

't' in the RES column stands for terabytes ;)

The time taken is

real    1m25.283s
user 0m31.279s
sys 0m5.819s

In the C++03 mode, g++ compiles the same file using just a few megabytes. The time taken is

real    0m0.107s
user 0m0.074s
sys 0m0.011s

I would say this is definitely a bug. A workaround is to give the machine more RAM, or enable swap. Or use clang++.

Compiling larger (~6MB) map initializing C++ file with gcc

The compiler is allowed to put implementation defined limits on the amount of supported levels/quantities in many language constructs.

Appendix B lists the minimum quantities required for a conforming compiler.

From Appendix B, bolding the most relevant ones:

The limits may constrain quantities that include those described below or
others. The bracketed number following each quantity is recommended as the
minimum for that quantity. However, these quantities are only guidelines and do
not determine compliance.

  • Nesting levels of compound statements, iteration control structures, and selection control structures
    [256].
  • Nesting levels of conditional inclusion [256].
  • Pointer, array, and function declarators (in any combination) modifying a class, arithmetic, or incom-
    plete type in a declaration [256].
  • Nesting levels of parenthesized expressions within a full-expression [256].
  • Number of characters in an internal identifier or macro name [1 024].
  • Number of characters in an external identifier [1 024].
  • External identifiers in one translation unit [65 536].
  • Identifiers with block scope declared in one block [1 024].
  • Macro identifiers simultaneously defined in one translation unit [65 536].
  • Parameters in one function definition [256].
  • Arguments in one function call [256].
  • Parameters in one macro definition [256].
  • Arguments in one macro invocation [256].
  • Characters in one logical source line [65 536].
  • Characters in a string literal (after concatenation) [65 536].
  • Size of an object [262 144].
  • Nesting levels for #include files [256].
  • Case labels for a switch statement (excluding those for any nested switch statements) [16 384].
  • Data members in a single class [16 384].
  • Enumeration constants in a single enumeration [4 096].
  • Levels of nested class definitions in a single member-specification [256]
  • Functions registered by atexit() [32].
  • Functions registered by at_quick_exit() [32].
  • Direct and indirect base classes [16 384].
  • Direct base classes for a single class [1 024].
  • Members declared in a single class [4 096].
  • Final overriding virtual functions in a class, accessible or not [16 384].
  • Direct and indirect virtual bases of a class [1 024].
  • Static members of a class [1 024].
  • Friend declarations in a class [4 096].
  • Access control declarations in a class [4 096].
  • Member initializers in a constructor definition [6 144].
  • Scope qualifications of one identifier [256].
  • Nested external specifications [1 024].
  • Recursive constexpr function invocations [512].
  • Template arguments in a template declaration [1 024].
  • Recursively nested template instantiations, including substitution during template argument deduction (14.8.2) [1 024].
  • Handlers per try block [256].
  • Throw specifications on a single function declaration [256].
  • Number of placeholders (20.8.9.1.4) [10]

Now, initializer lists are actually just 'constructed' from a number of arguments and apparently GCC doesn't quite support the quantity/volume you provided.

There might be options in the man page to alleviate this:

  • -mlarge-data (which is the default)
  • -mlarge-text (also the default)


Related Topics



Leave a reply



Submit