Commit 0912bc8c authored by Ilya Biryukov's avatar Ilya Biryukov Committed by TensorFlower Gardener
Browse files

Fix 'cc_op_gen' to use static storage for constant arrays.

Previously, the generate would emit code like this:
  struct Attrs {
    ArraySlice<int> dilations_ = {1, 1, 1, 1};
  };

This code is incorrect, since the array slice references a temporary object
that dies after initialization finishes.

After this change change the generator will produce static functions to
initialize the values:
  struct Attrs {
    ArraySlice<int> dilations_ = Default_dilations();

  private:
    ArraySlice<int> Default_dilations() {
      static int kStorage[] = {1, 1, 1, 1};
      return ArraySlice<int>(kStorage);
    }
  };

Presumably, it used to work because all compilers chose to use static storage
in those cases anyway. However, new versions of clang tend to miscompile this
code, causing test failures. (This error was found when trying to upgrade our
clang revision from r328903 to r331746).

PiperOrigin-RevId: 200110952
parent 21aa82e1
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment