llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.06k stars 11.59k forks source link

clang++: alias template ignores alignment given by `__attribute__((aligned(X)))` #59788

Open richardebeling opened 1 year ago

richardebeling commented 1 year ago

This code:

#include <iostream>
#include <cstdint>

template <typename T=void>
using TemplatedT __attribute__((aligned(8))) = uint32_t;

using ManualT __attribute__((aligned(8))) = uint32_t;

int main() {
    std::cout << "alignof Template: " << alignof(TemplatedT<>) << std::endl;
    std::cout << "alignof Manual:   " << alignof(ManualT) << std::endl;
}

prints (godbolt)

alignof Template: 4
alignof Manual:   8

when compiled with clang (in the version currently available as "trunk" on godbolt).

I would have expected both types to have an alignment of 8. I've asked on StackOverflow, and the comments indicated this may be a bug, so I'm reporting this here.

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-codegen

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend