https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83040

            Bug ID: 83040
           Summary: __attribute__((always_inline)) causes
                    internal_compiler_error (segmentation fault)
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jj804785 at wcupa dot edu
  Target Milestone: ---

gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 
Flags: g++ -fopenmp -ftemplate-depth=1000000 -std=c++17 -O3 -Wall -c
-fmessage-length=0

IDE (Eclipse_Oxygen)

If you remove the __attribute__((always_inline)) the code compiles fine

Code... 

#include <iostream>
#include <omp.h>
#include "math.h"
#include "time.h"
#include <stdio.h>

template<int sz, class T>
struct adder {

        __attribute__((always_inline)) static void add(T* eval_to, T* a, T* b)
{
                eval_to[sz] = a[sz] + b[sz];
                adder<sz - 1, T>::add(eval_to, a, b);
        }
};

template<class T>
struct adder<0, T> {

        static void add(T* eval_to, T* a, T* b) {
                eval_to[0] = a[0] + b[0];
        }
};

void dumb_add(double* a, double* b, double* c, int sz) {
        for (int i = 0; i < sz; ++i) {
                a[i] = b[i] + c[i];
        }
}

int main() {

        const int sz = 60000;

        double* a = new double[sz];
        double* b = new double[sz];
        double* c = new double[sz];

        for (int i = 0; i < sz; ++i) {
                a[i] = rand();
                b[i] = rand();
                c[i] = rand();

        }

        clock_t t;
        t = clock();
        printf("Calculating...\n");
        for (int i = 0; i < 1000; ++i)
        adder<sz, double>::add(a, b, c);

        t = clock() - t;
        printf("It took me %d clicks (%f seconds).\n", t, ((float) t) /
CLOCKS_PER_SEC);
        t = clock();
        printf("Calculating...\n");
        for (int i = 0; i < 1000; ++i)

        dumb_add(a, b, c, sz);
        t = clock() - t;
        printf("It took me %d clicks (%f seconds).\n", t, ((float) t) /
CLOCKS_PER_SEC);

        delete[] a;
        delete[] b;
        delete[] c;
        return 0;
}

Reply via email to