[flang-commits] [flang] a24421f - [flang][bbc] Fix dangling reference to `envDefaults` (#82800)

via flang-commits flang-commits at lists.llvm.org
Fri Feb 23 10:51:38 PST 2024


Author: Krzysztof Parzyszek
Date: 2024-02-23T12:51:26-06:00
New Revision: a24421fef713e5b3c0a885cf36a62cc3257be1f3

URL: https://github.com/llvm/llvm-project/commit/a24421fef713e5b3c0a885cf36a62cc3257be1f3
DIFF: https://github.com/llvm/llvm-project/commit/a24421fef713e5b3c0a885cf36a62cc3257be1f3.diff

LOG: [flang][bbc] Fix dangling reference to `envDefaults` (#82800)

The lowering bridge stores the evvironment defaults (passed to the
constructor) as a reference. In the call to the constructor in bbc, the
defaults were passed as `{}`, which creates a temporary whose lifetime
ends immediately after the call.

The flang driver passes a member of the compilation instance to the
constructor, which presumably remains alive long enough, so storing the
reference in the bridge is justified. To avoid the dangling reference,
create an actual object `envDefaults` in bbc.

Added: 
    

Modified: 
    flang/tools/bbc/bbc.cpp

Removed: 
    


################################################################################
diff  --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index c9358c83e795c4..e701fdeb227a40 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -354,10 +354,11 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
   loweringOptions.setPolymorphicTypeImpl(enablePolymorphic);
   loweringOptions.setNoPPCNativeVecElemOrder(enableNoPPCNativeVecElemOrder);
   loweringOptions.setLowerToHighLevelFIR(useHLFIR || emitHLFIR);
+  std::vector<Fortran::lower::EnvironmentDefault> envDefaults = {};
   auto burnside = Fortran::lower::LoweringBridge::create(
       ctx, semanticsContext, defKinds, semanticsContext.intrinsics(),
       semanticsContext.targetCharacteristics(), parsing.allCooked(),
-      targetTriple, kindMap, loweringOptions, {},
+      targetTriple, kindMap, loweringOptions, envDefaults,
       semanticsContext.languageFeatures(), targetMachine);
   burnside.lower(parseTree, semanticsContext);
   mlir::ModuleOp mlirModule = burnside.getModule();


        


More information about the flang-commits mailing list