Skip to content

Fix GCC 15.2.1 compilation error: reposition function attributes#81

Merged
emeryberger merged 5 commits intomasterfrom
copilot/fix-libhoard-compile-error
Dec 30, 2025
Merged

Fix GCC 15.2.1 compilation error: reposition function attributes#81
emeryberger merged 5 commits intomasterfrom
copilot/fix-libhoard-compile-error

Conversation

Copy link
Contributor

Copilot AI commented Dec 30, 2025

GCC 15.2.1 rejects attributes placed between function signature elements when defining (not declaring) a function. The code had:

void * __attribute__((flatten)) xxmalloc (size_t sz) __attribute__((alloc_size(1))) __attribute__((malloc))

This triggers:

error: attributes are not allowed on a function-definition

Changes

  • src/source/libhoard.cpp: Moved all attributes before return type
    __attribute__((flatten)) __attribute__((alloc_size(1))) __attribute__((malloc))
    void * xxmalloc (size_t sz)
  • .gitignore: Added build/ and CodeQL artifacts to prevent committing build output

The new syntax is compatible with GCC 15.2.1 while maintaining compatibility with older GCC versions and Clang.

Original prompt

This section details on the original issue you should resolve

<issue_title>Compile failure in libhoard.cpp with gcc 15.2.1</issue_title>
<issue_description>

/usr/src/Hoard/src/source/libhoard.cpp:100:56: error: attributes are not allowed on a function-definition
  100 |   void * __attribute__((flatten)) xxmalloc (size_t sz) __attribute__((alloc_size(1))) __attribute__((malloc))
      |                                                        ^~~~~~~~~~~~~
make[2]: *** [CMakeFiles/hoard.dir/build.make:93: CMakeFiles/hoard.dir/src/source/libhoard.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:87: CMakeFiles/hoard.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Also a few redefinition warnings but they're not fatal...

In file included from /usr/src/Hoard/build/_deps/heap-layers-src/locks/all.h:4,
                 from /usr/src/Hoard/build/_deps/heap-layers-src/heaplayers.h:112,
                 from /usr/src/Hoard/src/include/hoard/hoardheap.h:21,
                 from /usr/src/Hoard/src/include/hoard/hoardtlab.h:27,
                 from /usr/src/Hoard/src/source/unixtls.cpp:60:
/usr/src/Hoard/build/_deps/heap-layers-src/locks/spinlock.h:49:9: warning: ‘NO_INLINE’ redefined
   49 | #define NO_INLINE
      |         ^~~~~~~~~
/usr/src/Hoard/build/_deps/heap-layers-src/heaplayers.h:66:9: note: this is the location of the previous definition
   66 | #define NO_INLINE       __attribute__ ((noinline))
      |         ^~~~~~~~~
[ 66%] Building CXX object CMakeFiles/hoard.dir/src/source/libhoard.cpp.o
In file included from /usr/src/Hoard/build/_deps/heap-layers-src/locks/all.h:4,
                 from /usr/src/Hoard/build/_deps/heap-layers-src/heaplayers.h:112,
                 from /usr/src/Hoard/src/source/libhoard.cpp:32:
/usr/src/Hoard/build/_deps/heap-layers-src/locks/spinlock.h:49:9: warning: ‘NO_INLINE’ redefined
   49 | #define NO_INLINE
      |         ^~~~~~~~~
/usr/src/Hoard/build/_deps/heap-layers-src/heaplayers.h:66:9: note: this is the location of the previous definition
   66 | #define NO_INLINE       __attribute__ ((noinline))

</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits December 30, 2025 04:26
Co-authored-by: emeryberger <1612723+emeryberger@users.noreply.github.com>
Co-authored-by: emeryberger <1612723+emeryberger@users.noreply.github.com>
Co-authored-by: emeryberger <1612723+emeryberger@users.noreply.github.com>
Co-authored-by: emeryberger <1612723+emeryberger@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix compile failure in libhoard.cpp with gcc 15.2.1 Fix GCC 15.2.1 compilation error: reposition function attributes Dec 30, 2025
Copilot AI requested a review from emeryberger December 30, 2025 04:30
@emeryberger
Copy link
Owner

@copilot I want you to verify this builds under GCC 15.2.1.

Copy link
Contributor Author

Copilot AI commented Dec 30, 2025

@copilot I want you to verify this builds under GCC 15.2.1.

Verified successful build with GCC 15.2.0 using the official GCC Docker container.

Test Results:

  • ✅ Old syntax: Produces error "attributes are not allowed on a function-definition"
  • ✅ New syntax: Compiles successfully with no errors
  • ✅ Full Hoard library: Builds successfully (libhoard.so created)

The only warnings are the non-fatal NO_INLINE redefinition warnings from the Heap-Layers dependency mentioned in the original issue.

Build completed with commit e469973.

@emeryberger emeryberger marked this pull request as ready for review December 30, 2025 04:47
@emeryberger emeryberger merged commit 37cd13b into master Dec 30, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compile failure in libhoard.cpp with gcc 15.2.1

2 participants