const char *
reproducer::get_identifier_as_rvalue (recording::rvalue *m)
{
+ if (!m)
+ return "NULL";
return m->access_as_rvalue (*this);
}
const char *
reproducer::get_identifier_as_lvalue (recording::lvalue *m)
{
+ if (!m)
+ return "NULL";
return m->access_as_lvalue (*this);
}
const char *
reproducer::get_identifier_as_type (recording::type *m)
{
+ if (!m)
+ return "NULL";
return m->access_as_type (*this);
}
r.write (" gcc_jit_rvalue *value = NULL;\n");
else
r.write (" gcc_jit_rvalue *value = %s;\n",
- r.get_identifier (m_values[0]));
+ r.get_identifier_as_rvalue (m_values[0]));
if (m_fields.length () == 0)
r.write (" gcc_jit_field *field = NULL;\n");
{
r.write (" gcc_jit_rvalue *values[] = {\n");
for (size_t i = 0; i < m_values.length (); i++)
- r.write (" %s,\n", r.get_identifier (m_values[i]));
+ r.write (" %s,\n", r.get_identifier_as_rvalue (m_values[i]));
r.write (" };\n");
}
/* Write the array of fields. */
#undef create_code
#undef verify_code
+/* test-pr117886-write-reproducer.c. */
+#define create_code create_code_pr117886_write_reproducer
+#define verify_code verify_code_pr117886_write_reproducer
+#include "test-pr117886-write-reproducer.c"
+#undef create_code
+#undef verify_code
+
/* test-pure-attribute.c: This can't be in the testcases array as it needs
the `-O3` flag. */
{"pr95314_rvalue_reuse",
create_code_pr95314_rvalue_reuse,
verify_code_pr95314_rvalue_reuse},
+ {"pr117886_write_reproducer",
+ create_code_pr117886_write_reproducer,
+ verify_code_pr117886_write_reproducer},
{"reading_struct ",
create_code_reading_struct ,
verify_code_reading_struct },
--- /dev/null
+/* Verify that we can generate and compile reproducers for
+ gcc_jit_context_new_array_constructor
+ when the values are lvalues */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "libgccjit.h"
+#include "harness.h"
+
+/*
+ int foo[3];
+
+ void test (void)
+ {
+ int a = 1;
+ int b = 2;
+ int c = 3;
+ foo = {a,b,c};
+ }
+*/
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+ gcc_jit_type *int_type
+ = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+ gcc_jit_type *void_type
+ = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
+
+ gcc_jit_type *arr_type = gcc_jit_context_new_array_type (ctxt,
+ 0,
+ int_type,
+ 3);
+ gcc_jit_lvalue *global_intarr_123 = gcc_jit_context_new_global (
+ ctxt, NULL,
+ GCC_JIT_GLOBAL_EXPORTED,
+ arr_type,
+ "global_intarr_123");
+
+ gcc_jit_function *func =
+ gcc_jit_context_new_function (ctxt, NULL,
+ GCC_JIT_FUNCTION_EXPORTED,
+ void_type,
+ "initialize_intarr_123",
+ 0, NULL, 0);
+ gcc_jit_lvalue *a
+ = gcc_jit_function_new_local (func, NULL, int_type, "a");
+ gcc_jit_lvalue *b
+ = gcc_jit_function_new_local (func, NULL, int_type, "b");
+ gcc_jit_lvalue *c
+ = gcc_jit_function_new_local (func, NULL, int_type, "c");
+
+ gcc_jit_block *bb =
+ gcc_jit_function_new_block (func, "initial");
+
+ gcc_jit_block_add_assignment (bb, NULL,
+ a, gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 1));
+ gcc_jit_block_add_assignment (bb, NULL,
+ b, gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 2));
+ gcc_jit_block_add_assignment (bb, NULL,
+ c, gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 3));
+
+ gcc_jit_rvalue *values[] = {(gcc_jit_rvalue *)a,
+ (gcc_jit_rvalue *)b,
+ (gcc_jit_rvalue *)c};
+ gcc_jit_rvalue *ctor = gcc_jit_context_new_array_constructor (ctxt,
+ 0,
+ arr_type,
+ 3,
+ values);
+ gcc_jit_block_add_assignment (bb, NULL,
+ global_intarr_123,
+ ctor);
+
+ gcc_jit_block_end_with_void_return (bb, NULL);
+}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+ CHECK_NON_NULL (result);
+
+ typedef void (*my_fn_type) (void);
+ my_fn_type initialize_intarr_123
+ = (my_fn_type)gcc_jit_result_get_code (result, "initialize_intarr_123");
+ CHECK_NON_NULL (initialize_intarr_123);
+
+ {
+ int *foo = gcc_jit_result_get_global (result, "global_intarr_123");
+ CHECK_NON_NULL (foo);
+
+ CHECK_VALUE (foo[0], 0);
+ CHECK_VALUE (foo[1], 0);
+ CHECK_VALUE (foo[2], 0);
+
+ initialize_intarr_123 ();
+
+ CHECK_VALUE (foo[0], 1);
+ CHECK_VALUE (foo[1], 2);
+ CHECK_VALUE (foo[2], 3);
+ }
+}