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

[CIR][CodeGen] support array def after decl with unknown bound #375

Merged
merged 2 commits into from
Jan 9, 2024

Conversation

Lancern
Copy link
Collaborator

@Lancern Lancern commented Dec 31, 2023

Arrays can be first declared without a known bound, and then defined with a known bound. For example:

extern int data[];

int test() { return data[1]; }

int data[3] {1, 2, 3};

Currently clangir crashes on generating CIR for this case. This is due to the type of the data definition being different from its declaration. This patch adds support for such a case.

@bcardosolopes
Copy link
Member

Thanks for your recent PRs, I'm currently on vacation but should resume reviewing patches by next Wed. Cheers.

Arrays can be first declared without a known bound, and then defined
with a known bound. clangir crashes on generating CIR for this case.
This patch adds support.
Copy link
Collaborator

@sitio-couto sitio-couto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Lancern, thanks for the contribution!

It seems that this patch is solving a different assertion than the one triggered by the example provided in the PR description. This is possible because the new isValidRedeclarationType(Entry.getSymType(), Ty) statement evaluates to true, effectively changing the code path for the example code. In the original codegen, this evaluates to false.

This is the assertion causing the crash:

assert(!Entry && "not implemented");

I would suggest trying to update these changes to fix this assertion instead.

@@ -546,7 +574,7 @@ CIRGenModule::getOrCreateCIRGlobal(StringRef MangledName, mlir::Type Ty,
assert(0 && "not implemented");

// TODO(cir): check TargetAS matches Entry address space
if (Entry.getSymType() == Ty &&
if (isValidRedeclarationType(Entry.getSymType(), Ty) &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this diverges from the original codegen. The Entry.getSymType() == Ty statement should be evaluated as false.

Comment on lines 938 to 946
if (!GV || GV.getSymType() != InitType) {
// TODO(cir): this should include an address space check as well.
assert(0 && "not implemented");
setTypeOfGlobal(GV, InitType);
}
Copy link
Collaborator

@sitio-couto sitio-couto Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oddly, the counterpart for this code section is not executed in the original codegen for the example in the PR description, despite the comment indicating otherwise.

@Lancern
Copy link
Collaborator Author

Lancern commented Jan 4, 2024

@sitio-couto Thanks for your helpful review! I have updated the code according to the review.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reflecting the state from @sitio-couto review.

Copy link
Collaborator

@sitio-couto sitio-couto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Lancern Lancern force-pushed the array-decl-unknown-bound branch 2 times, most recently from 2bca2f4 to 5edd5ce Compare January 8, 2024 14:22
@bcardosolopes bcardosolopes merged commit 3d25ba9 into llvm:main Jan 9, 2024
6 checks passed
@Lancern Lancern deleted the array-decl-unknown-bound branch January 10, 2024 12:43
lanza pushed a commit that referenced this pull request Jan 29, 2024
Arrays can be first declared without a known bound, and then defined
with a known bound. For example:

```cpp
extern int data[];

int test() { return data[1]; }

int data[3] {1, 2, 3};
```

Currently `clangir` crashes on generating CIR for this case. This is due
to the type of the `data` definition being different from its
declaration. This patch adds support for such a case.
lanza pushed a commit that referenced this pull request Mar 23, 2024
Arrays can be first declared without a known bound, and then defined
with a known bound. For example:

```cpp
extern int data[];

int test() { return data[1]; }

int data[3] {1, 2, 3};
```

Currently `clangir` crashes on generating CIR for this case. This is due
to the type of the `data` definition being different from its
declaration. This patch adds support for such a case.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
Arrays can be first declared without a known bound, and then defined
with a known bound. For example:

```cpp
extern int data[];

int test() { return data[1]; }

int data[3] {1, 2, 3};
```

Currently `clangir` crashes on generating CIR for this case. This is due
to the type of the `data` definition being different from its
declaration. This patch adds support for such a case.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
Arrays can be first declared without a known bound, and then defined
with a known bound. For example:

```cpp
extern int data[];

int test() { return data[1]; }

int data[3] {1, 2, 3};
```

Currently `clangir` crashes on generating CIR for this case. This is due
to the type of the `data` definition being different from its
declaration. This patch adds support for such a case.
lanza pushed a commit that referenced this pull request Apr 29, 2024
Arrays can be first declared without a known bound, and then defined
with a known bound. For example:

```cpp
extern int data[];

int test() { return data[1]; }

int data[3] {1, 2, 3};
```

Currently `clangir` crashes on generating CIR for this case. This is due
to the type of the `data` definition being different from its
declaration. This patch adds support for such a case.
lanza pushed a commit that referenced this pull request Apr 29, 2024
Arrays can be first declared without a known bound, and then defined
with a known bound. For example:

```cpp
extern int data[];

int test() { return data[1]; }

int data[3] {1, 2, 3};
```

Currently `clangir` crashes on generating CIR for this case. This is due
to the type of the `data` definition being different from its
declaration. This patch adds support for such a case.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Apr 29, 2024
Arrays can be first declared without a known bound, and then defined
with a known bound. For example:

```cpp
extern int data[];

int test() { return data[1]; }

int data[3] {1, 2, 3};
```

Currently `clangir` crashes on generating CIR for this case. This is due
to the type of the `data` definition being different from its
declaration. This patch adds support for such a case.
lanza pushed a commit that referenced this pull request Apr 29, 2024
Arrays can be first declared without a known bound, and then defined
with a known bound. For example:

```cpp
extern int data[];

int test() { return data[1]; }

int data[3] {1, 2, 3};
```

Currently `clangir` crashes on generating CIR for this case. This is due
to the type of the `data` definition being different from its
declaration. This patch adds support for such a case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants