Skip to content
cyrusknopfPublic

About

gcc plugin to enforce allocation-free paths at compile time

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

35 Commits

Folders and files

Repository files navigation

heapless

Compile-time restriction on dynamic memory allocations.

See supported cases in test/.

example usage

❯ cat test.c
#include <stdlib.h>
#include <stddef.h>

void* allocating(size_t sz)
{
  return malloc(sz);
}

[[heapless::noalloc]] void nonallocating(size_t sz)
{
  allocating(sz + 1);
}
❯ gcc -fplugin=./heapless.so -c test.c
test.c: In function ‘nonallocating’:
test.c:6:10: error: malloc() used in noalloc function
    6 |   return malloc(sz);
      |          ^~~~~~~~~~
test.c:11:3: note: allocation occurs in function called here
   11 |   allocating(sz + 1);
      |   ^~~~~~~~~~~~~~~~~~

building

make produces top-level heapless.so

make test runs expect-tests in test/

Resources and references

About

gcc plugin to enforce allocation-free paths at compile time

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages