[llvm-bugs] [Bug 44508] New: Wrong optimization of comparison of addresses of empty structs

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 10 02:38:54 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=44508

            Bug ID: 44508
           Summary: Wrong optimization of comparison of addresses of empty
                    structs
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: ch3root at openwall.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

Wrong optimization of comparison of addresses of empty structs:

----------------------------------------------------------------------
#include <stdio.h>

int main()
{
    struct {} x, y;

    void *p = &x;
    void *q = &y;
    printf("eq1: %d\n", p == q);

    unsigned long u = (unsigned long)p;
    unsigned long v = (unsigned long)q;
    printf("diff: %lu\n", u - v);
    printf("eq2: %d\n", u == v);
}
----------------------------------------------------------------------
$ clang -std=c11 -Wall -O3 test.c && ./a.out
eq1: 0
diff: 0
eq2: 0
----------------------------------------------------------------------
clang x86-64 version: clang version 10.0.0
(https://github.com/llvm/llvm-project.git
8647a72c4a52e0386c0397ce3fbd38121c18b873)
----------------------------------------------------------------------

Empty structs is a gcc extension (they are UB according to C11, 6.7.2.1p8) but,
nevertheless, I think zero `diff` should imply non-zero eq2 and eq1.

-- 
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/20200110/de636c69/attachment.html>


More information about the llvm-bugs mailing list