[Bug c/112840] feature request: warn on incorrect tagged union value access

2024-01-29 Thread matheus.a.m.moreira at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112840

--- Comment #3 from Matheus Afonso Martins Moreira  ---
(In reply to uecker from comment #2)
> I would go for a more generic feature where one can specify some invariant /
> condition that needs be true when a member of a struct / union is accessed.

So the proposed solution is a guard(expr) attribute that causes the compiler to
warn the developer if it can't statically determine that expr is true in the
appropriate context.

This would be great!! Much more flexible than the tag attribute I proposed. How
can we make it happen? I've never hacked on GCC before.

[Bug c/112840] feature request: warn on incorrect tagged union value access

2023-12-17 Thread uecker at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112840

uecker at gcc dot gnu.org changed:

   What|Removed |Added

 CC||uecker at gcc dot gnu.org

--- Comment #2 from uecker at gcc dot gnu.org ---
I would go for a more generic feature where one can specify some invariant /
condition that needs be true when a member of a struct / union is accessed.



 struct S {
enum T t;
union U {
int i   [[gnu::guard(.t == I)]];
float f [[gnu::guard(.t == f)]];
} u;
};

[Bug c/112840] feature request: warn on incorrect tagged union value access

2023-12-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112840

--- Comment #1 from Andrew Pinski  ---
This seems more like something for analyzier rather than a generic warning due
to it requires keeping track of the path where the access is located.

[Bug c/112840] feature request: warn on incorrect tagged union value access

2023-12-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112840

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||diagnostic
   Severity|normal  |enhancement
   See Also||https://github.com/llvm/llv
   ||m-project/issues/74205