[go: up one dir, main page]

File: acc_chkr.ch

package info (click to toggle)
ucl 1.03-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,884 kB
  • ctags: 9,973
  • sloc: sh: 11,725; asm: 10,461; ansic: 5,057; makefile: 137
file content (126 lines) | stat: -rw-r--r-- 3,010 bytes parent folder | download | duplicates (11)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* ACC -- Automatic Compiler Configuration

   Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
   All Rights Reserved.

   This software is a copyrighted work licensed under the terms of
   the GNU General Public License. Please consult the file "ACC_LICENSE"
   for details.

   Markus F.X.J. Oberhumer
   <markus@oberhumer.com>
   http://www.oberhumer.com/
 */


/*************************************************************************
//
**************************************************************************/

#if !defined(__ACCCHKR_FUNCNAME)
#  define __ACCCHKR_FUNCNAME(f) accchkr_ ## f
#endif



#if !defined(ACCCHKR_ASSERT)

#if 0 || defined(ACCCHKR_CONFIG_DEBUG)

#include <stdio.h>
static int __ACCCHKR_FUNCNAME(assert_fail)(const char* s, unsigned l)
{
    fprintf(stderr, "ACCCHKR assertion failed in line %u: `%s'\n", l, s);
    return 0;
}
#define ACCCHKR_ASSERT(expr)    ((expr) ? 1 : __ACCCHKR_FUNCNAME(assert_fail)(#expr,__LINE__))

#else

#define ACCCHKR_ASSERT(expr)    ((expr) ? 1 : 0)

#endif

#endif



/* avoid inlining */
static int __ACCCHKR_FUNCNAME(schedule_insns_bug)(void);
static int __ACCCHKR_FUNCNAME(strength_reduce_bug)(int*);


/*************************************************************************
// main entry
**************************************************************************/

static int __ACCCHKR_FUNCNAME(check)(int r)
{
#if defined(ACC_ENDIAN_BIG_ENDIAN)
    {
        union { long l; unsigned char c[sizeof(long)]; } u;
        u.l = 0; u.c[sizeof(long)-1] = 0x80;
        r &= ACCCHKR_ASSERT(u.l == 128);
        u.l = 0; u.c[0] = 0x80;
        r &= ACCCHKR_ASSERT(u.l < 0);
        ACC_UNUSED(u);
    }
#endif
#if defined(ACC_ENDIAN_LITTLE_ENDIAN)
    {
        union { long l; unsigned char c[sizeof(long)]; } u;
        u.l = 0; u.c[0] = 0x80;
        r &= ACCCHKR_ASSERT(u.l == 128);
        u.l = 0; u.c[sizeof(long)-1] = 0x80;
        r &= ACCCHKR_ASSERT(u.l < 0);
        ACC_UNUSED(u);
    }
#endif

    /* check for the gcc schedule-insns optimization bug */
    if (r == 1)
    {
        r &= ACCCHKR_ASSERT(!__ACCCHKR_FUNCNAME(schedule_insns_bug()));
    }

    /* check for the gcc strength-reduce optimization bug */
    if (r == 1)
    {
        static int x[3];
        static unsigned xn = 3;
        register unsigned j;

        for (j = 0; j < xn; j++)
            x[j] = (int)j - 3;
        r &= ACCCHKR_ASSERT(!__ACCCHKR_FUNCNAME(strength_reduce_bug(x)));
    }

    return r;
}


/*************************************************************************
//
**************************************************************************/

static int __ACCCHKR_FUNCNAME(schedule_insns_bug)(void)
{
    const int a[] = {1, 2, 0}; const int* b;
    b = a; return (*b) ? 0 : 1;
}


static int __ACCCHKR_FUNCNAME(strength_reduce_bug)(int* x)
{
#if 0 && (ACC_CC_DMC || ACC_CC_SYMANTECC || ACC_CC_ZORTECHC)
    ACC_UNUSED(x); return 0;
#else
    return x[0] != -3 || x[1] != -2 || x[2] != -1;
#endif
}



/*
vi:ts=4:et
*/