[PATCH] D94618: [flang] Fix dangling pointer in LabelEnforce

Tim Keith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 13 11:02:03 PST 2021


tskeith created this revision.
tskeith added a project: Flang.
Herald added a subscriber: jdoerfert.
tskeith requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

`DirectiveStructureChecker` was passing in a pointer to a temporary
string for the `construct` argument to the constructor for `LabelEnforce`.
The `LabelEnforce` object had a lifetime longer than the temporary,
resulting in accessing a dangling pointer when emitting an error message
for `omp-parallell01.f90`.

The fix is to make the lifetime of the temporary as long as the lifetime
of the `LabelEnforce` object.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94618

Files:
  flang/lib/Semantics/check-directive-structure.h


Index: flang/lib/Semantics/check-directive-structure.h
===================================================================
--- flang/lib/Semantics/check-directive-structure.h
+++ flang/lib/Semantics/check-directive-structure.h
@@ -280,9 +280,9 @@
       context_, directiveSource, directive, ContextDirectiveAsFortran()};
   parser::Walk(block, noBranchingEnforce);
 
+  auto construct{parser::ToUpperCaseLetters(getDirectiveName(directive).str())};
   LabelEnforce directiveLabelEnforce{context_, noBranchingEnforce.labels(),
-      directiveSource,
-      parser::ToUpperCaseLetters(getDirectiveName(directive).str()).c_str()};
+      directiveSource, construct.c_str()};
   parser::Walk(block, directiveLabelEnforce);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94618.316453.patch
Type: text/x-patch
Size: 726 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210113/046ff465/attachment.bin>


More information about the llvm-commits mailing list