[Bug c++/59895] New: Updates to global variables not consistent across translation units when FLTO is enabled

adob321 at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Jan 21 01:05:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59895

            Bug ID: 59895
           Summary: Updates to global variables not consistent across
                    translation units when FLTO is enabled
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: adob321 at gmail dot com

Created attachment 31902
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31902&action=edit
PoC code

Modifications of global variables are sometimes not carried out properly when
FLTO is enabled. Short PoC follows.

// FILE bug-flto.cpp //
#include <vector>
#include <stdio.h>

#include "shared.h"

std::vector<int> globalvec;

S1::S1() {
    printf("S1() called\n");
    globalvec.push_back(42);
    printf("S1() globalvec.size() = %d\n", (int) globalvec.size());
}

int main() {
    printf("main globalvec.size() = %d\n", (int) globalvec.size());
    return 0;
}

// FILE tu2.cpp
#include "shared.h"

S1 s1;

// FILE shared.h
#pragma once

struct S1 {
    S1();
};

// FILE Makefile
run: bug-flto
    ./bug-flto

bug-flto: bug-flto.o tu2.o
    g++-4.8 -O -flto -obug-flto bug-flto.o tu2.o

bug-flto.o: bug-flto.cpp
    g++-4.8 -O -flto -obug-flto.o -c bug-flto.cpp

tu2.o: tu2.cpp
    g++-4.8 -O -flto -otu2.o -c tu2.cpp

clean:
    rm *.o
    rm



More information about the Gcc-bugs mailing list