From fda5652f8fe24f637b29608d12fff72e6df08ba9 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 22 Dec 2015 15:23:21 +0000 Subject: re PR c/69002 (C front end should warn about undefined access to atomic structure or union) PR c/69002 * c-typeck.c (build_component_ref): Warn when acessing elements of atomic structures or unions. * gcc.dg/c11-atomic-1.c: Add dg-warnings. * gcc.dg/c11-atomic-4.c: New test. From-SVN: r231902 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-typeck.c | 12 ++++++++++++ 2 files changed, 18 insertions(+) (limited to 'gcc/c') diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index fb9fda3..f99f426 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2015-12-22 Marek Polacek + + PR c/69002 + * c-typeck.c (build_component_ref): Warn when acessing elements of + atomic structures or unions. + 2015-12-21 David Malcolm * c-typeck.c: Include "gcc-rich-location.h". diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index a97774f..928fcd5 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -2349,6 +2349,18 @@ build_component_ref (location_t loc, tree datum, tree component) return error_mark_node; } + /* Accessing elements of atomic structures or unions is undefined + behavior (C11 6.5.2.3#5). */ + if (TYPE_ATOMIC (type) && c_inhibit_evaluation_warnings == 0) + { + if (code == RECORD_TYPE) + warning_at (loc, 0, "accessing a member %qE of an atomic " + "structure %qE", component, datum); + else + warning_at (loc, 0, "accessing a member %qE of an atomic " + "union %qE", component, datum); + } + /* Chain the COMPONENT_REFs if necessary down to the FIELD. This might be better solved in future the way the C++ front end does it - by giving the anonymous entities each a -- cgit v1.1