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

C++ codegen regression: memset called on a result variable of importcpp type #5140

Closed
nigredo-tori opened this issue Dec 22, 2016 · 5 comments

Comments

@nigredo-tori
Copy link
Contributor

nigredo-tori commented Dec 22, 2016

Reduced example:

{.emit:"""
#import <cassert>

template <typename X> class C {
  public:
    int d;

    C(): d(1) { }

    C<X>& operator=(const C<X> other) {
      assert(d == 1);
    }
};
""".}

type C{.importcpp, header: "<stdio.h>", nodecl.} [X] = object
proc mkC[X]: C[X] {.importcpp: "C<'*0>()", constructor, nodecl.}

proc foo(): C[int] =
  result = mkC[int]()

discard foo()

The assertion fails, because the generated code for foo looks like this:

C<NI>  result0;
nimfr("foo", "test_default_constructor.nim")
memset((void*)(&result0), 0, sizeof(result0));
nimln(20, "test_default_constructor.nim");
result0 = C<NI>();
popFrame();
return result0;

This memset breaks use cases relying on default constructor (in my case this was QList).

Tested on: 80f9dcc
Bisect points to: 860cbd3

@Araq Araq closed this as completed in 0ef6815 Dec 22, 2016
philip-wernersbach added a commit to philip-wernersbach/nim-qt5_qtsql that referenced this issue Jun 15, 2017
philip-wernersbach added a commit to philip-wernersbach/influx-mysql that referenced this issue Jun 15, 2017
1.0.3. This fixes a SEGFAULT when generating time objects.
@philip-wernersbach
Copy link
Contributor

This should be reopened, this regressed in 0.17.0.

@Yardanico
Copy link
Collaborator

@philip-wernersbach I don't have any error messages after running this example on Arch Linux with latest gcc and latest nim devel

@Yardanico
Copy link
Collaborator

[root@tiberium ~]# nim cpp test.nim
Hint: used config file '/root/.choosenim/toolchains/nim-#devel/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
CC: test
CC: stdlib_system
Hint:  [Link]
Hint: operation successful (10912 lines compiled; 5.415 sec total; 17.938MiB peakmem; Debug Build) [SuccessX]
[root@tiberium ~]# ./test
[root@tiberium ~]#

@Araq Araq reopened this Jun 15, 2017
philip-wernersbach added a commit to philip-wernersbach/nim-qt5_qtsql that referenced this issue Jun 30, 2017
nim-lang/Nim#5140, disabling automatic conversions of Qt types to
Nim types.
philip-wernersbach added a commit to philip-wernersbach/nim-qt5_qtsql that referenced this issue Jun 30, 2017
nim-lang/Nim#5140, disabling automatic conversions of Qt types to
Nim types.
@Yardanico
Copy link
Collaborator

Can this be closed?

@Araq
Copy link
Member

Araq commented Oct 16, 2017

The example program continues to compile. Please open a new bug with a new snippet that fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants