[PATCH] D116590: [flang] Separate temporary and user-specified object files

Andrzej Warzynski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 4 03:12:36 PST 2022


awarzynski created this revision.
Herald added a project: Flang.
awarzynski requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.

This patch updates the `flang` bash scripts to differentiate between
object files provided by the user and intermediate object files
generated by the script. The latter are an "implementation detail" that
should not be visible to the end user (i.e. deleted before the scripts
exits). The former should be preserved.

Fixes https://github.com/flang-compiler/f18-llvm-project/issues/1348


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116590

Files:
  flang/tools/f18/flang


Index: flang/tools/f18/flang
===================================================================
--- flang/tools/f18/flang
+++ flang/tools/f18/flang
@@ -123,14 +123,15 @@
 #   $2 - Fortran source files extracted from $1 (array, name reference)
 #   $3 - other source files extracted from $1 (array, name reference)
 #   $4 - object files extracted from $1 (array, name reference)
-#   $4 - lib files extracted from $1 (array, name reference)
+#   $5 - lib files extracted from $1 (array, name reference)
 # =============================================================================
 categorise_files()
 {
   local -n -r all_files=$1
   local -n fortran_sources=$2
   local -n other_sources=$3
-  local -n libs=$4
+  local -n objects=$4
+  local -n libs=$5
 
   for current_file in "${all_files[@]}"; do
     file_ext=${current_file##*.}
@@ -144,7 +145,7 @@
     elif [[ $file_ext == "a" ]] || [[ $file_ext == "so" ]]; then
       libs+=($current_file)
     elif [[ $file_ext == "o" ]]; then
-      object_files+=($current_file)
+      objects+=($current_file)
     else
       other_sources+=($current_file)
     fi
@@ -330,6 +331,7 @@
     exit 0
   fi
 
+  # Source, object and library files provided by the user
   local fortran_source_files=()
   local other_source_files=()
   local object_files=()
@@ -388,6 +390,8 @@
 
   # STEP 2: Compile Fortran Source Files
   readonly ext_fc="${F18_FC:-gfortran}"
+  # Temporary object files generated by this script. To be deleted at the end.
+  local temp_object_files=()
   for idx in "${!fortran_source_files[@]}"; do
     # We always have to specify the output name with `-o <out_obj_file>`. This
     # is because we are using the unparsed rather than the original source file
@@ -402,7 +406,7 @@
       echo flang: in "$PWD", "$ext_fc" failed with exit status "$ret_status": "$ext_fc" "${ext_fc_options[@]}" "$@" >&2
          exit "$ret_status"
     fi
-    object_files+=(${out_obj_file})
+    temp_object_files+=(${out_obj_file})
   done
 
   # Delete the unparsed files
@@ -425,7 +429,7 @@
       echo flang: in "$PWD", "$ext_fc" failed with exit status "$ret_status": "$ext_fc" "${ext_fc_options[@]}" "$@" >&2
          exit "$ret_status"
     fi
-    object_files+=(${out_obj_file})
+    temp_object_files+=(${out_obj_file})
   done
 
   # STEP 4: Link
@@ -433,7 +437,7 @@
     exit 0;
   fi
 
-  if [[ ${#object_files[@]} -ge 1 ]]; then
+  if [[ ${#temp_object_files[@]} -ge 1 ]] || [[ ${#object_files[@]} -ge 1 ]] ; then
     # If $OUTPUT_FILE was specified, use it for the output name.
     if [[ ! -z ${OUTPUT_FILE:+x} ]]; then
       output_definition="-o $OUTPUT_FILE"
@@ -442,7 +446,7 @@
     fi
 
     set +e
-    $ext_fc "${ext_fc_options[@]}" "${object_files[@]}" "${lib_files[@]}" ${output_definition:+$output_definition}
+    $ext_fc "${ext_fc_options[@]}" "${object_files[@]}" "${temp_object_files[@]}" "${lib_files[@]}" ${output_definition:+$output_definition}
     ret_status=$?
     set -e
     if [[ $ret_status != 0 ]]; then
@@ -453,7 +457,7 @@
 
   # Delete intermediate object files
   for idx in "${!fortran_source_files[@]}"; do
-    rm "${object_files[$idx]}"
+    rm "${temp_object_files[$idx]}"
   done
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116590.397249.patch
Type: text/x-patch
Size: 3194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220104/c34bdc85/attachment.bin>


More information about the llvm-commits mailing list