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

Crash/LLVM error mixing runtime and comptime code (maybe?) #1462

Closed
ghost opened this issue Sep 3, 2018 · 1 comment
Closed

Crash/LLVM error mixing runtime and comptime code (maybe?) #1462

ghost opened this issue Sep 3, 2018 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@ghost
Copy link

ghost commented Sep 3, 2018

Here is some code which can crash in several ways. It depends on which field(s) in the SystemData struct are optional. If the second field is optional, but the first isn't, I get this:

Entry block to function must not have predecessors!
label %Entry
LLVM ERROR: Broken module found, compilation aborted!
The following command exited with error code 1:
zig test /home/dbandstra/oxid/test.zig --library c 

If the other field is optional instead, or if both are optional, I get a crash with no error message (probably a straight crash, not failed assert). If neither field is optional, it doesn't crash.

See comments where I've noted code that can be removed to dodge the crash.

const builtin = @import("builtin");

const ComponentA = struct{ unused: u32 };
const ComponentB = struct{ unused: u32 };
const SystemData = struct{
  a: *ComponentA,
  b: ?*ComponentB,
};

test "" {
  // if this variable is `comptime`, it works (this is actually what I should be doing)
  var all_fields_optional = true;

  inline for (@typeInfo(SystemData).Struct.fields) |field| {
    if (@typeId(field.field_type) == builtin.TypeId.Optional) {
      all_fields_optional = false;
    }
  }

  inline for (@typeInfo(SystemData).Struct.fields) |field| {
    // if `and !all_fields_optional` is removed, it works
    if (@typeId(field.field_type) == builtin.TypeId.Optional and !all_fields_optional) {
      continue;
    }
    // ...
  }
}
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Sep 3, 2018
@andrewrk andrewrk added this to the 0.3.0 milestone Sep 3, 2018
@andrewrk
Copy link
Member

andrewrk commented Sep 4, 2018

This was the same as #834, fixed by 68db9d5

@andrewrk andrewrk closed this as completed Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

1 participant