[llvm-bugs] [Bug 47993] New: __builtin_object_size() handled inconsistently in latest git with scan-build

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 28 02:09:23 PDT 2020


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

            Bug ID: 47993
           Summary: __builtin_object_size() handled inconsistently in
                    latest git with scan-build
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: tss at iki.fi
                CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org

I upgraded to latest git version of clang yesterday:

clang version 12.0.0 (https://github.com/llvm/llvm-project.git
5839e13910ca0d5ccd11debc0ea3f8491c8c29df)

And I started getting a bunch of warnings in my code base with scan-build (no
warnings with normal clang builds):

warning: Declared variable-length array (VLA) has negative size [core.VLASize]

This happens somewhat inconsistently. Below is the smallest test case I managed
to get to reproduce it:

#include <stdlib.h>
#  define COMPILE_ERROR_IF_TRUE(condition) \
        (sizeof(char[1 - 2 * ((condition) ? 1 : 0)]) - 1)
int extfunc(void);
static void func2(void)
{
        char *d = malloc(10);
        (void)COMPILE_ERROR_IF_TRUE(__builtin_object_size((d),1) < 10);
        free(d);
        if (extfunc() == 0)
                extfunc();
}
void func1(void)
{
        func2();
        func2();
}

# scan-build clang test.c -c -o test.o
test.c:22:8: warning: Declared variable-length array (VLA) has negative size
[core.VLASize]
        (void)COMPILE_ERROR_IF_TRUE(__builtin_object_size((d),1) < 10);
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.c:15:3: note: expanded from macro 'COMPILE_ERROR_IF_TRUE'
        (sizeof(char[1 - 2 * ((condition) ? 1 : 0)]) - 1)
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

-- 
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/20201028/f2e66b70/attachment.html>


More information about the llvm-bugs mailing list