[PATCH] D74094: Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 1 03:10:20 PDT 2023


alexfh added a comment.

In D74094#4633785 <https://reviews.llvm.org/D74094#4633785>, @alexfh wrote:

> This commit caused invalid AddressSanitizer: stack-use-after-scope errors in our internal setup. Trying to create a standalone repro, but so far we think that the patch is incorrect. @vitalybuka says "The patch seems wrong, callee can return a reference to temp, so lifetime should be extended to full expression."

A standalone reproducer is here: https://gcc.godbolt.org/z/Ed1s15Kv5. The test passes when compiled with clang before this patch, and generates a bogus address sanitizer error after this patch. This only happens with `-march=haswell`.

The affected code is:

  #include <unsupported/Eigen/CXX11/Tensor>
  #include <gtest/gtest.h>
  #include <gmock/gmock.h>
  #include <absl/types/span.h>
  
  template <typename Tensor>
  auto AsArray(const Tensor& t)
      -> absl::Span<const typename Tensor::Scalar> {
    return {t.data(), (size_t)t.size()};
  }
  using testing::ElementsAre;
  
  int main() {
    using Tensor = Eigen::TensorFixedSize<float, Eigen::Sizes<2, 2>,
                                         Eigen::RowMajor, Eigen::DenseIndex>;
    Tensor a;
    a.setValues({{1, 2}, {3, 4}});
    auto round = [](Tensor m) {
      return (m + 0.5f).cast<int>().cast<float>();
    };
  
    const Tensor t3 = round(a.log().exp());
    EXPECT_THAT(AsArray(t3), ElementsAre(1, 2, 3, 4));
  }

The problem reproduces with `clang -std=c++17 -O3 -fsanitize=address -march=haswell`.

I'm going to revert the commit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74094/new/

https://reviews.llvm.org/D74094



More information about the cfe-commits mailing list