===================================================================
@@ -8600,6 +8600,7 @@
cp_apply_type_quals_to_decl (int type_quals, tree decl)
{
tree type = TREE_TYPE (decl);
+ int was_const;
if (type == error_mark_node)
return;
@@ -8610,6 +8611,9 @@
gcc_assert (!(TREE_CODE (type) == FUNCTION_TYPE
&& type_quals != TYPE_UNQUALIFIED));
+ /* Remember const qualifer even if we don't set TREE_READONLY */
+ was_const = type_quals & TYPE_QUAL_CONST;
+
/* Avoid setting TREE_READONLY incorrectly. */
/* We used to check TYPE_NEEDS_CONSTRUCTING here, but now a constexpr
constructor can produce constant init, so rely on cp_finish_decl to
@@ -8621,6 +8625,9 @@
type_quals &= ~TYPE_QUAL_CONST;
c_apply_type_quals_to_decl (type_quals, decl);
+
+ if (was_const)
+ TREE_WASREADONLY(decl) = 1;
}
/* Subroutine of casts_away_constness. Make T1 and T2 point at
===================================================================
@@ -633,6 +633,7 @@
init = NULL_TREE;
code = pop_stmt_list (code);
DECL_INITIAL (dest) = init;
+ TREE_WASREADONLY (dest) = TREE_READONLY (dest);
TREE_READONLY (dest) = 0;
}
else
===================================================================
@@ -18370,7 +18370,9 @@
if (decl_by_reference_p (decl_or_origin))
add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
else
- add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
+ add_type_attribute (var_die, type,
+ TREE_READONLY (decl_or_origin) ||
+ TREE_WASREADONLY (decl_or_origin),
TREE_THIS_VOLATILE (decl_or_origin), context_die);
}
===================================================================
@@ -438,6 +438,9 @@
unsigned deprecated_flag : 1;
unsigned default_def_flag : 1;
+ unsigned wasreadonly_flag : 1;
+ unsigned spare : 7;
+
union {
/* The bits in the following structure should only be used with
accessor macros that constrain inputs with tree checking. */
@@ -1246,6 +1249,11 @@
as "const" function (can only read its arguments). */
#define TREE_READONLY(NODE) (NON_TYPE_CHECK (NODE)->base.readonly_flag)
+/* Keep track of variables that were declared const, even if they might
+ not be placed in read-only memory. This allows generation of more
+ accurate debug info. */
+#define TREE_WASREADONLY(NODE) (NON_TYPE_CHECK (NODE)->base.wasreadonly_flag)
+
/* Value of expression is constant. Always on in all ..._CST nodes. May
also appear in an expression or decl where the value is constant. */
#define TREE_CONSTANT(NODE) (NON_TYPE_CHECK (NODE)->base.constant_flag)