align attribute should works as expected
kubo39 opened this issue · 4 comments
kubo39 commented
D's align attribute did not works as exptected, see this commit.
kubo39 commented
This does not work too.
import ldc.attributes;
import ldc.llvmasm;
@llvmAttr("alignstack", "8") @naked void foo()
{
__asm("nop", "");
}
output asm is below:
.text
.attribute 4, 16
.attribute 5, "rv32i2p0"
.file "app.d"
.section .text._D3app3fooFZv,"ax",@progbits
.globl _D3app3fooFZv
.p2align 2
.type _D3app3fooFZv,@function
_D3app3fooFZv:
.cfi_startproc
#APP
nop
#NO_APP
.Lfunc_end0:
.size _D3app3fooFZv, .Lfunc_end0-_D3app3fooFZv
.cfi_endproc
.ident "ldc version 1.36.0-git-89267b1-dirty"
.section ".note.GNU-stack","",@progbits
kubo39 commented
kubo39 commented
以下の関数でfoo.alignof
は16ではなく1を返す。これはfooの無引数関数呼び出し(CallExp)に対するalignofとしてコンパイラが解釈するためである。
これを関数に対するalignofとして実装すると非互換な変更になってしまう。
import ldc.attributes;
import ldc.llvmasm;
pragma(mangle, "foo")
align(16) @naked void foo()
{
version(LDC) {
__asm("nop", "");
}
}
pragma(msg, foo.alignof); // 1LU
kubo39 commented
GCCの __alignof__
:
https://gcc.gnu.org/onlinedocs/gcc/Alignment.html
If the operand of the alignof expression is a function, the expression evaluates to the alignment of the function which may be specified by attribute aligned
なので、D言語はちょっと挙動が違ってる。