File: attr-mode-enums.c

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (45 lines) | stat: -rw-r--r-- 1,406 bytes parent folder | download | duplicates (12)
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
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s

// Test checks that 'mode' attribute is handled correctly with enums, i. e. code
//   1. "typedef enum { A } __attribute__((mode(HI))) T;" is accepted,
//   2. "enum X __attribute__((mode(QI))) var;" forms a complete integer type.

int main(void) {
  // CHECK: [[X1:%.+]] = alloca i8
  enum { A1, B1 } __attribute__((mode(QI))) x1 = A1;

  // CHECK: [[X2:%.+]] = alloca i16
  enum { A2, B2 } x2 __attribute__((mode(HI))) = B2;

  // CHECK: [[X3:%.+]] = alloca i32
  typedef enum { A3, B3 } __attribute__((mode(SI))) T3;
  T3 x3 = A3;

  // CHECK: [[X4:%.+]] = alloca i64
  typedef enum { A4, B4 } T4 __attribute__((mode(DI)));
  T4 x4 = B4;

  // CHECK: [[X5:%.+]] = alloca i8
  typedef enum __attribute__((mode(QI))) { A5, B5 } T5;
  T5 x5 = A5;

  // CHECK: [[X6:%.+]] = alloca i8
  typedef enum X __attribute__((mode(QI))) T6;
  T6 x6;

  // CHECK: [[X7:%.+]] = alloca i128
  enum { A7, B7 } __attribute__((mode(TI))) x7 = A7;

  // CHECK: [[X8:%.+]] = alloca i8
  enum __attribute__((mode(QI))) { A8, B8 } x8 = B8;

  // CHECK: store i8 0, ptr [[X1]]
  // CHECK: store i16 1, ptr [[X2]]
  // CHECK: store i32 0, ptr [[X3]]
  // CHECK: store i64 1, ptr [[X4]]
  // CHECK: store i8 0, ptr [[X5]]
  // CHECK: store i128 0, ptr [[X7]]
  // CHECK: store i8 1, ptr [[X8]]

  return x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8;
}