[LLVMbugs] [Bug 15683] New: pointer arithmetic with empty struct compiles into division by zero

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Apr 5 01:14:49 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=15683

            Bug ID: 15683
           Summary: pointer arithmetic with empty struct compiles into
                    division by zero
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jari at kirma.fi
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Unoptimized compilation of following program emits code that includes division
by zero (apparently clang considers struct to be zero-sized, and doesn't handle
the special case?):

#include <stddef.h>

int main(int argc, char **argv)
{
  struct {} x[2];
  volatile ptrdiff_t y = 1+x-x;
  return 0;
}

This issue occurs with -O0, but not with -O1.

Generated assembler below.

        .file   "struct_test.c"
        .text
        .globl  main
        .align  16, 0x90
        .type   main, at function
main:                                   # @main
        .cfi_startproc
# BB#0:
        pushq   %rbp
.Ltmp2:
        .cfi_def_cfa_offset 16
.Ltmp3:
        .cfi_offset %rbp, -16
        movq    %rsp, %rbp
.Ltmp4:
        .cfi_def_cfa_register %rbp
        movl    $0, %eax
        movl    $0, -4(%rbp)
        movl    %edi, -8(%rbp)
        movq    %rsi, -16(%rbp)
        xorl    %esi, %esi
        xorl    %edx, %edx
        movl    %eax, -36(%rbp)         # 4-byte Spill
        movq    %rsi, %rax
        divq    %rsi
        movq    %rax, -32(%rbp)
        movl    -36(%rbp), %eax         # 4-byte Reload
        popq    %rbp
        ret
.Ltmp5:
        .size   main, .Ltmp5-main
        .cfi_endproc


        .section        ".note.GNU-stack","", at progbits

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130405/549ce794/attachment.html>


More information about the llvm-bugs mailing list