[flang-commits] [flang] flang: fix backtrace build on FreeBSD (PR #120297)

Brooks Davis via flang-commits flang-commits at lists.llvm.org
Tue Dec 17 12:44:56 PST 2024


https://github.com/brooksdavis created https://github.com/llvm/llvm-project/pull/120297

FreeBSD's libexecinfo defines backtrace with a size_t for the size argument and return type.  This almost certainly doesn't make sense, but what's done is done so cast the output to allow compilation. Otherwise we get:

.../flang/runtime/stop.cpp:165:13: error: non-constant-expression cannot be narrowed from type 'size_t' (aka 'unsigned long') to 'int' in initializer list [-Wc++11-narrowing]
  165 |   int nptrs{backtrace(buffer, MAX_CALL_STACK)};
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

>From c5106426425343c9dfcc9a018a47deef55ffb96e Mon Sep 17 00:00:00 2001
From: Brooks Davis <brooks at one-eyed-alien.net>
Date: Tue, 17 Dec 2024 20:35:58 +0000
Subject: [PATCH] flang: fix backtrace build on FreeBSD

FreeBSD's libexecinfo defines backtrace with a size_t for the size
argument and return type.  This almost certainly doesn't make sense,
but what's done is done so cast the output to allow compilation.
Otherwise we get:

.../flang/runtime/stop.cpp:165:13: error: non-constant-expression cannot be narrowed from type 'size_t' (aka 'unsigned long') to 'int' in
initializer list [-Wc++11-narrowing]
  165 |   int nptrs{backtrace(buffer, MAX_CALL_STACK)};
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
 flang/runtime/stop.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/runtime/stop.cpp b/flang/runtime/stop.cpp
index f8457e10566a23..a7be8a082e026b 100644
--- a/flang/runtime/stop.cpp
+++ b/flang/runtime/stop.cpp
@@ -162,7 +162,7 @@ static void PrintBacktrace() {
   // 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)};
+  int nptrs{(int)backtrace(buffer, MAX_CALL_STACK)};
 
   if (char **symbols{backtrace_symbols(buffer, nptrs)}) {
     for (int i = 0; i < nptrs; i++) {



More information about the flang-commits mailing list