Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sink var/var sink both accepted; sink var leads to bad codegen and strange behavior #15671

Closed
jrfondren opened this issue Oct 21, 2020 · 0 comments
Labels
Invalid Code Acceptance Everything related to compiler not complaining about invalid code

Comments

@jrfondren
Copy link
Contributor

Example

import os

when defined(good):
  proc ex(s1: var sink TaintedString) =
    var
      a1 = s1[0].addr
      s2 = move(s1).string
    echo a1 == s2[0].addr

when defined(bad):
  proc ex(s1: sink var TaintedString) =
    var
      a1 = s1[0].addr
      s2 = move(s1).string
    echo a1 == s2[0].addr

var x = paramStr(0)
ex(x)

Current Output -d:good

true

Current Output -d:bad --gc:refc

false

Current Output -d:bad --gc:arc

/home/jfondren/nim/shadow/nc/conv3.nim(14, 20) Hint: conversion from string to itself is pointless [ConvFromXtoItselfNotNeeded]                                       
CC: conv3.nim                                                                      
/home/jfondren/.cache/nim/conv3_d/@mconv3.nim.c: In function ‘ex__NQwMCZiZiLaucv2cJhGPYw’:
/home/jfondren/.cache/nim/conv3_d/@mconv3.nim.c:124:7: error: incompatible types when assigning to type ‘NimStringV2’ from type ‘NimStringV2 *’
  124 |  s2 = s1;
      |       ^~
/home/jfondren/.cache/nim/conv3_d/@mconv3.nim.c:125:4: error: ‘s1’ is a pointer; did you mean to use ‘->’?
  125 |  s1.len = 0; s1.p = NIM_NIL;
      |    ^
      |    ->
/home/jfondren/.cache/nim/conv3_d/@mconv3.nim.c:125:16: error: ‘s1’ is a pointer; did you mean to use ‘->’?
  125 |  s1.len = 0; s1.p = NIM_NIL;
      |                ^
      |                ->
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/home/jfondren/.choosenim/toolchains/nim-1.4.0/lib -I/home/jfondren/nim/shadow/nc -o /home/jfondren/.cache/nim/conv3_d/@mconv3.nim.c.o /home/jfondren/.cache/nim/conv3_d/@mconv3.nim.c' failed with exit code: 1

Additional Information

Nim Compiler Version 1.4.0 [Linux: amd64]
Compiled at 2020-10-16
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: bdcd87afca238a0a7b2c70971827cf9172817b12
active boot switches: -d:release
@alaviss alaviss added the Invalid Code Acceptance Everything related to compiler not complaining about invalid code label Oct 21, 2020
Araq added a commit that referenced this issue Oct 23, 2020
@Araq Araq closed this as completed in d9038ed Nov 20, 2020
narimiran pushed a commit that referenced this issue Nov 20, 2020
* fixes #15671 [backport:1.4]

* progress

(cherry picked from commit d9038ed)
ringabout pushed a commit to ringabout/Nim that referenced this issue Nov 25, 2020
mildred pushed a commit to mildred/Nim that referenced this issue Jan 11, 2021
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid Code Acceptance Everything related to compiler not complaining about invalid code
Projects
None yet
Development

No branches or pull requests

2 participants