[LLVMbugs] [Bug 18028] New: clang puzzled with bitfields and/or bitwise &

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Nov 22 00:48:09 PST 2013


            Bug ID: 18028
           Summary: clang puzzled with bitfields and/or bitwise &
           Product: clang
           Version: 3.3
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: devel at fresse.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Following program:

#include <stdio.h>
#include <stdint.h>
#include <string.h>

typedef union {
    uint64_t u:56;
    struct {
        uint32_t u24:24;
    } __attribute__((packed));
    struct {
        uint64_t s:8;
        uint64_t m:8;
        uint64_t h:8;
    } __attribute__((packed));
} __attribute__((packed)) dt_hms_t;

struct dt_t_s {
    struct {
    } __attribute__((packed));
    union {
        uint64_t u:56;
        dt_hms_t hms;
    } __attribute__((packed));

struct dt_dt_s {
    union {
        /* sandwich types */
        struct {
            uint64_t ign;
            struct dt_t_s t;

    struct dt_dt_s test;
    struct dt_t_s beef;

    beef.hms.h = 23;
    beef.hms.m = 59;
    beef.hms.s = 0;

    test.t = beef;

    unsigned int first_access = (test.t.hms.u24 & 0xfffffffU);
    unsigned int second_access = (test.t.hms.u24 & 0xfffffffU);
    printf("%x  %x\n", first_access, second_access);
    return first_access != second_access;

The snippet (ab)uses implementation defined behaviour (accessing a union
element without writing to it first).  However, the implementation defined
behaviour changes over time.  Output:

$ ./a.out
60173b00  173b00

return code is 1

clang version 3.2 (tags/RELEASE_32/final) on the other hand handles this
snippet just fine.

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/20131122/b36c41a6/attachment.html>

More information about the llvm-bugs mailing list