forked from wangliu-iscas/gcc-patch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle component_ref to a structre/union field including flexible arr…
…ay member [PR101832] GCC extension accepts the case when a struct with a C99 flexible array member is embedded into another struct or union (possibly recursively) as the last field. __builtin_object_size should treat such struct as flexible size. gcc/c/ChangeLog: PR tree-optimization/101832 * c-decl.cc (finish_struct): Set TYPE_INCLUDES_FLEXARRAY for struct/union type. gcc/lto/ChangeLog: PR tree-optimization/101832 * lto-common.cc (compare_tree_sccs_1): Compare bit TYPE_NO_NAMED_ARGS_STDARG_P or TYPE_INCLUDES_FLEXARRAY properly for its corresponding type. gcc/ChangeLog: PR tree-optimization/101832 * print-tree.cc (print_node): Print new bit type_includes_flexarray. * tree-core.h (struct tree_type_common): Use bit no_named_args_stdarg_p as type_includes_flexarray for RECORD_TYPE or UNION_TYPE. * tree-object-size.cc (addr_object_size): Handle structure/union type when it has flexible size. * tree-streamer-in.cc (unpack_ts_type_common_value_fields): Stream in bit no_named_args_stdarg_p properly for its corresponding type. * tree-streamer-out.cc (pack_ts_type_common_value_fields): Stream out bit no_named_args_stdarg_p properly for its corresponding type. * tree.h (TYPE_INCLUDES_FLEXARRAY): New macro TYPE_INCLUDES_FLEXARRAY. gcc/testsuite/ChangeLog: PR tree-optimization/101832 * gcc.dg/builtin-object-size-pr101832.c: New test.
- Loading branch information
1 parent
c2d62cd
commit 61957ae
Showing
9 changed files
with
192 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* PR 101832: | ||
GCC extension accepts the case when a struct with a C99 flexible array | ||
member is embedded into another struct (possibly recursively). | ||
__builtin_object_size will treat such struct as flexible size. | ||
However, when a structure with non-C99 flexible array member, i.e, trailing | ||
[0], [1], or [4], is embedded into anther struct, the stucture will not | ||
be treated as flexible size. */ | ||
/* { dg-do run } */ | ||
/* { dg-options "-O2" } */ | ||
|
||
#include "builtin-object-size-common.h" | ||
|
||
#define expect(p, _v) do { \ | ||
size_t v = _v; \ | ||
if (p == v) \ | ||
__builtin_printf ("ok: %s == %zd\n", #p, p); \ | ||
else {\ | ||
__builtin_printf ("WAT: %s == %zd (expected %zd)\n", #p, p, v); \ | ||
FAIL (); \ | ||
} \ | ||
} while (0); | ||
|
||
|
||
struct A { | ||
int n; | ||
char data[]; | ||
}; | ||
|
||
struct B { | ||
int m; | ||
struct A a; | ||
}; | ||
|
||
struct C { | ||
int q; | ||
struct B b; | ||
}; | ||
|
||
struct A0 { | ||
int n; | ||
char data[0]; | ||
}; | ||
|
||
struct B0 { | ||
int m; | ||
struct A0 a; | ||
}; | ||
|
||
struct C0 { | ||
int q; | ||
struct B0 b; | ||
}; | ||
|
||
struct A1 { | ||
int n; | ||
char data[1]; | ||
}; | ||
|
||
struct B1 { | ||
int m; | ||
struct A1 a; | ||
}; | ||
|
||
struct C1 { | ||
int q; | ||
struct B1 b; | ||
}; | ||
|
||
struct An { | ||
int n; | ||
char data[8]; | ||
}; | ||
|
||
struct Bn { | ||
int m; | ||
struct An a; | ||
}; | ||
|
||
struct Cn { | ||
int q; | ||
struct Bn b; | ||
}; | ||
|
||
volatile void *magic1, *magic2; | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
struct B *outer; | ||
struct C *outest; | ||
|
||
/* Make sure optimization can't find some other object size. */ | ||
outer = (void *)magic1; | ||
outest = (void *)magic2; | ||
|
||
expect (__builtin_object_size (&outer->a, 1), -1); | ||
expect (__builtin_object_size (&outest->b, 1), -1); | ||
expect (__builtin_object_size (&outest->b.a, 1), -1); | ||
|
||
struct B0 *outer0; | ||
struct C0 *outest0; | ||
|
||
/* Make sure optimization can't find some other object size. */ | ||
outer0 = (void *)magic1; | ||
outest0 = (void *)magic2; | ||
|
||
expect (__builtin_object_size (&outer0->a, 1), sizeof (outer0->a)); | ||
expect (__builtin_object_size (&outest0->b, 1), sizeof (outest0->b)); | ||
expect (__builtin_object_size (&outest0->b.a, 1), sizeof (outest0->b.a)); | ||
|
||
struct B1 *outer1; | ||
struct C1 *outest1; | ||
|
||
/* Make sure optimization can't find some other object size. */ | ||
outer1 = (void *)magic1; | ||
outest1 = (void *)magic2; | ||
|
||
expect (__builtin_object_size (&outer1->a, 1), sizeof (outer1->a)); | ||
expect (__builtin_object_size (&outest1->b, 1), sizeof (outest1->b)); | ||
expect (__builtin_object_size (&outest1->b.a, 1), sizeof (outest1->b.a)); | ||
|
||
struct Bn *outern; | ||
struct Cn *outestn; | ||
|
||
/* Make sure optimization can't find some other object size. */ | ||
outern = (void *)magic1; | ||
outestn = (void *)magic2; | ||
|
||
expect (__builtin_object_size (&outern->a, 1), sizeof (outern->a)); | ||
expect (__builtin_object_size (&outestn->b, 1), sizeof (outestn->b)); | ||
expect (__builtin_object_size (&outestn->b.a, 1), sizeof (outestn->b.a)); | ||
|
||
DONE (); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters