Skip to content

flang: fix backtrace build on FreeBSD #120297

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 2, 2025

Conversation

brooksdavis
Copy link
Contributor

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)};
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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)};
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Dec 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 17, 2024

@llvm/pr-subscribers-flang-runtime

Author: Brooks Davis (brooksdavis)

Changes

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)};
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

1 Files Affected:

  • (modified) flang/runtime/stop.cpp (+1-1)
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++) {

@brooksdavis
Copy link
Contributor Author

This fixes e8baa79

@devnexen devnexen requested a review from brad0 December 22, 2024 08:53
@brad0 brad0 merged commit 7326e90 into llvm:main Jan 2, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants