-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Closed
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behaviorclang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.
Milestone
Description
As seen in the Linux kernel:
- https://lore.kernel.org/all/202409170436.C3C6E7F7A@keescook/
- https://lore.kernel.org/all/CAGG=3QVWCQB-3sM=iwgTmX8zrU81H+F_A1icJwROvW_DSvsBeA@mail.gmail.com
we're having erroneous size reporting from __builtin_dynamic_object_size()
, where the depth of dereference for the flexible array causes a 0 size report:
https://godbolt.org/z/qohGd5xh1
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
struct variable {
int a;
int b;
int length;
short array[] __attribute__((counted_by(length)));
};
struct bucket {
int a;
struct variable *growable;
int b;
};
int main(int argc, char *argv[])
{
struct bucket *p;
struct variable *v;
p = malloc(sizeof(*p));
v = malloc(sizeof(*p->growable) + sizeof(*p->growable->array) * 32);
v->length = 32;
printf("%zu\n", __builtin_dynamic_object_size(v->array, 1));
p->growable = v;
printf("%zu\n", __builtin_dynamic_object_size(p->growable->array, 1));
return 0;
}
GCC shows 64 64, but Clang shows 64 0.
Metadata
Metadata
Assignees
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behaviorclang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.
Type
Projects
Status
Done