+2005-10-05 Paolo Bonzini <bonzini@gnu.org>
+
+ PR tree-optimization/21419
+ PR tree-optimization/24146
+ PR tree-optimization/24151
+
+ * c-typeck.c (readonly_error): Handle USE being lv_asm.
+ (build_asm_expr): Call it if outputs are read-only.
+ * gimplify.c (gimplify_asm_expr): Remove former fix to PR 21419.
+
2005-10-05 Billy Biggs <billy.biggs@gmail.com>
Paolo Bonzini <bonzini@gnu.org>
static void
readonly_error (tree arg, enum lvalue_use use)
{
- gcc_assert (use == lv_assign || use == lv_increment || use == lv_decrement);
+ gcc_assert (use == lv_assign || use == lv_increment || use == lv_decrement
+ || use == lv_asm);
/* Using this macro rather than (for example) arrays of messages
ensures that all the format strings are checked at compile
time. */
-#define READONLY_MSG(A, I, D) (use == lv_assign \
- ? (A) \
- : (use == lv_increment ? (I) : (D)))
+#define READONLY_MSG(A, I, D, AS) (use == lv_assign ? (A) \
+ : (use == lv_increment ? (I) \
+ : (use == lv_decrement ? (D) : (AS))))
if (TREE_CODE (arg) == COMPONENT_REF)
{
if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
else
error (READONLY_MSG (G_("assignment of read-only member %qD"),
G_("increment of read-only member %qD"),
- G_("decrement of read-only member %qD")),
+ G_("decrement of read-only member %qD"),
+ G_("read-only member %qD used as %<asm%> output")),
TREE_OPERAND (arg, 1));
}
else if (TREE_CODE (arg) == VAR_DECL)
error (READONLY_MSG (G_("assignment of read-only variable %qD"),
G_("increment of read-only variable %qD"),
- G_("decrement of read-only variable %qD")),
+ G_("decrement of read-only variable %qD"),
+ G_("read-only variable %qD used as %<asm%> output")),
arg);
else
error (READONLY_MSG (G_("assignment of read-only location"),
G_("increment of read-only location"),
- G_("decrement of read-only location")));
+ G_("decrement of read-only location"),
+ G_("read-only location used as %<asm%> output")));
}
if (!lvalue_or_else (output, lv_asm))
output = error_mark_node;
+ if (output != error_mark_node
+ && (TREE_READONLY (output)
+ || TYPE_READONLY (TREE_TYPE (output))
+ || ((TREE_CODE (TREE_TYPE (output)) == RECORD_TYPE
+ || TREE_CODE (TREE_TYPE (output)) == UNION_TYPE)
+ && C_TYPE_FIELDS_READONLY (TREE_TYPE (output)))))
+ readonly_error (output, lv_asm);
+
constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
oconstraints[i] = constraint;
args = build_stmt (ASM_EXPR, string, outputs, inputs, clobbers);
- /* Simple asm statements are treated as volatile. */
- if (simple)
- {
- ASM_VOLATILE_P (args) = 1;
- ASM_INPUT_P (args) = 1;
- }
+ /* asm statements without outputs, including simple ones, are treated
+ as volatile. */
+ ASM_INPUT_P (args) = simple;
+ ASM_VOLATILE_P (args) = (noutputs == 0);
return args;
}
+2005-10-05 Paolo Bonzini <bonzini@gnu.org>
+
+ PR tree-optimization/21419
+ PR tree-optimization/24146
+ PR tree-optimization/24151
+
+ * semantics.c (finish_asm_stmt): Call readonly_error if outputs are
+ read-only. Set ASM_VOLATILE_P for asms without outputs.
+
2005-10-05 Nathan Sidwell <nathan@codesourcery.com>
PR c++/23513
{
tree r;
tree t;
+ int ninputs = list_length (input_operands);
+ int noutputs = list_length (output_operands);
if (!processing_template_decl)
{
- int ninputs, noutputs;
const char *constraint;
const char **oconstraints;
bool allows_mem, allows_reg, is_inout;
tree operand;
int i;
- ninputs = list_length (input_operands);
- noutputs = list_length (output_operands);
oconstraints = (const char **) alloca (noutputs * sizeof (char *));
string = resolve_asm_operand_names (string, output_operands,
if (!lvalue_or_else (operand, lv_asm))
operand = error_mark_node;
+ if (operand != error_mark_node
+ && (TREE_READONLY (operand)
+ || CP_TYPE_CONST_P (TREE_TYPE (operand))
+ /* Functions are not modifiable, even though they are
+ lvalues. */
+ || TREE_CODE (TREE_TYPE (operand)) == FUNCTION_TYPE
+ || TREE_CODE (TREE_TYPE (operand)) == METHOD_TYPE
+ /* If it's an aggregate and any field is const, then it is
+ effectively const. */
+ || (CLASS_TYPE_P (TREE_TYPE (operand))
+ && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
+ readonly_error (operand, "assignment (via 'asm' output)", 0);
+
constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
oconstraints[i] = constraint;
r = build_stmt (ASM_EXPR, string,
output_operands, input_operands,
clobbers);
- ASM_VOLATILE_P (r) = volatile_p;
+ ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
r = maybe_cleanup_point_expr_void (r);
return add_stmt (r);
}
parse_output_constraint (&constraint, i, 0, 0,
&allows_mem, &allows_reg, &is_inout);
- if (TYPE_READONLY (TREE_TYPE (TREE_VALUE (link))))
- {
- error ("invalid lvalue in asm output %d", i);
- ret = GS_ERROR;
- }
-
if (!allows_reg && allows_mem)
lang_hooks.mark_addressable (TREE_VALUE (link));
+2005-10-05 Paolo Bonzini <bonzini@gnu.org>
+
+ PR tree-optimization/21419
+ PR tree-optimization/24146
+ PR tree-optimization/24151
+
+ * g++.dg/ext/asm7.C: New.
+ * g++.dg/ext/asm8.C: New.
+ * gcc.dg/asm-1.c: Compile on all targets.
+ * gcc.dg/asm-pr24146.c: New.
+ * gcc.dg/pr21419.c: Adjust error messages.
+
2005-10-05 Richard Guenther <rguenther@suse.de>
PR fortran/24176
--- /dev/null
+/* { dg-do compile } */
+const int i = 0;
+
+void f(void)
+{
+ __asm__ __volatile__ ("" : "=m" (i)); /* { dg-error "read-only variable" } */
+}
+
+void g(const int set)
+{
+ __asm__ __volatile__ ("" : "=r" (set)); /* { dg-error "read-only parameter" } */
+}
+
+
--- /dev/null
+/* { dg-do compile } */
+
+/* Test that asm with no outputs are treated as volatile. */
+
+void f(int x)
+{
+ __asm__ ("extended asm not discarded" : : "r" (x));
+}
+
+void g (void)
+{
+ __asm__ ("simple asm not discarded");
+}
+/* { dg-final { scan-assembler "extended asm not discarded" } } */
+/* { dg-final { scan-assembler "simple asm not discarded" } } */
+
-/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
+/* { dg-do compile } */
struct x {
int selector;
--- /dev/null
+/* { dg-do compile } */
+
+/* Test that asm with no outputs are treated as volatile. */
+
+void f(int x)
+{
+ __asm__ ("extended asm not discarded" : : "r" (x));
+}
+
+void g (void)
+{
+ __asm__ ("simple asm not discarded");
+}
+/* { dg-final { scan-assembler "extended asm not discarded" } } */
+/* { dg-final { scan-assembler "simple asm not discarded" } } */
+
void f(void)
{
- __asm__ __volatile__ ("" : "=m" (i)); /* { dg-error "invalid lvalue in asm output" } */
+ __asm__ __volatile__ ("" : "=m" (i)); /* { dg-error "read-only variable" } */
}
void g(const int set)
{
- __asm__ __volatile__ ("" : "=r" (set)); /* { dg-error "invalid lvalue in asm output" } */
+ __asm__ __volatile__ ("" : "=r" (set)); /* { dg-error "read-only location" } */
}