Skip to content
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

Revert "[flang]Add new intrinsic function backtrace and complete the TODO of abort" #117990

Merged
merged 1 commit into from
Nov 28, 2024

Conversation

tblah
Copy link
Contributor

@tblah tblah commented Nov 28, 2024

Reverts #117603 due to failed buildbot https://lab.llvm.org/buildbot/#/builders/152/builds/710

The important bit of the log was

FAILED: CMakeFiles/FortranRuntime.dir/stop.cpp.o 
ccache /usr/bin/g++ -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -DRT_USE_LIBCUDACXX=1 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbot/worker/as-builder-7/ramdisk/flang-runtime-cuda-gcc/llvm-project/flang/runtime/../include -I/home/buildbot/worker/as-builder-7/ramdisk/flang-runtime-cuda-gcc/build -I/home/buildbot/worker/third-party/nv/cccl/libcudacxx/include -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-lto -O3 -DNDEBUG   -U_GLIBCXX_ASSERTIONS -U_LIBCPP_ENABLE_ASSERTIONS -UNDEBUG -std=c++17  -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -MD -MT CMakeFiles/FortranRuntime.dir/stop.cpp.o -MF CMakeFiles/FortranRuntime.dir/stop.cpp.o.d -o CMakeFiles/FortranRuntime.dir/stop.cpp.o -c /home/buildbot/worker/as-builder-7/ramdisk/flang-runtime-cuda-gcc/llvm-project/flang/runtime/stop.cpp
/home/buildbot/worker/as-builder-7/ramdisk/flang-runtime-cuda-gcc/llvm-project/flang/runtime/stop.cpp:19:10: fatal error: llvm/Config/config.h: No such file or directory
   19 | #include "llvm/Config/config.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

CC @dty2

@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category flang:fir-hlfir flang:semantics labels Nov 28, 2024
@tblah tblah merged commit 1858a4e into main Nov 28, 2024
5 of 7 checks passed
@tblah tblah deleted the revert-117603-dty2 branch November 28, 2024 10:43
@llvmbot
Copy link
Member

llvmbot commented Nov 28, 2024

@llvm/pr-subscribers-flang-semantics

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

Author: Tom Eccles (tblah)

Changes

Reverts llvm/llvm-project#117603 due to failed buildbot https://lab.llvm.org/buildbot/#/builders/152/builds/710

The important bit of the log was

FAILED: CMakeFiles/FortranRuntime.dir/stop.cpp.o 
ccache /usr/bin/g++ -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -DRT_USE_LIBCUDACXX=1 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/buildbot/worker/as-builder-7/ramdisk/flang-runtime-cuda-gcc/llvm-project/flang/runtime/../include -I/home/buildbot/worker/as-builder-7/ramdisk/flang-runtime-cuda-gcc/build -I/home/buildbot/worker/third-party/nv/cccl/libcudacxx/include -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-lto -O3 -DNDEBUG   -U_GLIBCXX_ASSERTIONS -U_LIBCPP_ENABLE_ASSERTIONS -UNDEBUG -std=c++17  -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -MD -MT CMakeFiles/FortranRuntime.dir/stop.cpp.o -MF CMakeFiles/FortranRuntime.dir/stop.cpp.o.d -o CMakeFiles/FortranRuntime.dir/stop.cpp.o -c /home/buildbot/worker/as-builder-7/ramdisk/flang-runtime-cuda-gcc/llvm-project/flang/runtime/stop.cpp
/home/buildbot/worker/as-builder-7/ramdisk/flang-runtime-cuda-gcc/llvm-project/flang/runtime/stop.cpp:19:10: fatal error: llvm/Config/config.h: No such file or directory
   19 | #include "llvm/Config/config.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

CC @dty2


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

8 Files Affected:

  • (modified) flang/include/flang/Optimizer/Builder/IntrinsicCall.h (-1)
  • (modified) flang/include/flang/Optimizer/Builder/Runtime/Stop.h (-3)
  • (modified) flang/include/flang/Runtime/stop.h (-1)
  • (modified) flang/lib/Evaluate/intrinsics.cpp (-1)
  • (modified) flang/lib/Optimizer/Builder/IntrinsicCall.cpp (-7)
  • (modified) flang/lib/Optimizer/Builder/Runtime/Stop.cpp (-7)
  • (modified) flang/runtime/stop.cpp (+1-31)
  • (removed) flang/test/Lower/Intrinsics/backtrace.f90 (-10)
diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
index 71955632e48cde..19c623cc1ec006 100644
--- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
+++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h
@@ -196,7 +196,6 @@ struct IntrinsicLibrary {
   fir::ExtendedValue genAssociated(mlir::Type,
                                    llvm::ArrayRef<fir::ExtendedValue>);
   mlir::Value genAtand(mlir::Type, llvm::ArrayRef<mlir::Value>);
-  void genBacktrace(llvm::ArrayRef<fir::ExtendedValue>);
   fir::ExtendedValue genBesselJn(mlir::Type,
                                  llvm::ArrayRef<fir::ExtendedValue>);
   fir::ExtendedValue genBesselYn(mlir::Type,
diff --git a/flang/include/flang/Optimizer/Builder/Runtime/Stop.h b/flang/include/flang/Optimizer/Builder/Runtime/Stop.h
index be73cffff021e3..6f764badf6f3a8 100644
--- a/flang/include/flang/Optimizer/Builder/Runtime/Stop.h
+++ b/flang/include/flang/Optimizer/Builder/Runtime/Stop.h
@@ -30,9 +30,6 @@ void genExit(fir::FirOpBuilder &, mlir::Location, mlir::Value status);
 /// Generate call to ABORT intrinsic runtime routine.
 void genAbort(fir::FirOpBuilder &, mlir::Location);
 
-/// Generate call to BACKTRACE intrinsic runtime routine.
-void genBacktrace(fir::FirOpBuilder &builder, mlir::Location loc);
-
 /// Generate call to crash the program with an error message when detecting
 /// an invalid situation at runtime.
 void genReportFatalUserError(fir::FirOpBuilder &, mlir::Location,
diff --git a/flang/include/flang/Runtime/stop.h b/flang/include/flang/Runtime/stop.h
index d442f72bfe1fa4..f7c4ffe7403e8e 100644
--- a/flang/include/flang/Runtime/stop.h
+++ b/flang/include/flang/Runtime/stop.h
@@ -29,7 +29,6 @@ NORETURN void RTNAME(ProgramEndStatement)(NO_ARGUMENTS);
 // Extensions
 NORETURN void RTNAME(Exit)(int status DEFAULT_VALUE(EXIT_SUCCESS));
 NORETURN void RTNAME(Abort)(NO_ARGUMENTS);
-void RTNAME(Backtrace)(NO_ARGUMENTS);
 
 // Crash with an error message when the program dynamically violates a Fortran
 // constraint.
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 87ce6ed3396676..cdea572c147576 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -1336,7 +1336,6 @@ static const IntrinsicInterface intrinsicSubroutine[]{
             {"stat", AnyInt, Rank::scalar, Optionality::optional,
                 common::Intent::Out}},
         {}, Rank::elemental, IntrinsicClass::atomicSubroutine},
-    {"backtrace", {}, {}, Rank::elemental, IntrinsicClass::pureSubroutine},
     {"co_broadcast",
         {{"a", AnyData, Rank::anyOrAssumedRank, Optionality::required,
              common::Intent::InOut},
diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index acb77694d6ebf6..5dfa53e047f421 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -150,7 +150,6 @@ static constexpr IntrinsicHandler handlers[]{
     {"atan2pi", &I::genAtanpi},
     {"atand", &I::genAtand},
     {"atanpi", &I::genAtanpi},
-    {"backtrace", &I::genBacktrace},
     {"bessel_jn",
      &I::genBesselJn,
      {{{"n1", asValue}, {"n2", asValue}, {"x", asValue}}},
@@ -2683,12 +2682,6 @@ IntrinsicLibrary::genBesselJn(mlir::Type resultType,
   }
 }
 
-// Backtrace
-void IntrinsicLibrary::genBacktrace(llvm::ArrayRef<fir::ExtendedValue> args) {
-  assert(args.size() == 0);
-  fir::runtime::genBacktrace(builder, loc);
-}
-
 // BESSEL_YN
 fir::ExtendedValue
 IntrinsicLibrary::genBesselYn(mlir::Type resultType,
diff --git a/flang/lib/Optimizer/Builder/Runtime/Stop.cpp b/flang/lib/Optimizer/Builder/Runtime/Stop.cpp
index 541e5f3b5d11a8..411181cc6dd1ca 100644
--- a/flang/lib/Optimizer/Builder/Runtime/Stop.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/Stop.cpp
@@ -28,13 +28,6 @@ void fir::runtime::genAbort(fir::FirOpBuilder &builder, mlir::Location loc) {
   builder.create<fir::CallOp>(loc, abortFunc, std::nullopt);
 }
 
-void fir::runtime::genBacktrace(fir::FirOpBuilder &builder,
-                                mlir::Location loc) {
-  mlir::func::FuncOp backtraceFunc =
-      fir::runtime::getRuntimeFunc<mkRTKey(Backtrace)>(loc, builder);
-  builder.create<fir::CallOp>(loc, backtraceFunc, std::nullopt);
-}
-
 void fir::runtime::genReportFatalUserError(fir::FirOpBuilder &builder,
                                            mlir::Location loc,
                                            llvm::StringRef message) {
diff --git a/flang/runtime/stop.cpp b/flang/runtime/stop.cpp
index 17d0ca661d9e84..cfb36b40840200 100644
--- a/flang/runtime/stop.cpp
+++ b/flang/runtime/stop.cpp
@@ -16,11 +16,6 @@
 #include <cstdio>
 #include <cstdlib>
 
-#include "llvm/Config/config.h"
-#ifdef HAVE_BACKTRACE
-#include BACKTRACE_HEADER
-#endif
-
 extern "C" {
 
 static void DescribeIEEESignaledExceptions() {
@@ -157,36 +152,11 @@ void RTNAME(PauseStatementText)(const char *code, std::size_t length) {
   std::exit(status);
 }
 
-static void PrintBacktrace() {
-#ifdef HAVE_BACKTRACE
-  // TODO: Need to parse DWARF information to print function line numbers
-  constexpr int MAX_CALL_STACK{999};
-  void *buffer[MAX_CALL_STACK];
-  int nptrs{backtrace(buffer, MAX_CALL_STACK)};
-
-  if (char **symbols{backtrace_symbols(buffer, nptrs)}) {
-    for (int i = 0; i < nptrs; i++) {
-      Fortran::runtime::Terminator{}.PrintCrashArgs("#%d %s\n", i, symbols[i]);
-    }
-    free(symbols);
-  }
-
-#else
-
-  // TODO: Need to implement the version for other platforms.
-  Fortran::runtime::Terminator{}.PrintCrashArgs(
-      "Handle the case when a backtrace is not available");
-
-#endif
-}
-
 [[noreturn]] void RTNAME(Abort)() {
-  PrintBacktrace();
+  // TODO: Add backtrace call, unless with `-fno-backtrace`.
   std::abort();
 }
 
-void RTNAME(Backtrace)() { PrintBacktrace(); }
-
 [[noreturn]] void RTNAME(ReportFatalUserError)(
     const char *message, const char *source, int line) {
   Fortran::runtime::Terminator{source, line}.Crash(message);
diff --git a/flang/test/Lower/Intrinsics/backtrace.f90 b/flang/test/Lower/Intrinsics/backtrace.f90
deleted file mode 100644
index 9d5e7b4965baff..00000000000000
--- a/flang/test/Lower/Intrinsics/backtrace.f90
+++ /dev/null
@@ -1,10 +0,0 @@
-! RUN: bbc -emit-fir %s -o - | FileCheck %s
-
-! CHECK-LABEL: func.func @_QPbacktrace_test() {
-! CHECK:         %[[VAL_0:.*]] = fir.call @_FortranABacktrace() {{.*}}: () -> none
-! CHECK:         return
-! CHECK:       }
-
-subroutine backtrace_test()
-  call backtrace
-end subroutine

@dty2
Copy link
Contributor

dty2 commented Nov 30, 2024

Sorry for the long wait. I made some changes. Please review them. Then I adopted Jean Perier's suggestion. I made some additional corrections. the new pr is #118179

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:runtime 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