diff options
author | flywind <43030857+xflywind@users.noreply.github.com> | 2020-11-18 01:05:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-17 17:05:20 +0000 |
commit | 0f7f159a35bc10a43ff15bcb6c20eefdc574138e (patch) | |
tree | a39632747534bfdd5bc0a74919e11c23bb65f56e | |
parent | fec19c980e36e62747eb119f0740cb785e858ac3 (diff) | |
download | Nim-0f7f159a35bc10a43ff15bcb6c20eefdc574138e.tar.gz |
fix #15623 (#16009)
* fix #15623 * add testcase for #15623 * fix * add testcase
-rw-r--r-- | compiler/semfold.nim | 2 | ||||
-rw-r--r-- | lib/posix/posix_linux_amd64_consts.nim | 2 | ||||
-rw-r--r-- | tests/ccgbugs/t15623.nim | 11 | ||||
-rw-r--r-- | tests/ccgbugs/t15623_2.nim | 13 |
4 files changed, 26 insertions, 2 deletions
diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 9b21c5fa3..f38359a64 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -674,7 +674,7 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode of nkCast: var a = getConstExpr(m, n[1], idgen, g) if a == nil: return - if n.typ != nil and n.typ.kind in NilableTypes: + if n.typ != nil and n.typ.kind in NilableTypes and a.kind != nkNilLit: # we allow compile-time 'cast' for pointer types: result = a result.typ = n.typ diff --git a/lib/posix/posix_linux_amd64_consts.nim b/lib/posix/posix_linux_amd64_consts.nim index f3230f71d..917c1f966 100644 --- a/lib/posix/posix_linux_amd64_consts.nim +++ b/lib/posix/posix_linux_amd64_consts.nim @@ -365,7 +365,7 @@ const SCHED_RR* = cint(2) const SCHED_OTHER* = cint(0) # <semaphore.h> -const SEM_FAILED* = cast[pointer]((nil)) +const SEM_FAILED* = nil # <signal.h> const SIGEV_NONE* = cint(1) diff --git a/tests/ccgbugs/t15623.nim b/tests/ccgbugs/t15623.nim new file mode 100644 index 000000000..c8246c85b --- /dev/null +++ b/tests/ccgbugs/t15623.nim @@ -0,0 +1,11 @@ +discard """ + action: "compile" +""" + +# bug #15623 +block: + echo cast[ptr int](nil)[] + +block: + var x: ref int = nil + echo cast[ptr int](x)[] diff --git a/tests/ccgbugs/t15623_2.nim b/tests/ccgbugs/t15623_2.nim new file mode 100644 index 000000000..4f33bc745 --- /dev/null +++ b/tests/ccgbugs/t15623_2.nim @@ -0,0 +1,13 @@ +discard """ + output: '''0 +0 +''' +""" + +# bug #15623 +block: + echo cast[int](cast[ptr int](nil)) + +block: + var x: ref int = nil + echo cast[int](cast[ptr int](x)) |