Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Lack of Dereference of null pointer, at compile time #2215

@Salc-wm

Description

@Salc-wm

Lack of Dereference of null pointer

When I try to assign a null value to a pointer with type any, a null dereference error should occur after trying to get its type.

This normally happens at runtime, but for some reason when it happens
at compile time, it fails to compile correctly and indicates the problem.

Problem in question:

Compiler encountered an unexpected error: "Violated assert: !LLVMConstIntGetZExtValue(value->value) && "Unexpected bounds check failed."".

- Function: llvm_emit_panic_if_true(...)
- Source file: D:\a\c3c\c3c\src\compiler\llvm_codegen_stmt.c:1599'

Expected ->

ERROR: 'Dereference of null pointer, 'value' was null.'

Or just Typeid!

anyway I don't know if the default behavior was really to print typeid as a response

Code that causes this...

macro void test(any *value = null)
{ 
   io::printn(value.type);  // >> Violated assert
}

The other tests go smoothly.

fn void test(any *value = null)
{
    io::printn(value.type);  // >> ERROR: 'Dereference of null pointer, 'value' was null.'
}
macro void test(any $value = null)
{
    io::printn($value.type);  // >> typeid
}

Problem is in the pointer and the macro, when he receives null
if it has a value assigned that is not null, it will return an error in the correct way
$ # doesn't matter, it happens anyway if they are in the scope of the function
$ If the variable is assigned to the function scope, the Violated assert occurs

macro void test()
{
    any *$value;
    io::printn($value.type);  // -> Violated assert
}

If it is not explicitly stated that it is not at compile time, the error is triggered without any problem.

macro void test()
{
    any *value;
    io::printn(value.type);  // -> Dereference of null
}

but it is only triggered if the value verification occurs

Metadata

Metadata

Assignees

Labels

BugSomething isn't workingFixed needs testingNeeds verification / testing that it now works

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions