summaryrefslogtreecommitdiff
path: root/test/regression/volatile2.c
blob: 3bad6ae2618bddbe467f45f1b1a02e80d8d0831f (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
39
40
41
42
43
44
45
46
47
48
49
/* Checking that __builtin_volatile_xxx functions are correctly compiled */

#include <stdio.h>

#define TEST(msg,ty,x,v1,v2) \
  *((volatile ty *) &x) = v1;                                      \
  printf("%s 1: %s\n", msg, *((ty *) &x) == v1 ? "OK" : "FAILED"); \
  *((ty *) &x) = v2;                                               \
  printf("%s 2: %s\n", msg, *((volatile ty *) &x) == v2 ? "OK" : "FAILED");

signed char gsc;
unsigned char guc;
signed short gss;
unsigned short gus;
int gi;
float gf;
double gd;
long long gll;

int main()
{
  signed char sc;
  unsigned char uc;
  signed short ss;
  unsigned short us;
  int i;
  float f;
  double d;
  long long ll;

  TEST("signed char", signed char, sc, 12, 34);
  TEST("unsigned char", unsigned char, uc, 56, 78);
  TEST("signed short", signed short, ss, 1234, 5678);
  TEST("unsigned short", unsigned short, us, 1357, 2468);
  TEST("int", int, i, 0x123456, 0x7890AB);
  TEST("float", float, f, 0.5, 256.0);
  TEST("double", double, d, 3.1415, 2.718);
  TEST("long long", long long, ll, 0x123456789ABCDEFLL, 0x789ABCDEF1234567LL);
  TEST("global signed char", signed char, gsc, 12, 34);
  TEST("global unsigned char", unsigned char, guc, 56, 78);
  TEST("global signed short", signed short, gss, 1234, 5678);
  TEST("global unsigned short", unsigned short, gus, 1357, 2468);
  TEST("global int", int, gi, 0x123456, 0x7890AB);
  TEST("global float", float, gf, 0.5, 256.0);
  TEST("global double", double, gd, 3.1415, 2.718);
  TEST("global long long", long long, gll, 0x123456789ABCDEFLL, 0x789ABCDEF1234567LL);
  return 0;
}