[llvm-bugs] [Bug 40196] New: printf bug when arguments from a member of union

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 1 08:59:31 PST 2019


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

            Bug ID: 40196
           Summary: printf bug when arguments from a member of union
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: metora at x-legend.com.tw
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Hi

We found a bug in printf.
It may have included below
1. 64bit union
2. a bit number in union
3. out of register count (x64-ABI limit)

#include <stdio.h>

union U {
    unsigned long long Value;
    struct {
        unsigned long long Data:2;
    };
};

int main ()
{
    int a = 0;
    U b = { 0 };

    printf ("%d, %llu\n", a, b.Data);
    printf ("%d, %d, %llu\n", a, a, b.Data);
    printf ("%d, %d, %d, %llu\n", a, a, a, b.Data);
    printf ("%d, %d, %d, %d, %llu\n", a, a, a, a, b.Data);
    printf ("%d, %d, %d, %d, %d, %llu\n", a, a, a, a, a, b.Data);
    printf ("%d, %d, %d, %d, %d, %d, %llu\n", a, a, a, a, a, a, b.Data);
    printf ("%d, %d, %d, %d, %d, %d, %d, %llu\n", a, a, a, a, a, a, a, b.Data);
    printf ("%d, %d, %d, %d, %d, %d, %d, %d, %llu\n", a, a, a, a, a, a, a, a,
b.Data);
    printf ("%d, %d, %d, %d, %d, %d, %d, %d, %d, %llu\n", a, a, a, a, a, a, a,
a, a, b.Data);

    return 0;
}

metora at pro-debian:$ clang-6.0 1.cc
metora at pro-debian:$ ./a.out 
0, 0
0, 0, 0
0, 0, 0, 0
0, 0, 0, 0, 0
0, 0, 0, 0, 0, 140724603453440
0, 0, 0, 0, 0, 0, 140724603453440
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0, 0, 0

How to fix or prevent it?

Thank you

-- 
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/20190101/65269591/attachment-0001.html>


More information about the llvm-bugs mailing list