This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PROCESSOR-SDK-J721S2: [TIARMCLANG]

Part Number: PROCESSOR-SDK-J721S2

Hi,

I want to use atomic_flags on MCU2_0, but immediately, if I call the "atomic_flag_test_and_set_explicit" function,

the whole processor seems to crash.

#include <stdatomics.h>

atomic_flag flag;

atomic_flag_test_and_set_explicit(&flag, memory_order_acquire);

and if I want to do:

atomic_flag flag = ATOMIC_FLAG_INIT;

the compiler starts to complain

error: non-constant-expression cannot be narrowed from type 'int' to 'atomic_bool' (aka '_Atomic(bool)') in initializer list [-Wc++11-narrowing]
flag = ATOMIC_FLAG_INIT;

Does anyone faced this issue, too?

Thanks

Martin

  • if I want to do:

    atomic_flag flag = ATOMIC_FLAG_INIT;

    the compiler starts to complain

    error: non-constant-expression cannot be narrowed from type 'int' to 'atomic_bool' (aka '_Atomic(bool)') in initializer list [-Wc++11-narrowing]
    flag = ATOMIC_FLAG_INIT;

    I can reproduce this diagnostic by writing this code in a C++ file.

    /* fails.cpp */
    
    #include <stdatomic.h>
    
    atomic_flag flag = ATOMIC_FLAG_INIT;

    Build it ...

    $ tiarmclang -c fails.cpp
    fails.cpp:5:20: error: non-constant-expression cannot be narrowed from type 'int' to 'atomic_bool' (aka '_Atomic(bool)')
          in initializer list [-Wc++11-narrowing]
    atomic_flag flag = ATOMIC_FLAG_INIT;
                       ^~~~~~~~~~~~~~~~
    C:\ti\compilers\ti-cgt-armllvm_3.2.0.LTS\lib\clang\15.0.7\include\stdatomic.h:161:28: note: expanded from macro
          'ATOMIC_FLAG_INIT'
    #define ATOMIC_FLAG_INIT { 0 }
                               ^
    fails.cpp:5:20: note: insert an explicit cast to silence this issue
    atomic_flag flag = ATOMIC_FLAG_INIT;
                       ^~~~~~~~~~~~~~~~
    C:\ti\compilers\ti-cgt-armllvm_3.2.0.LTS\lib\clang\15.0.7\include\stdatomic.h:161:28: note: expanded from macro
          'ATOMIC_FLAG_INIT'
    #define ATOMIC_FLAG_INIT { 0 }
                               ^
    1 error generated.

    Add the option -x c to tell the compiler to process this same code as C, and not C++, then it builds clean.

    $ tiarmclang -c -x c fails.cpp
    

    Here is the C++ way to write it ...

    /* works.cpp */
    
    #include <atomic>
    
    std::atomic_flag flag = ATOMIC_FLAG_INIT;

    Regarding ...

    I want to use atomic_flags on MCU2_0, but immediately, if I call the "atomic_flag_test_and_set_explicit" function,

    the whole processor seems to crash.

    I have to get with other experts.  I'll get back to you.

    Thanks and regards,

    -George

  • Hi Goerge,

    I also tried the c++ version, because I'm in this context: but then i get the following issues:

    /home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include/c++/v1/atomic:591:3: error: <atomic> is not supported on this single threaded system
    # error <atomic> is not supported on this single threaded system
    ^
    /home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include/c++/v1/atomic:594:3: error: <atomic> is not implemented
    # error <atomic> is not implemented
    ^
    /home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include/c++/v1/atomic:1535:13: error: use of undeclared identifier '__libcpp_thread_yield'
    __libcpp_thread_yield();
    ^
    /home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include/c++/v1/atomic:2496:23: error: use of undeclared identifier '_LIBCPP_ATOMIC_FLAG_TYPE'
    __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_;
    ^
    /home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include/c++/v1/atomic:2500:17: error: use of undeclared identifier '_LIBCPP_ATOMIC_FLAG_TYPE'
    {return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m);}
    ^
    /home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include/c++/v1/atomic:2503:17: error: use of undeclared identifier '_LIBCPP_ATOMIC_FLAG_TYPE'
    {return _LIBCPP_ATOMIC_FLAG_TYPE(true) == __cxx_atomic_load(&__a_, __m);}
    ^
    /home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include/c++/v1/atomic:2507:46: error: use of undeclared identifier '_LIBCPP_ATOMIC_FLAG_TYPE'
    {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);}
    ^
    /home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include/c++/v1/atomic:2510:46: error: use of undeclared identifier '_LIBCPP_ATOMIC_FLAG_TYPE'
    {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);}
    ^
    /home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include/c++/v1/atomic:2513:36: error: use of undeclared identifier '_LIBCPP_ATOMIC_FLAG_TYPE'
    {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);}
    ^
    /home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include/c++/v1/atomic:2516:36: error: use of undeclared identifier '_LIBCPP_ATOMIC_FLAG_TYPE'
    {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);}
    ^
    /home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include/c++/v1/atomic:2520:35: error: use of undeclared identifier '_LIBCPP_ATOMIC_FLAG_TYPE'
    {__cxx_atomic_wait(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m);}
    ^
    /home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include/c++/v1/atomic:2523:35: error: use of undeclared identifier '_LIBCPP_ATOMIC_FLAG_TYPE'
    {__cxx_atomic_wait(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(__v), __m);}

    Btw. this is my compiler call:

    ti-cgt-armllvm_1.3.0.LTS/bin/tiarmclang  -DBUILD_MCU -DBUILD_MCU2_0 -DSOC_J721S2 -D_GNU_SOURCE -I/home/ubuntu/prjtools/tisdk/ti-cgt-armllvm_1.3.0.LTS/include -I/home/ubuntu/prjtools/tisdk/psdkqa/pdk/packages  -mfloat-abi=hard -mfpu=vfpv3-d16 -mcpu=cortex-r5 -march=armv7-r -fno-strict-aliasing -frtti -Oz   -std=gnu++11 -o foo.cpp.obj -c /foo.cpp

    Thanks &Regards,

    Martin

  • You use an older version of the compiler.  Is it practical for you to upgrade to the latest version 3.2.0.LTS?  That supports <atomic> .

    Thanks and regards,

    -George

  • Oh okay, I did not expect, that we have such an old version. Do you think it's feasible for this psdk version:

    "ti-psdk-rtos-j721s2-08_05_00_11"

    Regards,

    Martin

  • You should use the compiler versions tested and documented to work with your SDK.  If that doesn't include version 3.2.0.LTS, then you can't use <atomic>.

    Thanks and regards,

    -George