Skip to content

zig cc array-bound check is not clear #23350

Closed
@otaviocozer

Description

@otaviocozer

Zig Version

0.13.0

Steps to Reproduce and Observed Output

Compile the program below using zig cc:

//test.c
int main() {
  int arr[5] = {1, 2, 3, 4, 5};
  int* dest = arr+6-(6*1);
  (void)dest;
  return 0;
}

Then run it and it shows the message: Illegal instruction (core dumped). After investigating I found out that this happens because an array bound check. When I compile the same code using clang -fsanitize=array-bounds test.c , I get the error: test.c:3:18: runtime error: index 6 out of bounds for type 'int[5]' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior test.c:3:18 in . I'm linking the verbose message of zig cc for detailed information.

zig_cc_verbose.txt

Expected Output

test.c:3:18: runtime error: index 6 out of bounds for type 'int[5]' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior test.c:3:18 in

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messageThis issue points out an error message that is unhelpful and should be improved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions