Compilation failure with Clang-21 due to macro conflicts
alsa-project/alsa-lib issue #436 was opened from ms178:
**Description:**
Attempting to compile alsa-lib (both the `git` version and version 1.2.13) with Clang-21 (commit `bfa7edcc6652bdb37d53e0cec64926aab3f280eb`) results in multiple compilation errors. These errors stem from conflicts between macros defined in `midifile.h` and member names within structures defined in `include/alsa/ump_msg.h`.
**Environment:**
* **alsa-lib version:** `git` (and 1.2.13) * **Compiler:** Clang-21 (`bfa7edcc6652bdb37d53e0cec64926aab3f280eb`) * **Operating System:** CachyOS * **Build System:** Autotools
**Steps to Reproduce:**
1. Obtain the PKGBUILD and the other files from https://github.com/ms178/archpkgbuilds/blob/main/packages/alsa-lib-main/PKGB... 2. Uncomment the patch that I apply to workaround the issue. 3. Configure the build to use Clang-21 (`bfa7edcc6652bdb37d53e0cec64926aab3f280eb`). 4. Attempt to compile the library.
**Expected Behavior:**
The compilation should complete successfully without errors.
**Actual Behavior:**
The compilation fails with multiple errors similar to the following:
``` In file included from playmidi1.c:51: In file included from ./../include/asoundlib.h:63: In file included from ../include/alsa/seq_event.h:31: ../include/alsa/ump_msg.h:170:27: error: expected member name or ';' after declaration specifiers 170 | snd_ump_msg_midi1_note_t note_on; /**< MIDI1 note-on message */ | ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ./midifile.h:55:27: note: expanded from macro 'note_on' 55 | #define note_on 0x90 | ^ In file included from playmidi1.c:51: In file included from ./../include/asoundlib.h:63: In file included from ../include/alsa/seq_event.h:31: ../include/alsa/ump_msg.h:170:26: error: expected ';' at end of declaration list 170 | snd_ump_msg_midi1_note_t note_on; /**< MIDI1 note-on message */ | ^ | ; ../include/alsa/ump_msg.h:171:27: error: expected member name or ';' after declaration specifiers 171 | snd_ump_msg_midi1_note_t note_off; /**< MIDI1 note-off message */ | ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ./midifile.h:54:27: note: expanded from macro 'note_off' 54 | #define note_off 0x80 | ^ In file included from playmidi1.c:51: In file included from ./../include/asoundlib.h:63: In file included from ../include/alsa/seq_event.h:31: ../include/alsa/ump_msg.h:171:26: error: expected ';' at end of declaration list 171 | snd_ump_msg_midi1_note_t note_off; /**< MIDI1 note-off message */ | ^ | ; ../include/alsa/ump_msg.h:173:26: error: expected member name or ';' after declaration specifiers 173 | snd_ump_msg_midi1_cc CCLD rawmidi _t control_change; /**< MIDI1 control-change message */ | ~~~~~~~~~~~~~~~~~~~~~~ ^ ./midifile.h:57:28: note: expanded from macro 'control_change' 57 | #define control_change 0xb0 | ^ In file included from playmidi1.c:51: In file included from ./../include/asoundlib.h:63: In file included from ../include/alsa/seq_event.h CCLD oldapi :31: ../include/alsa/ump_msg.h:173:24: error: expected ';' at end of declaration list 173 | snd_ump_msg_midi1_cc_t control_change; /**< MIDI1 control-change message */ | ^ | ; ../include/alsa/ump_msg.h:432:27: error: expected member name or ';' after declaration specifiers 432 | snd_ump_msg_midi2_note_t note_on; /**< MIDI2 note-on message */ | ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ./midifile.h:55:27: note: expanded from macro 'note_on' 55 | #define note_on 0x90 | ^ CCLD pcm_min In file included from playmidi1.c:51: In file included from ./../include/asoundlib.h:63: In file included from ../include/alsa/seq_event.h:31: ../include/alsa/ump_msg.h:432:26: error: expected ';' at end of declaration list 432 | snd_ump_msg_midi2_note_t note_on; /**< MIDI2 note-on message */ | ^ | ; ../include/alsa/ump_msg.h:433:27: error: expected member name or ';' after declaration specifiers 433 | snd_ump_msg_midi2_note_t note_off; /**< MIDI2 note-off message */ | ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ./midifile.h:54:27: note: expanded from macro 'note_off' 54 | #define note_off 0x80 | ^ In file included from playmidi1.c:51: In file included from ./../include/asoundlib.h:63: In file included from ../include/alsa/seq_event.h:31: ../include/alsa/ump_msg.h:433:26: error: expected ';' at end of declaration list 433 | snd_ump_msg_midi2_note_t note_off; /**< MIDI2 note-off message */ | ^ | ; ../include/alsa/ump_msg.h:438:26: error: expected member name or ';' after declaration specifiers 438 | snd_ump_msg_midi2_cc_t control_change; /**< MIDI2 control-change message */ | ~~~~~~~~~~~~~~~~~~~~~~ ^ ./midifile.h:57:28: note: expanded from macro 'control_change' 57 | #define control_change 0xb0 | ^ In file included from playmidi1.c:51: In file included from ./../include/asoundlib.h:63: In file included from ../include/alsa/seq_event.h:31: ../include/alsa/ump_msg.h:438:24: error: expected ';' at end of declaration list 438 | snd_ump_msg_midi2_cc_t control_change; /**< MIDI2 control-change message */ | ^ | ; ../include/alsa/ump_msg.h:711:27: error: expected member name or ';' after declaration specifiers 711 | snd_ump_msg_set_tempo_t set_tempo; /**< Set Tempo */ | ~~~~~~~~~~~~~~~~~~~~~~~ ^ ./midifile.c:57:20: note: expanded from macro 'set_tempo' 57 | #define set_tempo 0x51 | ^ In file included from playmidi1.c:51: In file included from ./../include/asoundlib.h:63: In file included from ../include/alsa/seq_event.h:31: ../include/alsa/ump_msg.h:711:25: error: expected ';' at end of declaration list 711 | snd_ump_msg_set_tempo_t set_tempo; /**< Set Tempo */ | ^ | ; CCLD control CCLD chmap 14 errors generated. ```
**Root Cause analysis by AI:**
The macros `note_on`, `note_off`, `control_change`, and `set_tempo` defined in `midifile.h` are conflicting with member names used in structures within `include/alsa/ump_msg.h`. This leads to incorrect code expansion and subsequent compilation errors.
**Workaround:**
The following patch applied to `include/asoundlib-head.h` allows the compilation to succeed:
```diff --- a/include/asoundlib-head.h +++ b/include/asoundlib-head.h @@ -28,6 +28,11 @@ #ifndef __ASOUNDLIB_H #define __ASOUNDLIB_H
+#undef note_on +#undef note_off +#undef control_change +#undef set_tempo + #include <unistd.h> #include <stdio.h> #include <stdlib.h> ```
**Suggested Solutions by AI:**
While the provided workaround resolves the immediate compilation issue, a more robust solution might involve:
1. **Renaming conflicting members:** Consider renaming the members in `ump_msg.h` (e.g., `midi1_note_on`, `midi2_note_off`, etc.) to avoid clashes with commonly used MIDI event names. 2. **Namespace/prefix:** If renaming is not feasible, consider using a namespace or prefix for the `ump_msg.h` members to prevent conflicts. 3. **Conditional undef:** Instead of unconditionally undefining the macros in `asoundlib-head.h`, a more targeted approach could be to undefine them only within the scope of `ump_msg.h`'s inclusion. 4. **Review macro definitions:** Investigate if the macros in `midifile.h` are strictly necessary or if they can be replaced with constants or enums within a namespace.
**Additional Notes:**
* I am not a programmer and cannot provide a definitive fix. The provided workaround is based on AI feedback.
Issue URL : https://github.com/alsa-project/alsa-lib/issues/436 Repository URL: https://github.com/alsa-project/alsa-lib
participants (1)
-
GitHub issues - opened