// case BT_DFLOAT128:
// case BT_VALIST_REF:
// case BT_VALIST_ARG:
- // case BT_I1:
- // case BT_I2:
- // case BT_I4:
- // case BT_I8:
- // case BT_I16:
+ case BT_I1: return m_ctxt->get_int_type (1, true);
+ case BT_I2: return m_ctxt->get_int_type (2, true);
+ case BT_I4: return m_ctxt->get_int_type (4, true);
+ case BT_I8: return m_ctxt->get_int_type (8, true);
+ case BT_I16: return m_ctxt->get_int_type (16, true);
// case BT_PTR_CONST_STRING:
}
}
return false;
/* It's OK to assign to a (const T *) from a (T *). */
- return m_other_type->unqualified ()
- ->accepts_writes_from (rtype_points_to);
+ if (m_other_type->unqualified ()->accepts_writes_from (rtype_points_to))
+ {
+ return true;
+ }
+
+ /* It's OK to assign to a (volatile const T *) from a (volatile const T *). */
+ return m_other_type->is_same_type_as (rtype_points_to);
}
/* Implementation of pure virtual hook recording::memento::replay_into
virtual bool is_float () const = 0;
virtual bool is_bool () const = 0;
virtual type *is_pointer () = 0;
+ virtual type *is_volatile () { return NULL; }
+ virtual type *is_const () { return NULL; }
virtual type *is_array () = 0;
virtual struct_ *is_struct () { return NULL; }
virtual bool is_void () const { return false; }
/* Strip off the "const", giving the underlying type. */
type *unqualified () FINAL OVERRIDE { return m_other_type; }
+ virtual bool is_same_type_as (type *other)
+ {
+ if (!other->is_const ())
+ return false;
+ return m_other_type->is_same_type_as (other->is_const ());
+ }
+
+ virtual type *is_const () { return m_other_type; }
+
void replay_into (replayer *) FINAL OVERRIDE;
private:
memento_of_get_volatile (type *other_type)
: decorated_type (other_type) {}
+ virtual bool is_same_type_as (type *other)
+ {
+ if (!other->is_volatile ())
+ return false;
+ return m_other_type->is_same_type_as (other->is_volatile ());
+ }
+
/* Strip off the "volatile", giving the underlying type. */
type *unqualified () FINAL OVERRIDE { return m_other_type; }
+ virtual type *is_volatile () { return m_other_type; }
+
void replay_into (replayer *) FINAL OVERRIDE;
private:
#undef create_code
#undef verify_code
+/* test-builtin-types.c */
+#define create_code create_code_builtin_types
+#define verify_code verify_code_builtin_types
+#include "test-builtin-types.c"
+#undef create_code
+#undef verify_code
+
/* test-hello-world.c */
#define create_code create_code_hello_world
#define verify_code verify_code_hello_world
{"functions",
create_code_functions,
verify_code_functions},
+ {"builtin-types",
+ create_code_builtin_types,
+ verify_code_builtin_types},
{"hello_world",
create_code_hello_world,
verify_code_hello_world},
--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#include "libgccjit.h"
+
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+ CHECK_NON_NULL (gcc_jit_context_get_builtin_function (ctxt, "__atomic_fetch_add_4"));
+
+ gcc_jit_function *atomic_load = gcc_jit_context_get_builtin_function (ctxt, "__atomic_load_8");
+
+ gcc_jit_type *void_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
+ gcc_jit_type *const_void_type =
+ gcc_jit_type_get_const (gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID));
+ gcc_jit_type *volatile_void_ptr =
+ gcc_jit_type_get_pointer (gcc_jit_type_get_volatile (const_void_type));
+ gcc_jit_type *long_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG);
+ gcc_jit_type *int_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+ gcc_jit_function *func =
+ gcc_jit_context_new_function (ctxt, NULL, GCC_JIT_FUNCTION_EXPORTED, void_type, "atomics", 0, NULL, 0);
+
+ gcc_jit_lvalue *variable = gcc_jit_function_new_local (func, NULL, long_type, "variable");
+ gcc_jit_rvalue *builtin_args[2];
+ gcc_jit_rvalue *param1 = gcc_jit_lvalue_get_address(variable, NULL);
+ builtin_args[0] = gcc_jit_context_new_cast(ctxt, NULL, param1, volatile_void_ptr);
+ builtin_args[1] = gcc_jit_context_new_rvalue_from_long(ctxt, int_type, 0);
+ gcc_jit_context_new_call (ctxt, NULL, atomic_load, 2, builtin_args);
+}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+ /* Verify that no errors were emitted. */
+ CHECK_NON_NULL (result);
+}
--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "libgccjit.h"
+
+#include "harness.h"
+
+void
+create_code (gcc_jit_context *ctxt, void *user_data)
+{
+ /* Let's try to inject the equivalent of:
+
+ void
+ test_fn ()
+ {
+ long integer;
+ volatile const void *variable;
+ variable = &integer;
+ long aligned_integer __attribute__((aligned(4)));
+ variable = &aligned_integer;
+ }
+
+ and verify that the API complains about the mismatching types
+ in the assignments.
+ */
+ gcc_jit_type *void_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
+ gcc_jit_type *long_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG);
+ gcc_jit_type *const_void_type =
+ gcc_jit_type_get_const (void_type);
+ gcc_jit_type *volatile_void_ptr =
+ gcc_jit_type_get_pointer (gcc_jit_type_get_volatile (const_void_type));
+
+ gcc_jit_function *func =
+ gcc_jit_context_new_function (ctxt, NULL,
+ GCC_JIT_FUNCTION_EXPORTED,
+ void_type,
+ "test_fn",
+ 0, NULL,
+ 0);
+
+ gcc_jit_lvalue *integer = gcc_jit_function_new_local (func, NULL, long_type, "integer");
+ gcc_jit_rvalue *address = gcc_jit_lvalue_get_address(integer, NULL);
+
+ gcc_jit_lvalue *variable = gcc_jit_function_new_local (func, NULL, volatile_void_ptr, "variable");
+ gcc_jit_block *initial =
+ gcc_jit_function_new_block (func, "initial");
+ gcc_jit_block_add_assignment(initial, NULL, variable, address);
+
+ gcc_jit_type *aligned_long_type = gcc_jit_type_get_aligned (long_type, 4);
+ gcc_jit_lvalue *aligned_integer = gcc_jit_function_new_local (func, NULL, aligned_long_type, "aligned_integer");
+ gcc_jit_rvalue *aligned_address = gcc_jit_lvalue_get_address(aligned_integer, NULL);
+
+ gcc_jit_block_add_assignment(initial, NULL, variable, aligned_address);
+
+ gcc_jit_block_end_with_void_return (initial, NULL);
+}
+
+void
+verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
+{
+ CHECK_VALUE (result, NULL);
+
+ /* Verify that the correct error messages were emitted. */
+ CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
+ "gcc_jit_block_add_assignment:"
+ " mismatching types:"
+ " assignment to variable (type: volatile const void *)"
+ " from &integer (type: long *)");
+
+ CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt),
+ "gcc_jit_block_add_assignment:"
+ " mismatching types:"
+ " assignment to variable (type: volatile const void *)"
+ " from &aligned_integer (type: long __attribute__((aligned(4))) *)");
+}
+
static gcc_jit_type *
make_random_type (fuzzer *f)
{
- switch (fuzzer_randrange (f, 0, 5))
+ switch (fuzzer_randrange (f, 0, 8))
{
case 0:
return gcc_jit_type_get_pointer (get_random_type (f));
case 1:
return gcc_jit_type_get_const (get_random_type (f));
+ case 2:
+ return gcc_jit_type_get_vector (get_random_type (f), 4);
+ case 3:
+ return gcc_jit_type_get_volatile (get_random_type (f));
+ case 4:
+ return gcc_jit_type_get_aligned (get_random_type (f), 4);
default:
{
/* Create a struct. */