compile lvm.c as cpp code fails at 'goto condjump'

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

compile lvm.c as cpp code fails at 'goto condjump'

zerofighter
for some reason, I'm compiling lua as a single cpp code (unity builds), that is, supply a `cpp` file that include all `*.c` files of lua source code

everything's fine until the recently lua 5.3.4, the `goto condjump` (e.g. lvm.c at line 1475) cause these issue

```
lvm.c:1475:9: error: cannot jump from this goto statement to its label
    goto condjump;
lvm.c:1402:17: note: jump bypasses variable initialization
    TValue *rb = vRB(i);
```

would you please to support cpp unity builds compile method? Thanks
Reply | Threaded
Open this post in threaded view
|

Re: compile lvm.c as cpp code fails at 'goto condjump'

Paige DePol
zerofighter <[hidden email]> wrote:

> for some reason, I'm compiling lua as a single cpp code (unity builds),
> that is, supply a `cpp` file that include all `*.c` files of lua source
> code
>
> everything's fine until the recently lua 5.3.4, the `goto condjump` (e.g.
> lvm.c at line 1475) cause these issue
>
> ``` lvm.c:1475:9: error: cannot jump from this goto statement to its label
> goto condjump; lvm.c:1402:17: note: jump bypasses variable initialization
> TValue *rb = vRB(i); ```
>
> would you please to support cpp unity builds compile method? Thanks

Given the use of the vRB(i) macro it appears you have obtained the latest
development version of Lua from GitHub. The current version on GitHub, which
was very recently updated, did change the version to 5.4. However, the
previous version of the codebase was still identifying itself as 5.3.4.

You should visit http://www.lua.org/ and grab the latest release version of
Lua 5.3.4 instead of using the GitHub version. The version on GitHub is
essentially the current development path for Lua 5.4 and is subject to
change, especially as there isn't even an official release candidate yet.

~Paige


Reply | Threaded
Open this post in threaded view
|

Re: compile lvm.c as cpp code fails at 'goto condjump'

Paige DePol
In reply to this post by zerofighter
zerofighter <[hidden email]> wrote:

> for some reason, I'm compiling lua as a single cpp code (unity builds),
> that is, supply a `cpp` file that include all `*.c` files of lua source
> code
>
> would you please to support cpp unity builds compile method? Thanks

Out of curiosity, how are you creating a "unity cpp" file? Sadly, searching
for unity and cpp just gives me a ton of links about the Unity3D gaming
engine! Are you just 'cat'ing all the *.c files into a single *.cpp file and
leaving all the headers? Using Xcode I seem unable to generate the error you
have demonstrated, though I do see why the error could occur. I am curious
why it is considered an error for your build but not mine though?

At any rate, perhaps one fix might simply be to swap the entire contents of
the goto label at lines 1404-1409 with the goto statement at line 1475. This
would just move the 'condjump' logic to the OP_TEST vmcase block instead of
having it in the OP_EQ vmcase block.

Personally, I think moving the 'condjump' logic to the last vmcase block
that any goto targets reads nicer than having it be in the first block that
would use it. Also, it should remove the error regarding jumping into a
block after an uninitialised variable!

Let me know if that fixes your issue. I would test it for you but as I said
I am unable to generate the same error as you, and I am not entirely sure
what your build environment is.

~Paige


Reply | Threaded
Open this post in threaded view
|

Re: compile lvm.c as cpp code fails at 'goto condjump'

Roberto Ierusalimschy
In reply to this post by zerofighter
> for some reason, I'm compiling lua as a single cpp code (unity builds), that is, supply a `cpp` file that include all `*.c` files of lua source code
>
>
> everything's fine until the recently lua 5.3.4, the `goto condjump` (e.g. lvm.c at line 1475) cause these issue
>
>
> ```
> lvm.c:1475:9: error: cannot jump from this goto statement to its label
>     goto condjump;
> lvm.c:1402:17: note: jump bypasses variable initialization
>     TValue *rb = vRB(i);
> ```

This is probably a bug in your compiler. C does not have this restriction.
(That kind of restriction only applies to variables with a variable length
array.)

  ISO/IEC 9899:1999 (E)

  6.8.6.1 The goto statement

  Constraints

  1 The identifier in a goto statement shall name a label located
  somewhere in the enclosing function. A goto statement shall not jump
  from outside the scope of an identifier having a variably modified
  type to inside the scope of that identifier.

(Anyway, I recognize that that code is ugly; the compiler had the right
to give a warning there.)

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: compile lvm.c as cpp code fails at 'goto condjump'

Xavier Wang

Roberto Ierusalimschy <[hidden email]>于2018年1月3日 周三下午8:22写道:
> for some reason, I'm compiling lua as a single cpp code (unity builds), that is, supply a `cpp` file that include all `*.c` files of lua source code
>
>
> everything's fine until the recently lua 5.3.4, the `goto condjump` (e.g. lvm.c at line 1475) cause these issue
>
>
> ```
> lvm.c:1475:9: error: cannot jump from this goto statement to its label
>     goto condjump;
> lvm.c:1402:17: note: jump bypasses variable initialization
>     TValue *rb = vRB(i);
> ```

This is probably a bug in your compiler. C does not have this restriction.
(That kind of restriction only applies to variables with a variable length
array.)

  ISO/IEC 9899:1999 (E)

  6.8.6.1 The goto statement

  Constraints

  1 The identifier in a goto statement shall name a label located
  somewhere in the enclosing function. A goto statement shall not jump
  from outside the scope of an identifier having a variably modified
  type to inside the scope of that identifier.

(Anyway, I recognize that that code is ugly; the compiler had the right
to give a warning there.)

-- Roberto


Maybe he compiled the code in C++ mode (include codes in a cop file)? Perhaps C++ cannot do that.  A check to C++ standard possibility be needed.
--
regards,
Xavier Wang.
Reply | Threaded
Open this post in threaded view
|

Re: compile lvm.c as cpp code fails at 'goto condjump'

Paige DePol
Xavier Wang <[hidden email]> wrote:

> Roberto Ierusalimschy <[hidden email]>于2018年1月3日 周三下午8:22写道:
>> > for some reason, I'm compiling lua as a single cpp code (unity builds), that is, supply a `cpp` file that include all `*.c` files of lua source code
>> >
>> >
>> > everything's fine until the recently lua 5.3.4, the `goto condjump` (e.g. lvm.c at line 1475) cause these issue
>> >
>> >
>> > ```
>> > lvm.c:1475:9: error: cannot jump from this goto statement to its label
>> >     goto condjump;
>> > lvm.c:1402:17: note: jump bypasses variable initialization
>> >     TValue *rb = vRB(i);
>> > ```
>>
>> This is probably a bug in your compiler. C does not have this restriction.
>> (That kind of restriction only applies to variables with a variable length
>> array.)
>
> Maybe he compiled the code in C++ mode (include codes in a cop file)? Perhaps C++ cannot do that.  A check to C++ standard possibility be needed.
> --
> regards,
> Xavier Wang.

According to the specification this does appear to be the case[1]:


If transfer of control enters the scope of any automatic variables
(e.g. by jumping forward over a declaration statement), the program
is ill-formed (cannot be compiled), unless all variables whose scope
is entered have:

1) scalar types declared without initializers
2) class types with trivial default constructors and trivial destructors
   declared without initializers
3) cv-qualified versions of one of the above
4) arrays of one of the above


As the declaration of 'rb' earlier in the block is also initialised this
would violate the first rule above so the compiler aborts.

My solution in a previous message should then work as it simply moves
the logic of the goto to a block without any variable declarations.

What I am confused about is why my Xcode doesn't give me an error? Even
when I specifically tell it to compile in C++ mode, and especially as it
is an error condition and not simply a warning!

~Paige

[1] http://en.cppreference.com/w/cpp/language/goto


Reply | Threaded
Open this post in threaded view
|

Re: compile lvm.c as cpp code fails at 'goto condjump'

Paige DePol
Paige DePol <[hidden email]> wrote:

> What I am confused about is why my Xcode doesn't give me an error? Even
> when I specifically tell it to compile in C++ mode, and especially as it
> is an error condition and not simply a warning!

Well, I must have done something odd last time, or a cache didn't clear,
because I tried to compile the GitHub version of Lua in C++ mode again
and this time I do get the same error as the thread creator.

Moving the goto logic down to the OP_TEST vmcase block does fix the error.

~Paige


Reply | Threaded
Open this post in threaded view
|

Re: compile lvm.c as cpp code fails at 'goto condjump'

Matthias Kluwe
Hi!

2018-01-06 0:37 GMT+01:00 Paige DePol <[hidden email]>:

> Paige DePol <[hidden email]> wrote:
>
> > What I am confused about is why my Xcode doesn't give me an error?
> > Even
> > when I specifically tell it to compile in C++ mode, and especially
> > as it
> > is an error condition and not simply a warning!
>
> Well, I must have done something odd last time, or a cache didn't
> clear,
> because I tried to compile the GitHub version of Lua in C++ mode
> again
> and this time I do get the same error as the thread creator.
>
> Moving the goto logic down to the OP_TEST vmcase block does fix the
> error.

As `*rb` is not used after the `condjump` label, I "fixed" this by
enclosing `*rb` in a small scope to get C++ compatability:

    vmcase(OP_EQ) {
      {
      TValue *rb = vRB(i);
      Protect(cond = luaV_equalobj(L, vra, rb));
      }
    condjump:

Regards,
Matthias