soul-lang / SOUL

The SOUL programming language and API
Other
1.71k stars 95 forks source link

C++ code generator: Compiler errors on gcc-arm-none-eabi #34

Closed TheSlowGrowth closed 4 years ago

TheSlowGrowth commented 4 years ago

Applies to:

When building generated code, I get the following errors:

Error 1

template <typename Type, int size> struct Vector;
template <typename Type, int size> struct FixedArray;

Is later implemented as

template <typename Type, int32_t size> struct Vector { /**/ };
template <typename Type, int32_t size> struct FixedArray { /**/ };

which throws an error with this compiler.

Error 2

SOUL/reverb.cpp: In instantiation of 'static void Reverb::copyFromInterleaved(DestFloatType* const*, uint32_t, const SourceFloatType*, uint32_t) [with SourceFloatType = Reverb::Vector<float, 2>; DestFloatType = float; uint32_t = long unsigned int]':
SOUL/reverb.cpp:175:33:   required from 'void Reverb::render(Reverb::RenderContext<FloatType>) [with FloatType = float]'
main.cpp:81:20:   required from here
SOUL/reverb.cpp:582:23: error: invalid static_cast from type 'const Reverb::Vector<float, 2>' to type 'float'
  582 |             dest[i] = static_cast<DestFloatType> (monoSource[i]);

This happens because the compiler picks the copyFromInterleaved for mono sources instead of the vector source one. If I comment out the mono source one, I get this error:

SOUL/reverb.cpp:175:33: error: no matching function for call to 'Reverb::copyFromInterleaved(float**, uint32_t&, Reverb::FixedArray<Reverb::Vector<float, 2>, 1024>::ElementType [1024], long unsigned int&)'
  175 |             copyFromInterleaved (&context.outputChannels[0], startFrame, _getOutputFrameArrayRef_audioOut (state).elements, numFramesToDo);
      |             ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SOUL/reverb.cpp:586:24: note: candidate: 'template<class SourceFloatType, class DestFloatType, int numChannels> static void Reverb::copyFromInterleaved(DestFloatType* const*, uint32_t, const Reverb::Vector<SourceFloatType, numChannels>*, uint32_t)'
  586 |     static inline void copyFromInterleaved (DestFloatType* const* destChannels, uint32_t destStartFrame, const Vector<SourceFloatType, numChannels>* vectorSource, uint32_t numFrames)
      |                        ^~~~~~~~~~~~~~~~~~~
SOUL/reverb.cpp:586:24: note:   template argument deduction/substitution failed:
SOUL/reverb.cpp:175:33: note:   mismatched types 'int' and 'long int'
  175 |             copyFromInterleaved (&context.outputChannels[0], startFrame, _getOutputFrameArrayRef_audioOut (state).elements, numFramesToDo);
      |             ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It is fixed by changing the copyFromInterleaved() template arguments to

template <typename SourceFloatType, typename DestFloatType, int32_t numChannels>

Warning

warning: 'void* memset(void*, int, size_t)' clearing an object of non-trivial type 'struct Reverb::_State'; use assignment or value-initialization instead [-Wclass-memaccess]
  115 |         memset (&state, 0, sizeof (state));

(in init()) Solution:

memset ((void*) &state, 0, sizeof (state));
julianstorer commented 4 years ago

Thanks! I guess we need to make sure our CI runs GCC on these files as well as Clang.. We'll get these niggles sorted out!