llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Flang] Dangling references when building with the latest gcc

Open ceseo opened this issue 3 years ago • 2 comments

When building Flang with the most current gcc (top of the tree), I'm seeing:

FAILED: tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/ConvertCall.cpp.o 
/usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D_LIBCPP_ENABLE_HARDENED_MODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/flang/lib/Lower -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/lib/Lower -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/llvm/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/llvm/../mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/clang/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/llvm/../clang/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy -Wno-ctad-maybe-unsupported -fno-strict-aliasing -fno-semantic-interposition -O3 -DNDEBUG -fno-semantic-interposition  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/ConvertCall.cpp.o -MF tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/ConvertCall.cpp.o.d -o tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/ConvertCall.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/lib/Lower/ConvertCall.cpp
../llvm-project/flang/lib/Lower/ConvertCall.cpp: In member function ‘bool {anonymous}::ElementalUserCallBuilder::canLoadActualArgumentBeforeLoop(unsigned int) const’:
../llvm-project/flang/lib/Lower/ConvertCall.cpp:1700:17: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
 1700 |     const auto &arg = caller.getPassedArguments()[argIdx];
      |                 ^~~
../llvm-project/flang/lib/Lower/ConvertCall.cpp:1700:57: note: the temporary was destroyed at the end of the full expression ‘(&((const {anonymous}::ElementalUserCallBuilder*)this)->{anonymous}::ElementalUserCallBuilder::caller)->Fortran::lower::CallerInterface::<anonymous>.Fortran::lower::CallInterface<Fortran::lower::CallerInterface>::getPassedArguments().llvm::ArrayRef<Fortran::lower::CallInterface<Fortran::lower::CallerInterface>::PassedEntity>::operator[](((size_t)argIdx))’
 1700 |     const auto &arg = caller.getPassedArguments()[argIdx];
      |                                                         ^
cc1plus: all warnings being treated as errors
972.047 [110/3/6232] Building CXX object tools/flang/lib/Semantics/CMakeFiles/obj.FortranSemantics.dir/runtime-type-info.cpp.o
FAILED: tools/flang/lib/Semantics/CMakeFiles/obj.FortranSemantics.dir/runtime-type-info.cpp.o 
/usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D_LIBCPP_ENABLE_HARDENED_MODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/flang/lib/Semantics -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/lib/Semantics -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/llvm/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/llvm/../mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/clang/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/llvm/../clang/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy -Wno-ctad-maybe-unsupported -fno-strict-aliasing -fno-semantic-interposition -O3 -DNDEBUG -fno-semantic-interposition  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/flang/lib/Semantics/CMakeFiles/obj.FortranSemantics.dir/runtime-type-info.cpp.o -MF tools/flang/lib/Semantics/CMakeFiles/obj.FortranSemantics.dir/runtime-type-info.cpp.o.d -o tools/flang/lib/Semantics/CMakeFiles/obj.FortranSemantics.dir/runtime-type-info.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/lib/Semantics/runtime-type-info.cpp
../llvm-project/flang/lib/Semantics/runtime-type-info.cpp: In function ‘Fortran::semantics::SomeExpr Fortran::semantics::SaveDerivedPointerTarget(Scope&, SourceName, std::vector<Fortran::evaluate::StructureConstructor>&&, Fortran::evaluate::ConstantSubscripts&&)’:
../llvm-project/flang/lib/Semantics/runtime-type-info.cpp:205:17: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
  205 |     const auto &derivedType{x.front().GetType().GetDerivedTypeSpec()};
      |                 ^~~~~~~~~~~
../llvm-project/flang/lib/Semantics/runtime-type-info.cpp:205:67: note: the temporary was destroyed at the end of the full expression ‘(&(& x)->std::vector<Fortran::evaluate::StructureConstructor>::front())->Fortran::evaluate::StructureConstructor::GetType().Fortran::evaluate::DynamicType::GetDerivedTypeSpec()’
  205 |     const auto &derivedType{x.front().GetType().GetDerivedTypeSpec()};
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
cc1plus: all warnings being treated as errors
1056.665 [110/2/6233] Building CXX object tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/OpenMP.cpp.o
FAILED: tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/OpenMP.cpp.o 
/usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D_LIBCPP_ENABLE_HARDENED_MODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/flang/lib/Lower -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/lib/Lower -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/include -I/home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/llvm/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/llvm/../mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/build/tools/clang/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/llvm/../clang/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy -Wno-ctad-maybe-unsupported -fno-strict-aliasing -fno-semantic-interposition -O3 -DNDEBUG -fno-semantic-interposition  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/OpenMP.cpp.o -MF tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/OpenMP.cpp.o.d -o tools/flang/lib/Lower/CMakeFiles/obj.FortranLower.dir/OpenMP.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-latest-gcc/llvm-project/flang/lib/Lower/OpenMP.cpp
../llvm-project/flang/lib/Lower/OpenMP.cpp: In function ‘bool checkForSymbolMatch(const Fortran::parser::AssignmentStmt&)’:
../llvm-project/flang/lib/Lower/OpenMP.cpp:2193:37: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
 2193 |   const Fortran::semantics::Symbol &varSymbol =
      |                                     ^~~~~~~~~
../llvm-project/flang/lib/Lower/OpenMP.cpp:2194:52: note: the temporary was destroyed at the end of the full expression ‘(& Fortran::evaluate::GetSymbolVector(const A&) [with A = Expr<SomeType>; SymbolVector = std::vector<Fortran::common::Reference<const Fortran::semantics::Symbol> >]().std::vector<Fortran::common::Reference<const Fortran::semantics::Symbol> >::front())->Fortran::common::Reference<const Fortran::semantics::Symbol>::operator std::conditional_t<true, const Fortran::semantics::Symbol&, void>()’
 2194 |       Fortran::evaluate::GetSymbolVector(*v).front();
      |                                                    ^
cc1plus: all warnings being treated as errors

I cannot reproduce this when building with clang.

I wonder if this is a real problem or a gcc issue.

ceseo avatar Jul 28 '23 14:07 ceseo

These look like valid warnings of problems that should be fixed, which should be easy to do.

klausler avatar Jul 28 '23 15:07 klausler

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Assign the issue to you.
  2. Fix the issue locally.
  3. Run the test suite locally. 3.1) Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  4. Create a git commit
  5. Run git clang-format HEAD~1 to format your changes.
  6. Submit the patch to Phabricator. 6.1) Detailed instructions can be found here

For more instructions on how to submit a patch to LLVM, see our documentation.

If you have any further questions about this issue, don't hesitate to ask via a comment on this Github issue.

@llvm/issue-subscribers-good-first-issue

llvmbot avatar Jul 28 '23 15:07 llvmbot