0

GCC codegen doesn't seem to align stack variables with the specified alignment value, when the address sanitizer is used.

The following code causes an assertion failure on g++ (GCC) 13.1.1 20230429, arch x86_64 GNU/Linux, when the flag -fsanitize=address is used. When the flag isn't specified, the assertion doesn't fail.

#include <cassert>
#include <cstdint>

int main() {
    alignas(64) char c;
    auto addr = reinterpret_cast<uintptr_t>(&c);
    assert(addr % 64 == 0);
}

Using clang 15.0.7 on the same arch with the same flag does not cause this bug.

Is this a GCC bug?

  • Works here: https://gcc.godbolt.org/z/4oxTebj8h – Aykhan Hagverdili May 11 '23 at 20:10
  • godbolt is using v13.1, I'm using v13.1.1 – clang-enjoyer May 11 '23 at 20:14
  • It may be that `64` exceeds the maximum supported alignment of the compiler or platform. I ran into something like that as an issue when the PMMU required the table to be aligned on a 4096-byte address boundary, but the alignment specification was beyond the capability of the compiler to provide (I ended up doing it "the hard way", by hand). However, I hope this is a GCC bug that can be fixed. (Not that I "hope for bugs", especially in a compiler.) – Eljay May 11 '23 at 20:20
  • @clang-enjoyer Here's trunk 14.0.0 https://gcc.godbolt.org/z/M4dPeq8b3 – Aykhan Hagverdili May 11 '23 at 20:34
  • Are you using any other options besides `-fsanitize=address`? Are you able to reproduce the problem with other gcc versions? – Nate Eldredge Jun 16 '23 at 19:02
  • @NateEldredge Only the one flag. With GCC 12 codegen seems ok. – clang-enjoyer Aug 10 '23 at 16:36

0 Answers0