URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Go to most recent revision |
Details |
Compare with Previous |
View Log
Line No. |
Rev |
Author |
Line |
1 |
298 |
jeremybenn |
/* Test for constant expressions: details of what is a null pointer
|
2 |
|
|
constant.
|
3 |
|
|
*/
|
4 |
|
|
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
|
5 |
|
|
/* { dg-do compile } */
|
6 |
|
|
/* { dg-options "-std=iso9899:1990" } */
|
7 |
|
|
/* Note: not using -pedantic since the -std option alone should be enough
|
8 |
|
|
to give the correct behavior to conforming programs. If -pedantic is
|
9 |
|
|
needed to make (say) (0, 0) not be a constant expression, this is a
|
10 |
|
|
bug.
|
11 |
|
|
*/
|
12 |
|
|
|
13 |
|
|
int *a;
|
14 |
|
|
int b;
|
15 |
|
|
long *c;
|
16 |
|
|
|
17 |
|
|
#if defined(_LP64)
|
18 |
|
|
#define ZERO 0L
|
19 |
|
|
#elif defined(_WIN64)
|
20 |
|
|
#define ZERO 0LL
|
21 |
|
|
#else
|
22 |
|
|
#define ZERO 0
|
23 |
|
|
#endif
|
24 |
|
|
|
25 |
|
|
/* Assertion that n is a null pointer constant: so the conditional expression
|
26 |
|
|
has type 'int *' instead of 'void *'.
|
27 |
|
|
*/
|
28 |
|
|
#define ASSERT_NPC(n) (b = *(1 ? a : (n)))
|
29 |
|
|
/* Assertion that n is not a null pointer constant: so the conditional
|
30 |
|
|
expressions has type 'void *' instead of 'int *'.
|
31 |
|
|
*/
|
32 |
|
|
#define ASSERT_NOT_NPC(n) (c = (1 ? a : (n)))
|
33 |
|
|
|
34 |
|
|
void
|
35 |
|
|
foo (void)
|
36 |
|
|
{
|
37 |
|
|
ASSERT_NPC (0);
|
38 |
|
|
ASSERT_NPC ((void *)0);
|
39 |
|
|
ASSERT_NOT_NPC ((void *)(void *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
|
40 |
|
|
ASSERT_NOT_NPC ((void *)(char *)0); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
|
41 |
|
|
ASSERT_NOT_NPC ((void *)(0, ZERO)); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
|
42 |
|
|
ASSERT_NOT_NPC ((void *)(&"Foobar"[0] - &"Foobar"[0])); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
|
43 |
|
|
/* This last one is a null pointer constant in C99 only. */
|
44 |
|
|
ASSERT_NOT_NPC ((void *)(1 ? ZERO : (0, ZERO))); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
|
45 |
|
|
}
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.