bombomby / optick

C++ Profiler For Games
https://optick.dev
MIT License
2.95k stars 296 forks source link

Fix for clang and gcc optimization build crash #79

Closed topin89 closed 5 years ago

topin89 commented 5 years ago

Detailed version is in this issue: https://github.com/bombomby/optick/issues/77

In short, at least clang 8 and 8.3 optimize code in such a way than it should be aligned more than default malloc \ new alignment (that is alignof(max_align_t), typically 8).

Since the code targets C++11, we can either use platform_specific functions like posix_memalign and _aligned_malloc, or we can overallocate and use standard std::align to get address with desired alignment.

I choose latter for cross-platform and because I don't know how it works for consoles, so we now allocate size(T) + alignof(T) + sizeof(Header), and Header now also stores original pointer from malloc.

topin89 commented 5 years ago

Since fixed here: https://github.com/bombomby/optick/commit/c81a0235d03125982d10a779830403d730954333 I suppose this can be closed unless Alloc should be used for any arbitrary objects with arbitrary alignments.