https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85985
Bug ID: 85985 Summary: GCC >= 5.6 unaligned movaps Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: valentinp at mellanox dot com Target Milestone: --- Test case: #include <stdio.h> #include <stdlib.h> #include <stdint.h> struct aaa { void *a1; void *a2; struct { void* a3 #if defined(USE_ALIGN) && USE_ALIGN > 0 __attribute__((aligned(64))) #endif ; }; }; struct bbb { volatile int b; struct aaa A; }; static void print_A(struct aaa *A) { printf("a1: %p, %%8=%lu %%16=%lu %%32=%lu\na2: %p, %%8=%lu %%16=%lu %%32=%lu\n", &A->a1, ((uint64_t)(&A->a1)) % 8, ((uint64_t)(&A->a1)) % 16, ((uint64_t)(&A->a1)) % 32, &A->a2, ((uint64_t)(&A->a2)) % 8, ((uint64_t)(&A->a2)) % 16, ((uint64_t)(&A->a2)) % 32); } static void __attribute__ ((noinline)) B_init(struct bbb *B) { B->A.a2 = NULL; B->A.a1 = NULL; } int main(int argc, char *argv[]) { struct bbb *B; void *storage = malloc(sizeof(struct bbb)*32); B = (struct bbb*)((char*)storage + 8); print_A(&B->A); B_init(B); free(storage); return 0; } ASM: .file "compiler2.c" .text .p2align 4,,15 .type B_init, @function B_init: .LFB42: .cfi_startproc pxor %xmm0, %xmm0 movaps %xmm0, 64(%rdi) ret .cfi_endproc .LFE42: .size B_init, .-B_init .section .rodata.str1.8,"aMS",@progbits,1 .align 8 .LC0: .string "a1: %p, %%8=%lu %%16=%lu %%32=%lu\na2: %p, %%8=%lu %%16=%lu %%32=%lu\n" .section .text.startup,"ax",@progbits .p2align 4,,15 .globl main .type main, @function main: .LFB43: .cfi_startproc pushq %rbx .cfi_def_cfa_offset 16 .cfi_offset 3, -16 movl $6144, %edi call malloc@PLT leaq 74(%rax), %rdx movq %rax, %rbx leaq 82(%rax), %rax leaq .LC0(%rip), %rsi movl $1, %edi movq %rax, %rcx movq %rdx, %r9 movq %rdx, %r8 andl $31, %ecx andl $31, %r9d andl $15, %r8d pushq %rcx .cfi_def_cfa_offset 24 movq %rax, %rcx andl $15, %ecx pushq %rcx .cfi_def_cfa_offset 32 pushq $2 .cfi_def_cfa_offset 40 movl $2, %ecx pushq %rax .cfi_def_cfa_offset 48 xorl %eax, %eax call __printf_chk@PLT leaq 10(%rbx), %rdi addq $32, %rsp .cfi_def_cfa_offset 16 call B_init movq %rbx, %rdi call free@PLT xorl %eax, %eax popq %rbx .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE43: .size main, .-main .ident "GCC: (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0" .section .note.GNU-stack,"",@progbits gcc --version gcc (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. compile: gcc -v --save-temps -O3 -o ccc -DUSE_ALIGN=1 -Wall -Wextra compiler2.c Description: test always works with GCC 4.6 test works with GCC >= 5.6 and -DUSE_ALIGN=0 test segv on unaligned movaps with GCC >= 5.6 (latest tested GCC 7.2) and -DUSE_ALIGN=1 This may be a duplicate of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84525 but the test case here is different. Am I violating the spec with this test?