forked from gcc-mirror/gcc
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libgccjit: Allow sending a const pointer as argument
gcc/jit/ChangeLog: * jit-recording.h: Remove memento_of_get_const::accepts_writes_from, memento_of_get_type::is_same_type_as: new method. gcc/testsuite/ChangeLog: * jit.dg/all-non-failing-tests.h: Add test-const-pointer-argument.c. * jit.dg/test-const-pointer-argument.c: New test.
- Loading branch information
Showing
3 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#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) | ||
{ | ||
/* Let's try to inject the equivalent of: | ||
void test_ptr(const void* value) | ||
{ | ||
return; | ||
} | ||
void main (void) | ||
{ | ||
const void *ptr; | ||
test_ptr (ptr); | ||
return; | ||
} | ||
*/ | ||
gcc_jit_type *void_type = | ||
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID); | ||
gcc_jit_type *real_void_ptr_type = | ||
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID_PTR); | ||
gcc_jit_type *const_real_void_ptr_type = | ||
gcc_jit_type_get_const (real_void_ptr_type); | ||
|
||
/* Build the test_ptr. */ | ||
gcc_jit_param *param = | ||
gcc_jit_context_new_param (ctxt, NULL, const_real_void_ptr_type, "value"); | ||
gcc_jit_function *test_ptr = | ||
gcc_jit_context_new_function (ctxt, NULL, | ||
GCC_JIT_FUNCTION_EXPORTED, | ||
void_type, | ||
"test_ptr", | ||
1, ¶m, | ||
0); | ||
gcc_jit_block *block = gcc_jit_function_new_block (test_ptr, NULL); | ||
gcc_jit_block_end_with_void_return (block, NULL); | ||
|
||
/* Build main. */ | ||
gcc_jit_function *main = | ||
gcc_jit_context_new_function (ctxt, NULL, | ||
GCC_JIT_FUNCTION_EXPORTED, | ||
void_type, | ||
"main", | ||
0, NULL, | ||
0); | ||
gcc_jit_block *main_block = gcc_jit_function_new_block (main, NULL); | ||
|
||
gcc_jit_type *void_ptr_type = | ||
gcc_jit_type_get_pointer (void_type); | ||
gcc_jit_type *const_void_ptr_type = | ||
gcc_jit_type_get_const (void_ptr_type); | ||
|
||
gcc_jit_lvalue *pointer = | ||
gcc_jit_function_new_local (main, NULL, const_void_ptr_type, "ptr"); | ||
gcc_jit_rvalue *ptr_rvalue = gcc_jit_lvalue_as_rvalue (pointer); | ||
|
||
gcc_jit_block_add_eval (main_block, NULL, | ||
gcc_jit_context_new_call (ctxt, NULL, test_ptr, 1, &ptr_rvalue)); | ||
gcc_jit_block_end_with_void_return (main_block, NULL); | ||
} | ||
|
||
void | ||
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) | ||
{ | ||
CHECK_NON_NULL (result); | ||
} |