[llvm-bugs] [Bug 47727] New: False positive, 32-bit access from a 64-bit initialized value

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Oct 5 02:47:52 PDT 2020


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

            Bug ID: 47727
           Summary: False positive, 32-bit access from a 64-bit
                    initialized value
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: other
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: eblot.ml at gmail.com
                CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org

Using LLVM/clang 11.0.0-rc3 static analyzer.

The following snippets should, I believe, run ok with the static analyzer.

void foo1(uint32_t * out) {
    uint64_t tmp64;
    tmp64 = 0;

    uint32_t * tmp32 = (uint32_t *)&tmp64;
    *out = tmp32[1];
}

void foo2(uint32_t * out) {
    uint64_t tmp64[1];
    tmp64[0] = 0;

    uint32_t * tmp32 = (uint32_t *)tmp64;
    *out = tmp32[1];
}

void foo3(uint32_t * out) {
    uint64_t tmp64[1];
    memset(tmp64, 0, sizeof(tmp64));

    uint32_t * tmp32 = (uint32_t *)tmp64;
    *out = tmp32[1];
}

However, `foo2` is signalled with 

warning: Assigned value is garbage or undefined
    *out = tmp32[1];
         ^ ~~~~~~~~
1 warning generated.

On 32-bit target, both upper and lower 32-bit location of tmp64 are initialized
to 0, so these locations do not contain garbage.

They all generate the same ASM code (RISC-V 32 bit target, -O0)

-- 
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/20201005/5f3a0c54/attachment.html>


More information about the llvm-bugs mailing list