From 59c79ae734b55f89bc5ac1d6d5372cb323e9f118 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Tue, 29 Aug 2006 14:15:20 -0400 Subject: [PATCH] re PR c++/26577 (ICE in cp_expr_size with volatile and non POD) PR c++/26577 * cvt.c (convert_to_void): Don't automatically load from volatiles of TREE_ADDRESSABLE type. From-SVN: r116568 --- gcc/cp/ChangeLog | 6 +++++ gcc/cp/cvt.c | 37 +++++++++++++++------------ gcc/testsuite/g++.dg/warn/volatile1.C | 12 +++++++++ 3 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/volatile1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c0363ef140ce..b8eb591833fd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2006-08-28 Jason Merrill + + PR c++/26577 + * cvt.c (convert_to_void): Don't automatically load from volatiles + of TREE_ADDRESSABLE type. + 2006-08-28 Volker Reichelt PR c++/28860 diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 455027965fdb..0e1a8431202c 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -848,23 +848,26 @@ convert_to_void (tree expr, const char *implicit) case INDIRECT_REF: { - tree type = TREE_TYPE (expr); - int is_reference = TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) - == REFERENCE_TYPE; - int is_volatile = TYPE_VOLATILE (type); - int is_complete = COMPLETE_TYPE_P (complete_type (type)); - - if (is_volatile && !is_complete) - warning ("object of incomplete type %qT will not be accessed in %s", - type, implicit ? implicit : "void context"); - else if (is_reference && is_volatile) - warning ("object of type %qT will not be accessed in %s", - TREE_TYPE (TREE_OPERAND (expr, 0)), - implicit ? implicit : "void context"); - if (is_reference || !is_volatile || !is_complete) - expr = TREE_OPERAND (expr, 0); - - break; + tree type = TREE_TYPE (expr); + int is_reference = TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) + == REFERENCE_TYPE; + int is_volatile = TYPE_VOLATILE (type); + int is_complete = COMPLETE_TYPE_P (complete_type (type)); + + /* Can't load the value if we don't know the type. */ + if (is_volatile && !is_complete) + warning ("object of incomplete type %qT will not be accessed in %s", + type, implicit ? implicit : "void context"); + /* Don't load the value if this is an implicit dereference, or if + the type needs to be handled by ctors/dtors. */ + else if (is_volatile && (is_reference || TREE_ADDRESSABLE (type))) + warning ("object of type %qT will not be accessed in %s", + TREE_TYPE (TREE_OPERAND (expr, 0)), + implicit ? implicit : "void context"); + if (is_reference || !is_volatile || !is_complete || TREE_ADDRESSABLE (type)) + expr = TREE_OPERAND (expr, 0); + + break; } case VAR_DECL: diff --git a/gcc/testsuite/g++.dg/warn/volatile1.C b/gcc/testsuite/g++.dg/warn/volatile1.C new file mode 100644 index 000000000000..5b1050f9a1c0 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/volatile1.C @@ -0,0 +1,12 @@ +// PR c++/26577 + +struct A +{ + A(const A&); + A& operator=(const A&); + void baz() volatile; +}; +void A::baz() volatile +{ + *this; // { dg-warning "will not be accessed" } +} -- 2.47.2