lf-lang / lingua-franca

Intuitive concurrent programming in any language
https://www.lf-lang.org
Other
234 stars 62 forks source link

Python target compile error in wait_until (LF_PRINT_DEBUG macro) on aarch64 #2313

Closed elgeeko1 closed 3 months ago

elgeeko1 commented 3 months ago

Context: Monte Carlo pi example xronos-inc/example-monte-carlo-pi

LF version: 7.0 and later

Architecture: aarch64 (Mac M2)

Error:

In file included from example-monte-carlo-pi/src-gen/app/core/../include/core/utils/util.h:40,
                 from example-monte-carlo-pi/src-gen/app/core/../include/core/reactor.h:27,
                 from example-monte-carlo-pi/src-gen/app/core/threaded/reactor_threaded.c:23:
example-monte-carlo-pi/src-gen/app/core/threaded/reactor_threaded.c: In function ‘wait_until’:
example-monte-carlo-pi/src-gen/app/core/threaded/reactor_threaded.c:240:22: error: format ‘%ld’ expects argument of type ‘long int’, but argument 3 has type ‘long long int’ [-Werror=format=]
  240 |       LF_PRINT_DEBUG("Wait time " PRINTF_TIME " is less than MIN_SLEEP_DURATION " PRINTF_TIME ". Skipping wait.",
      |                      ^~~~~~~~~~~~
example-monte-carlo-pi/src-gen/app/logging/api/logging_macros.h:58:22: note: in definition of macro ‘LF_PRINT_DEBUG’
   58 |       lf_print_debug(format, ##__VA_ARGS__);                                                                           \
      |                      ^~~~~~
cc1: all warnings being treated as errors

Steps to recreate: Clone the example repository, and either ./run.sh or lfc src/app.lf using LF v7.0 or later.

This example built and ran correctly with LF v6.

edwardalee commented 3 months ago

Hmm. This line looks correct to me. What platform are you one? I think the only relevant change between v6 and v7 is that warnings are treated as errors. The PRINTF_TIME macro is defined as follows:

#define PRINTF_TIME "%" PRId64

The reason for this macro is that in C, long long has no fixed correct way to format by printf. Some platforms want %ld and some want %lld. Whichever of these you choose, you get warnings on the other platforms. PRId64 is supposed to be defined by the compiler and should be one of ld or lld. I suspect whatever platform/compiler you are using is defining this incorrectly.

elgeeko1 commented 3 months ago

This appears to work on OSX, but not on Ubuntu. I'm using standard gcc, apt install build-essential. I've tried both in my VM as well as native Ubuntu and this now fails (it didn't on LF v0.6)

elgeeko@reanimate-primary:~/xronos-inc/example-monte-carlo-pi$ uname --all
Linux reanimate-primary 5.15.0-112-generic #122-Ubuntu SMP Thu May 23 07:51:32 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux
elgeeko@reanimate-primary:~/xronos-inc/example-monte-carlo-pi$ gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
elgeeko1 commented 3 months ago

Arg... it appears I needed to clean the build outputs. Deleting src-gen, include and bin resolved.

cmnrd commented 3 months ago

So this can be closed?

elgeeko1 commented 3 months ago

Yes. The learning here is that changing the version of LF may break builds that were previously working, until a clean is performed.