Code gen: Casted pointer offets #140

Closed
opened 2023-07-10 14:09:47 +01:00 by deavmi · 4 comments
Owner

What is this?

C compiler's do this thing where: if <a> is a pointer and <b> is an integer then the following pointer arithmetic is allowed:

int* a = (int*)2;
a = a + b;

But it's WRONG if you do:

a = a + (int*)b;

Even though it makes logical sense coercion wise. Therefore we need to check such a case and yank the cast out me thinks.

## What is this? C compiler's do this thing where: if `<a>` is a pointer and `<b>` is an integer then the following pointer arithmetic is allowed: ```c int* a = (int*)2; a = a + b; ``` **But** it's WRONG if you do: ```c a = a + (int*)b; ``` Even though it makes logical sense coercion wise. Therefore we need to check such a case and yank the cast out me thinks.
deavmi added this to the Basics milestone 2023-07-10 14:09:47 +01:00
deavmi added the
emit
label 2023-07-10 14:09:47 +01:00
deavmi self-assigned this 2023-07-10 14:09:47 +01:00
deavmi added this to the Code emit project 2023-07-10 14:09:47 +01:00
deavmi added a new dependency 2023-07-10 14:10:07 +01:00
Author
Owner

This is being worked on as part of #115

This is being worked on as part of #115
deavmi started working 2023-07-10 15:08:11 +01:00
deavmi stopped working 2023-07-10 15:08:14 +01:00
3 seconds
deavmi added spent time 2023-07-10 15:08:21 +01:00
10 minutes
deavmi started working 2023-07-10 15:08:23 +01:00
Author
Owner

In commit 29d7cb7451b02ea6ab1ae736ede0e3094ca0d00d (and prior):

  1. Added "relaxation" support to CastedValueInstruction
  2. DGen now respects the CastedValueInstruction's relaxation
  3. DGen now also sets the "relaxation" flag when one of the operands of a BinaryOpInstr is a Pointer, the assumption is that TypeChecker would have coerced the non-pointer operseand to a CastedValueInstruction
In commit `29d7cb7451b02ea6ab1ae736ede0e3094ca0d00d` (and prior): 1. Added "relaxation" support to `CastedValueInstruction` 2. DGen now respects the `CastedValueInstruction`'s relaxation 3. DGen now also sets the "relaxation" flag when one of the operands of a `BinaryOpInstr` is a `Pointer`, the assumption is that `TypeChecker` would have coerced the non-pointer operseand to a `CastedValueInstruction`
deavmi stopped working 2023-07-10 15:12:10 +01:00
3 minutes 47 seconds
deavmi started working 2023-07-10 15:13:28 +01:00
deavmi stopped working 2023-07-10 15:13:31 +01:00
3 seconds
deavmi added the due date 2023-07-12 2023-07-10 20:22:52 +01:00
deavmi started working 2023-07-11 08:56:00 +01:00
Author
Owner

Marking this as closed for now as it seems correct

Marking this as closed **for now** as it seems correct
deavmi stopped working 2023-07-11 08:56:23 +01:00
23 seconds
deavmi reopened this issue 2023-07-11 08:57:24 +01:00
deavmi started working 2023-07-11 08:57:27 +01:00
Author
Owner

Made debug messages better for when this is used in DGen in commit a342fdcb93efb76272d5684cdf216e5e0a6122d1

Made debug messages better for when this is used in `DGen` in commit `a342fdcb93efb76272d5684cdf216e5e0a6122d1`
deavmi stopped working 2023-07-11 08:57:55 +01:00
28 seconds
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Total Time Spent: 14 minutes 44 seconds
deavmi
14 minutes 44 seconds
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

2023-07-12

Reference: tlang/tlang#140
No description provided.