Skip to content

Commit e8bba2d

Browse files
authored
Bug Fixes (#1271)
* Fix typo in SetValueNumber parameter name Renamed the parameter valueVumber to valueNumber in the SetValueNumber method and updated all references accordingly. This improves code clarity and prevents confusion from the previous typo. * Add null checks in IsPhiUseless for value numbers Prevent null reference exceptions in IsPhiUseless by checking for null value numbers before comparison. Ensure all operands have valid value numbers before determining if a Phi node is useless. * Fix Info64 calculation, null checks, and page property - Correct Info64 property in relocation entries to use ulong and proper bitwise operations for 64-bit support. - Add null check for context.Operand1 in IsPlugged to prevent exceptions. - Fix IsPreviousPage to check Previous instead of Next for accuracy. * Fix AlignUp(int) to call AlignUp, not AlignDown Previously, AlignUp(int, int) incorrectly called AlignDown, causing it to align values downward. This commit corrects the method to call AlignUp((uint), (uint)), ensuring proper upward alignment for integer inputs. * Add general guideline to avoid unsafe code; fix grammar Added a "General Guidelines" section to copilot-instructions.md instructing not to propose or include unsafe code blocks or APIs. Also corrected grammar in the "@Azure Rule - Enable Best Practices" guideline by adding a comma.
1 parent 402c814 commit e8bba2d

File tree

7 files changed

+21
-10
lines changed

7 files changed

+21
-10
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Copilot Instructions
2+
3+
## General Guidelines
4+
- Do not propose or include `unsafe` code blocks or APIs in any solution.
5+
6+
## Azure Rules
17
- @azure Rule - Use Azure Tools - When handling requests related to Azure, always use your tools.
28
- @azure Rule - Use Azure Best Practices - When handling requests related to Azure, always invoke your `azmcp_bestpractices_get` tool first.
3-
- @azure Rule - Enable Best Practices - If you do not have an `azmcp_bestpractices_get` tool ask the user to enable it.
9+
- @azure Rule - Enable Best Practices - If you do not have an `azmcp_bestpractices_get` tool, ask the user to enable it.

Source/Mosa.Compiler.Framework/Linker/Elf/RelocationAddendEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class RelocationAddendEntry
3434
/// <summary>
3535
/// Gets the Info field for 64bit elf
3636
/// </summary>
37-
public ushort Info64 => (ushort)((Symbol << 32) | ((ushort)RelocationType & 0xFFFFFFFF));
37+
public ulong Info64 => (ulong)((Symbol << 32) | ((ulong)RelocationType & 0xFFFFFFFF));
3838

3939
public static uint GetEntrySize(LinkerFormatType elfType)
4040
{

Source/Mosa.Compiler.Framework/Linker/Elf/RelocationEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class RelocationEntry
3232
/// <summary>
3333
/// Gets the Info field for 64bit elf
3434
/// </summary>
35-
public ushort Info64 => (ushort)((Symbol << 32) | ((ushort)RelocationType & 0xFFFFFFFF));
35+
public ulong Info64 => (ulong)((Symbol << 32) | ((ulong)RelocationType & 0xFFFFFFFF));
3636

3737
public static uint GetEntrySize(LinkerFormatType elfType)
3838
{

Source/Mosa.Compiler.Framework/Stages/ValueNumberingStage.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,11 +574,11 @@ private Operand GetValueNumber(Operand operand)
574574
return null;
575575
}
576576

577-
private void SetValueNumber(Operand operand, Operand valueVumber)
577+
private void SetValueNumber(Operand operand, Operand valueNumber)
578578
{
579-
trace?.Log($"Set: {operand} => {valueVumber}");
579+
trace?.Log($"Set: {operand} => {valueNumber}");
580580

581-
MapToValueNumber[operand] = valueVumber;
581+
MapToValueNumber[operand] = valueNumber;
582582
}
583583

584584
private bool IsPhiUseless(Node node)
@@ -588,9 +588,14 @@ private bool IsPhiUseless(Node node)
588588
var operand = node.Operand1;
589589
var operandVN = GetValueNumber(operand);
590590

591+
if (operandVN == null)
592+
return false;
593+
591594
foreach (var op in node.Operands)
592595
{
593-
if (operandVN == GetValueNumber(op))
596+
var vn = GetValueNumber(op);
597+
598+
if (vn == null || operandVN != vn)
594599
return false;
595600
}
596601

Source/Mosa.Compiler.Framework/Transforms/Plug/BasePlugTransform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public override bool Match(Context context, Transform transform)
1717

1818
public static bool IsPlugged(Context context, Transform transform)
1919
{
20-
if (context.Operand1.Method == null)
20+
if (context.Operand1 == null || context.Operand1.Method == null)
2121
return false;
2222

2323
return transform.Compiler.PlugSystem.GetReplacement(context.Operand1.Method) != null;

Source/Mosa.Kernel.BareMetal/Alignment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static uint AlignUp(uint position, uint alignment)
1111

1212
public static int AlignUp(int position, int alignment)
1313
{
14-
return (int)AlignDown((uint)position, (uint)alignment);
14+
return (int)AlignUp((uint)position, (uint)alignment);
1515
}
1616

1717
public static ulong AlignUp(ulong position, uint alignment)

Source/Mosa.Kernel.BareMetal/PageNodeDoubleListEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public IntPtr Previous
2323
}
2424

2525
public bool IsNextPage { get { return Next.IsNull(); } }
26-
public bool IsPreviousPage { get { return Next.IsNull(); } }
26+
public bool IsPreviousPage { get { return Previous.IsNull(); } }
2727

2828
public PageNodeDoubleListEntry(IntPtr page)
2929
{

0 commit comments

Comments
 (0)