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

Dereferencing a hardcoded address pointer declared as const on RHS creates compile error: "unreachable: ir.cpp:const_ptr_pointee" #1171

Closed
vegecode opened this Issue Jun 29, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@vegecode
Copy link
Contributor

vegecode commented Jun 29, 2018

const myP = @intToPtr(*u16, 0x2300);

pub fn main() void {
  myP.* = myP.* | 10;
}

This causes a compiler crash. With --verbose-ir:

{
    myP.* = (myP.* | 10);
}
{ // (IR)
Entry_0:
    #1  | (unknown)   | 1 | declref ptr myP
    #2  | (unknown)   | 1 | * #1
    #3  | (unknown)   | 1 | declref myP
    #4  | (unknown)   | 1 | * #3
    #5  | comptime_int| 1 | 10
    #6  | (unknown)   | 1 | #4 | 10
    #7  | void        | - | *#2 = #6
    #8  | void        | 1 | {}
    #9  | (unknown)   | - | @checkStatementIsVoid({})
    #10 | void        | 0 | {}
    #11 | void        | 2 | {}
    #12 | (unknown)   | - | @addImplicitReturnType({})
    #13 | noreturn    | - | return {}
}

Source: @intToPtr(*u16, 8960)
{ // (IR)
Entry_0:
    #1  | type        | 1 | u16
    #2  | (unknown)   | - | &:0:0 u16
    #3  | comptime_int| 1 | 8960
    #4  | (unknown)   | 2 | @intToPtr(#2,8960)
    #5  | (unknown)   | - | @addImplicitReturnType(#4)
    #6  | noreturn    | - | return #4
}
{ // (analyzed)
Entry_0:
    #7  | noreturn    | - | return (*u16)(2300)
}
unreachable: /home/justin/Code/Zig/zig/src/ir.cpp:const_ptr_pointee:166

The intended usage is for writing to memory mapped registers.

@vegecode vegecode changed the title Dereferencing a pointer twice in same line causes "unreachable: const Dereferencing a pointer twice in same line causes "unreachable: ir.cpp:const_ptr_pointee" on failed build Jun 29, 2018

@vegecode vegecode changed the title Dereferencing a pointer twice in same line causes "unreachable: ir.cpp:const_ptr_pointee" on failed build Dereferencing a hardcoded address pointer twice in same line causes "unreachable: ir.cpp:const_ptr_pointee" on failed build Jun 29, 2018

@andrewrk andrewrk added this to the 0.3.0 milestone Jun 29, 2018

@andrewrk andrewrk added the bug label Jun 29, 2018

@vegecode

This comment has been minimized.

Copy link
Contributor Author

vegecode commented Jun 30, 2018

Dereferencing the const pointer at all on the RHS makes an error:

const myP = @intToPtr(*volatile u16, 0x340);
const assert = @import("std").debug.assert;

pub fn main() void {
  assert(@typeOf(myP) == *volatile u16); // good
  assert(@typeOf(myP.*) == u16); // causes error
  var temp = myP.*; // also causes error
}

If the myP is declared as var instead it compiles fine but the --verbose-ir shows an error:
bigint.cpp:1633: uint64_t bigint_as_unsigned(const BigInt*): Assertion !bigint->is_negative' failed.`

@vegecode vegecode changed the title Dereferencing a hardcoded address pointer twice in same line causes "unreachable: ir.cpp:const_ptr_pointee" on failed build Dereferencing a hardcoded address pointer declared as const on RHS creates compile error: "unreachable: ir.cpp:const_ptr_pointee" Jun 30, 2018

@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Sep 3, 2018

andrewrk added a commit that referenced this issue Jan 4, 2019

Mark comptime int hardcoded address pointee as a run time variable #1171
 (#1868)

* Mark comptime int hardcoded address as a run time variable #1171

* test case for dereferencing hardcoded address intToPtr
@andrewrk

This comment has been minimized.

Copy link
Member

andrewrk commented Jan 4, 2019

Fixed by @vegecode in 1f08be4

@andrewrk andrewrk closed this Jan 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.