TensorArray.gather crash with Segmentation fault
The **enable_v2_behavior()** function was introduced in TensorFlow 2.0 and is no longer needed in TensorFlow 2.0 and later versions. enable_v2_behavior () is called or # 2) the TF2_BEHAVIOR=1 environment variable is set. Hi @trickiwoo, I was able to replicate the issue using  TF-nightly(2.13.0-dev20230208). Please find the screenshot below.
![image](https://user-images.githubusercontent.com/98147397/228731340-38be6671-5e10-4fa3-836f-ffabd2e20631.png)

Thank you! Thanks @pat749 and @Ruparani777 for pointing out the issue! I checked and found that `enable_v2_behavior` is not needed to trigger this bug, here is the minimized code that triggers Segmentation fault:
```
import tensorflow as tf

@tf.function
def foo():
    ta = tf.TensorArray(dtype=tf.int32, size=0, dynamic_size=True)
    ta.write(0, tf.constant(0))
    return ta.gather([0])

foo()
```
Output:
```
Segmentation fault (core dumped)
``` Use a different version of the library: If the segmentation fault is caused by a bug in a library, then using a different version of the library can sometimes help to remove the error. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60148">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60148">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

Yes

### Source

source

### Tensorflow Version

2.13.0-dev20230208

### Custom Code

Yes

### OS Platform and Distribution

_No response_

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

```shell
TensorArray.gather crash with Segmentation fault
```


### Standalone code to reproduce the issue

```shell
import tensorflow as tf
import numpy as np

tf = tf.compat.v2
tf.enable_v2_behavior()

@tf.function
def foo():
    ta = tf.TensorArray(dtype=tf.int32, size=0, dynamic_size=True)
    ta.write(0, tf.constant(0))
    return ta.gather([0])

foo()
```


### Relevant log output

```shell
Segmentation fault (core dumped)
```
</details>