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

Explicitly mark global variable definition as having 'undefined' value #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

heksterb
Copy link

With the code as is, global variable definitions have no initializer, producing invalid IR. For example, for the following input program to tinylang:

MODULE Point;

TYPE Point = RECORD X, Y: INTEGER END;

VAR p: Point;

PROCEDURE AssignX(a: INTEGER);
BEGIN
  p.X := a;
END AssignX;

END Point.

invoking build/tools/driver/tinylang --emit-llvm Point.mod produces this IR for the global variable definition:

@_t5Point1p = private global %Point

Attempting to process this produces an error:

$ llc Point.ll
llc: error: llc: Point.ll:10:1: error: expected value token
define void @_t5Point7AssignX(i64 %a) {
^

The simplest way to resolve this is to provide the variable with an 'undefined' initializer; now the IR reads

@_t5Point1p = private global %Point undef

which can be processed.

@OrchidRock
Copy link

OrchidRock commented Jan 9, 2023

How about use zeroinitializer instead of undef? I had pulled a PR #20 for this bug.

@heksterb
Copy link
Author

heksterb commented Jan 9, 2023

Hi @OrchidRock ; thanks for looking at this. I guess the answer to your question depends on what the semantics of global variables in 'tinylang' are, which are probably similar to those of Modula-2, which itself are probably similar to those of Pascal. I couldn't easily find any information about variable initialization in Modula-2, but in Pascal variables appear to be uninitialized (see for example freepascal.org).

Ultimately it doesn't matter so much for a toy language. and I know this isn't rock-solid evidence, but I think "uninitialized" looks like the correct answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants