Skip to content

Revert "[Flang][Driver] Add a flag to control zero initialization of global v…" #123067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

kiranchandramohan
Copy link
Contributor

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' flang:driver flang Flang issues not falling into any other category flang:fir-hlfir labels Jan 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 15, 2025

@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-flang-fir-hlfir

@llvm/pr-subscribers-clang

Author: Kiran Chandramohan (kiranchandramohan)

Changes

Reverts llvm/llvm-project#122144

Reverting due to CI failure https://lab.llvm.org/buildbot/#/builders/89/builds/14422


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

8 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (-5)
  • (modified) clang/lib/Driver/ToolChains/Flang.cpp (+1-3)
  • (modified) flang/include/flang/Lower/LoweringOptions.def (-3)
  • (modified) flang/lib/Frontend/CompilerInvocation.cpp (-8)
  • (modified) flang/lib/Lower/ConvertVariable.cpp (+1-5)
  • (removed) flang/test/Driver/fno-zero-init.f90 (-9)
  • (removed) flang/test/Lower/zero_init.f90 (-17)
  • (removed) flang/test/Lower/zero_init_default_init.f90 (-19)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index dacfca910acc40..2721c1b5d8dc55 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3505,11 +3505,6 @@ def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, Group<f_Group>;
 def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group<f_Group>;
 def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group<f_Group>,
   Visibility<[ClangOption, FlangOption]>;
-defm init_global_zero : BoolOptionWithoutMarshalling<"f", "init-global-zero",
-  PosFlag<SetTrue, [], [FlangOption, FC1Option],
-          "Zero initialize globals without default initialization (default)">,
-  NegFlag<SetFalse, [], [FlangOption, FC1Option],
-          "Do not zero initialize globals without default initialization">>;
 def fno_pointer_tbaa : Flag<["-"], "fno-pointer-tbaa">, Group<f_Group>;
 def fno_temp_file : Flag<["-"], "fno-temp-file">, Group<f_Group>,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, HelpText<
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index c46e8222a9631a..a7d0cc99f27d2d 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -155,9 +155,7 @@ void Flang::addCodegenOptions(const ArgList &Args,
                    options::OPT_flang_deprecated_no_hlfir,
                    options::OPT_fno_ppc_native_vec_elem_order,
                    options::OPT_fppc_native_vec_elem_order,
-                   options::OPT_finit_global_zero,
-                   options::OPT_fno_init_global_zero, options::OPT_ftime_report,
-                   options::OPT_ftime_report_EQ});
+                   options::OPT_ftime_report, options::OPT_ftime_report_EQ});
 }
 
 void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
diff --git a/flang/include/flang/Lower/LoweringOptions.def b/flang/include/flang/Lower/LoweringOptions.def
index 396c91948be36b..5a6debfdffe030 100644
--- a/flang/include/flang/Lower/LoweringOptions.def
+++ b/flang/include/flang/Lower/LoweringOptions.def
@@ -44,8 +44,5 @@ ENUM_LOWERINGOPT(IntegerWrapAround, unsigned, 1, 0)
 /// If false, assume that the shapes/types/allocation-status match.
 ENUM_LOWERINGOPT(ReallocateLHS, unsigned, 1, 1)
 
-/// If true, initialize globals without initialization to zero.
-/// On by default.
-ENUM_LOWERINGOPT(InitGlobalZero, unsigned, 1, 1)
 #undef LOWERINGOPT
 #undef ENUM_LOWERINGOPT
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 78d1199c19749b..5e7127313c1335 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1373,14 +1373,6 @@ bool CompilerInvocation::createFromArgs(
     invoc.loweringOpts.setNoPPCNativeVecElemOrder(true);
   }
 
-  // -f[no-]init-global-zero
-  if (args.hasFlag(clang::driver::options::OPT_finit_global_zero,
-                   clang::driver::options::OPT_fno_init_global_zero,
-                   /*default=*/true))
-    invoc.loweringOpts.setInitGlobalZero(true);
-  else
-    invoc.loweringOpts.setInitGlobalZero(false);
-
   // Preserve all the remark options requested, i.e. -Rpass, -Rpass-missed or
   // -Rpass-analysis. This will be used later when processing and outputting the
   // remarks generated by LLVM in ExecuteCompilerInvocation.cpp.
diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index 87236dc293ebbc..9ee42d5cd88002 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -635,11 +635,7 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter,
       global.setLinkName(builder.createCommonLinkage());
     Fortran::lower::createGlobalInitialization(
         builder, global, [&](fir::FirOpBuilder &builder) {
-          mlir::Value initValue;
-          if (converter.getLoweringOptions().getInitGlobalZero())
-            initValue = builder.create<fir::ZeroOp>(loc, symTy);
-          else
-            initValue = builder.create<fir::UndefOp>(loc, symTy);
+          mlir::Value initValue = builder.create<fir::ZeroOp>(loc, symTy);
           builder.create<fir::HasValueOp>(loc, initValue);
         });
   }
diff --git a/flang/test/Driver/fno-zero-init.f90 b/flang/test/Driver/fno-zero-init.f90
deleted file mode 100644
index 2ffa10dd040d52..00000000000000
--- a/flang/test/Driver/fno-zero-init.f90
+++ /dev/null
@@ -1,9 +0,0 @@
-! Check that the driver passes through -f[no-]init-global-zero:
-! RUN: %flang -### -S -finit-global-zero %s -o - 2>&1 | FileCheck --check-prefix=CHECK-POS %s
-! RUN: %flang -### -S -fno-init-global-zero %s -o - 2>&1 | FileCheck --check-prefix=CHECK-NEG %s
-! Check that the compiler accepts -f[no-]init-global-zero:
-! RUN: %flang_fc1 -emit-hlfir -finit-global-zero %s -o -
-! RUN: %flang_fc1 -emit-hlfir -fno-init-global-zero %s -o -
-
-! CHECK-POS: "-fc1"{{.*}}"-finit-global-zero"
-! CHECK-NEG: "-fc1"{{.*}}"-fno-init-global-zero"
diff --git a/flang/test/Lower/zero_init.f90 b/flang/test/Lower/zero_init.f90
deleted file mode 100644
index 89e6584f410f7c..00000000000000
--- a/flang/test/Lower/zero_init.f90
+++ /dev/null
@@ -1,17 +0,0 @@
-! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-DEFAULT %s
-! RUN: %flang_fc1 -finit-global-zero -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-DEFAULT %s
-! RUN: %flang_fc1 -fno-init-global-zero -emit-hlfir -o - %s | FileCheck --check-prefix=CHECK-NO-ZERO-INIT %s
-
-module m1
-  real :: x
-end module m1
-
-!CHECK-DEFAULT: fir.global @_QMm1Ex : f32 {
-!CHECK-DEFAULT:   %[[UNDEF:.*]] = fir.zero_bits f32
-!CHECK-DEFAULT:   fir.has_value %[[UNDEF]] : f32
-!CHECK-DEFAULT: }
-
-!CHECK-NO-ZERO-INIT: fir.global @_QMm1Ex : f32 {
-!CHECK-NO-ZERO-INIT:   %[[UNDEF:.*]] = fir.undefined f32
-!CHECK-NO-ZERO-INIT:   fir.has_value %[[UNDEF]] : f32
-!CHECK-NO-ZERO-INIT: }
diff --git a/flang/test/Lower/zero_init_default_init.f90 b/flang/test/Lower/zero_init_default_init.f90
deleted file mode 100644
index 761052b5b08a0e..00000000000000
--- a/flang/test/Lower/zero_init_default_init.f90
+++ /dev/null
@@ -1,19 +0,0 @@
-! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck %s
-! RUN: %flang_fc1 -finit-global-zero -emit-hlfir -o - %s | FileCheck %s
-! RUN: %flang_fc1 -fno-init-global-zero -emit-hlfir -o - %s | FileCheck %s
-
-! Test that the flag does not affect globals with default init
-
-module m2
-  type val
-    integer :: my_val = 1
-  end type val
-  type(val) :: v1
-end module m2
-
-!CHECK:  fir.global @_QMm2Ev1 : !fir.type<_QMm2Tval{my_val:i32}> {
-!CHECK:    %[[V1:.*]] = fir.undefined !fir.type<_QMm2Tval{my_val:i32}>
-!CHECK:    %[[ONE:.*]] = arith.constant 1 : i32
-!CHECK:    %[[V1_INIT:.*]] = fir.insert_value %[[V1]], %[[ONE]], ["my_val", !fir.type<_QMm2Tval{my_val:i32}>] : (!fir.type<_QMm2Tval{my_val:i32}>, i32) -> !fir.type<_QMm2Tval{my_val:i32}>
-!CHECK:    fir.has_value %[[V1_INIT]] : !fir.type<_QMm2Tval{my_val:i32}>
-!CHECK:  }

@kiranchandramohan kiranchandramohan merged commit 44ba43a into main Jan 15, 2025
10 of 12 checks passed
@kiranchandramohan kiranchandramohan deleted the revert-122144-zero-init branch January 15, 2025 15:23
kiranchandramohan added a commit to kiranchandramohan/llvm-project that referenced this pull request Jan 15, 2025
…tion of global v…" (llvm#123067)"

This reverts commit 44ba43a.

Adds the flag to bbc as well.
kiranchandramohan added a commit to kiranchandramohan/llvm-project that referenced this pull request Jan 16, 2025
…tion of global v…" (llvm#123067)"

This reverts commit 44ba43a.

Adds the flag to bbc as well.
kiranchandramohan added a commit that referenced this pull request Jan 17, 2025
#123097)

…tion of global v…" (#123067)"

This reverts commit 44ba43a.

Adds the flag to bbc as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category flang:driver flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants