summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-2993.c
blob: c97670d85f8be5a96379070f7f4c10b276de4e01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* bug-2993.c
   Invalid asm was generated in the stm8 backend for calls via immediate (or literal) function pointers.
 */

#include <testfwk.h>

void f(void)
{
	void (*p)(void) __reentrant = (void (*)(void))0x24;
	(*p)();
}

int func(void *var,int val) __reentrant;
typedef int (*SetVal)(void *, int) __reentrant;
typedef struct {
                int val;
                SetVal setval;
                } my_struct; 

void
testBug(void)
{  
    my_struct str1 = {0,func};
    my_struct str2 = {0,func};
    str1.setval(&str1,11);  
    str2.setval(&str2,5);
    
    ASSERT (str1.val == 11);
    ASSERT (str2.val == 5);
}

int func(void *var,int val) __reentrant
{
    my_struct *tmp = (my_struct*)var;
    tmp->val = val;
    return 0;
}