@@ -155,6 +155,47 @@ TEST(ATenBridgeTest, AliasTensorPtrToATenTensor) {
155155 EXPECT_EQ (at_tensor.const_data_ptr (), et_tensor_ptr->const_data_ptr ());
156156}
157157
158+ // 0-dim (scalar) tensors legitimately have empty sizes/strides arrays whose
159+ // `.data()` may return nullptr. Regression test for T270603238: ensure
160+ // check_tensor_meta does not abort on valid 0-dim tensors. We pass nullptr
161+ // explicitly for sizes/dim_order/strides because std::vector::data() on an
162+ // empty vector is implementation-defined (libstdc++/libc++ may return a
163+ // non-null sentinel) — using nullptr makes the regression deterministic
164+ // across STL implementations.
165+ TEST (ATenBridgeTest, AliasETensorToATenTensorZeroDim) {
166+ auto at_tensor = at::scalar_tensor (42 .0f );
167+ ASSERT_EQ (at_tensor.dim (), 0 );
168+ auto dtype = torchToExecuTorchScalarType (at_tensor.options ().dtype ());
169+ torch::executor::TensorImpl tensor_impl (
170+ dtype,
171+ /* dim=*/ 0 ,
172+ /* sizes=*/ nullptr ,
173+ /* data=*/ nullptr ,
174+ /* dim_order=*/ nullptr ,
175+ /* strides=*/ nullptr );
176+ torch::executor::Tensor etensor (&tensor_impl);
177+ alias_etensor_to_attensor (at_tensor, etensor);
178+ EXPECT_EQ (at_tensor.const_data_ptr (), etensor.const_data_ptr ());
179+ }
180+
181+ TEST (ATenBridgeTest, AliasATTensorToETensorZeroDim) {
182+ auto at_tensor = at::scalar_tensor (7 );
183+ ASSERT_EQ (at_tensor.dim (), 0 );
184+ auto dtype = torchToExecuTorchScalarType (at_tensor.options ().dtype ());
185+ std::vector<uint8_t > etensor_data (at_tensor.nbytes ());
186+ torch::executor::TensorImpl tensor_impl (
187+ dtype,
188+ /* dim=*/ 0 ,
189+ /* sizes=*/ nullptr ,
190+ etensor_data.data (),
191+ /* dim_order=*/ nullptr ,
192+ /* strides=*/ nullptr );
193+ torch::executor::Tensor etensor (&tensor_impl);
194+ auto aliased_at_tensor = alias_attensor_to_etensor (etensor);
195+ EXPECT_EQ (aliased_at_tensor.dim (), 0 );
196+ EXPECT_EQ (aliased_at_tensor.const_data_ptr (), etensor_data.data ());
197+ }
198+
158199TEST (ATenBridgeTest, AliasATTensorToETensorChannelsLast) {
159200 auto at_tensor = at::randn ({2 , 3 , 4 , 5 }).to (at::MemoryFormat::ChannelsLast);
160201 std::vector<Tensor::SizesType> sizes (
0 commit comments