Skip to content

Conversation

@sebpop
Copy link
Contributor

@sebpop sebpop commented May 7, 2025

when compiling with g++ 13.3.0 flang build on arm64-linux ubuntu 24.04 machine fails with:

llvm-project/flang/lib/Semantics/expression.cpp:424:17: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
424 | const Symbol &coarraySymbol{ref.GetBase().GetLastSymbol()};
| ^~~~~~~~~~~~~
llvm-project/flang/lib/Semantics/expression.cpp:424:58: note: the temporary was destroyed at the end of the full expression ‘Fortran::evaluate::CoarrayRef::GetBase() const().Fortran::evaluate::NamedEntity::GetLastSymbol()’
424 | const Symbol &coarraySymbol{ref.GetBase().GetLastSymbol()};
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

Keep the base in a temporary variable to make sure it is not deleted.

when compiling with g++ 13.3.0 flang build fails with:

llvm-project/flang/lib/Semantics/expression.cpp:424:17: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
424 |   const Symbol &coarraySymbol{ref.GetBase().GetLastSymbol()};
    |                 ^~~~~~~~~~~~~
llvm-project/flang/lib/Semantics/expression.cpp:424:58: note: the temporary was destroyed at the end of the full expression ‘Fortran::evaluate::CoarrayRef::GetBase() const().Fortran::evaluate::NamedEntity::GetLastSymbol()’
424 |   const Symbol &coarraySymbol{ref.GetBase().GetLastSymbol()};
    |                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

Keep the base in a temporary variable to make sure it is not deleted.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels May 7, 2025
@llvmbot
Copy link
Member

llvmbot commented May 7, 2025

@llvm/pr-subscribers-flang-semantics

Author: Sebastian Pop (sebpop)

Changes

when compiling with g++ 13.3.0 flang build fails with:

llvm-project/flang/lib/Semantics/expression.cpp:424:17: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
424 | const Symbol &coarraySymbol{ref.GetBase().GetLastSymbol()};
| ^~~~~~~~~~~~~
llvm-project/flang/lib/Semantics/expression.cpp:424:58: note: the temporary was destroyed at the end of the full expression ‘Fortran::evaluate::CoarrayRef::GetBase() const().Fortran::evaluate::NamedEntity::GetLastSymbol()’
424 | const Symbol &coarraySymbol{ref.GetBase().GetLastSymbol()};
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

Keep the base in a temporary variable to make sure it is not deleted.


Full diff: https://github.com/llvm/llvm-project/pull/138793.diff

1 Files Affected:

  • (modified) flang/lib/Semantics/expression.cpp (+2-1)
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index e139bda7e4950..35eb7b61429fb 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -421,7 +421,8 @@ static void CheckSubscripts(
 
 static void CheckSubscripts(
     semantics::SemanticsContext &context, CoarrayRef &ref) {
-  const Symbol &coarraySymbol{ref.GetBase().GetLastSymbol()};
+  const auto &base = ref.GetBase();
+  const Symbol &coarraySymbol{base.GetLastSymbol()};
   Shape lb, ub;
   if (FoldSubscripts(context, coarraySymbol, ref.subscript(), lb, ub)) {
     ValidateSubscripts(context, coarraySymbol, ref.subscript(), lb, ub);

Copy link
Contributor

@klausler klausler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use braced initialization; otherwise LGTM, and thanks.

static void CheckSubscripts(
semantics::SemanticsContext &context, CoarrayRef &ref) {
const Symbol &coarraySymbol{ref.GetBase().GetLastSymbol()};
const auto &base = ref.GetBase();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use braced initialization here.

@sebpop
Copy link
Contributor Author

sebpop commented May 20, 2025

Abandoning this patch as the code has changed and flang finishes build without errors on my system.

@sebpop sebpop closed this May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants