http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49535

           Summary: __builtin_object_size incorrect for array arguments
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: mse...@gmail.com


When compiled with gcc 4.4 and 4.5 (at -O1 or above) the program below prints
the following output:
800 800 800 800
800 800 800 800
800 800 800 800
800 800 800 800

When compiled with 4.6 (regardless of the -O setting) it prints this instead:
800 800 800 800
18446744073709551615 18446744073709551615 0 0
18446744073709551615 18446744073709551615 0 0
18446744073709551615 18446744073709551615 0 0

I believe the first output is expected and the second is wrong.

extern int printf (const char* fmt, ...);

#define BOS(a) \
    printf ("%zu %zu %zu %zu\n", \
            __builtin_object_size (a, 0), \
            __builtin_object_size (a, 1), \
            __builtin_object_size (a, 2), \
            __builtin_object_size (a, 3))

inline void f0 (int *a) { BOS (a); }
inline void f1 (int a[20]) { BOS (a); }
inline void f2 (int a[10][20]) { BOS (a); }

int main (void) {
    int a[10][20];

    BOS (a);

    f0 (a[0]);
    f1 (a[0]);
    f2 (a);
}

Reply via email to