summary refs log tree commit diff stats
path: root/tests/pragmas/tpush.nim
blob: a505bb32f1041918a3d98c3ddf6ce73aa5dae257 (plain) (blame)
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
127
128
129
130
131
132
discard """
  targets: "c js"
"""

# test the new pragmas

{.push warnings: off, hints: off.}
proc noWarning() =
  var
    x: int
  echo(x)

{.pop.}

proc WarnMe() =
  var
    x: int
  echo(x)

# bug #11852
proc foo(x: string, y: int, res: int) =
  {.push checks: off}
  var a: ptr char = unsafeAddr(x[y])
  {.pop.}
  if x.len > y:
    doAssert ord(a[]) == 51
  else:
    doAssert x.len + 48 == res

foo("", 0, 48)
foo("abc", 40, 51)

# bug #22362
{.push staticBoundChecks: on.}
proc main(): void =
  {.pop.}
  discard
  {.push staticBoundChecks: on.}

main()


proc timnFoo[T](obj: T) {.noSideEffect.} = discard # BUG

{.push exportc.}
proc foo1() =
  var s1 = "bar"
  timnFoo(s1)
  var s2 = @[1]
  timnFoo(s2)
{.pop.}


block: # bug #22913
  block:
    type r = object

    template std[T](x: T) =
      let ttt {.used.} = x
      result = $ttt

    proc bar[T](x: T): string =
      std(x)

    {.push exportc: "$1".}
    proc foo(): r =
      let s = bar(123)
    {.pop.}

    discard foo()

  block:
    type r = object
    {.push exportc: "$1".}
    proc foo2(): r =
      let s = $result
    {.pop.}

    discard foo2()

block: # bug #23019
  proc f(x: bool)

  proc a(x: int) =
    if false: f(true)

  proc f(x: bool) =
    if false: a(0)

  proc k(r: int|int) {.inline.} =  # seems to require being generic and inline
    if false: a(0)


  # {.push tags: [].}
  {.push raises: [].}

  {.push warning[ObservableStores]:off.}  # can be any warning, off or on
  let w = 0
  k(w)
  {.pop.}
  {.pop.}

{.push exportC.}

block:
  proc foo11() =
    const factor = [1, 2, 3, 4]
    doAssert factor[0] == 1
  proc foo21() =
    const factor = [1, 2, 3, 4]
    doAssert factor[0] == 1

  foo11()
  foo21()

template foo31() =
  let factor = [1, 2, 3, 4]
  doAssert factor[0] == 1
template foo41() =
  let factor = [1, 2, 3, 4]
  doAssert factor[0] == 1

foo31()
foo41()

{.pop.}

block:
  {.push deprecated.}
  template test() = discard
  test()
  {.pop.}