Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 2 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ csharp_style_prefer_null_check_over_type_check = true:error
csharp_prefer_simple_default_expression = true:error
csharp_space_between_method_declaration_parameter_list_parentheses = true
csharp_space_between_method_declaration_empty_parameter_list_parentheses = true
dotnet_diagnostic.SA0001.severity = none
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
dotnet_diagnostic.SA0001.severity = none
dotnet_diagnostic.SA1135.severity = none

# Analysis and refactoring rules for Ubiquity.NET
# Description: Code analysis rules for Ubiquity.NET projects
Expand Down Expand Up @@ -1254,8 +1255,6 @@ dotnet_diagnostic.RECS0147.severity = warning

dotnet_diagnostic.RECS0154.severity = suggestion

dotnet_diagnostic.SA0001.severity = silent

dotnet_diagnostic.SA1000.severity = none

dotnet_diagnostic.SA1001.severity = none
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0

- name: Build Source
run: ./Build-All.ps1 -ForceClean -BuildMode Source
Expand Down
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<PropertyGroup>
<CodeAnalysisIgnoreGeneratedCode>true</CodeAnalysisIgnoreGeneratedCode>
<Determenistic>true</Determenistic>
<Nullable>enable</Nullable>
<Nullable Condition="$(Nullable)=='' AND '$(UsingMicrosoftNETSdk)'=='true'">enable</Nullable>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<!--
Expand All @@ -76,9 +76,9 @@
<ImplicitUsings>disable</ImplicitUsings>
<!-- NOTE: Top-Level statements blocked as an error in .editorconfig and ImplicitUsings 'feature' VERIFIED in the targets file -->
</PropertyGroup>
<!--<ItemGroup Condition="'$(NoCommonAnalyzers)'!='true'">
<ItemGroup Condition="'$(NoCommonAnalyzers)'!='true'">
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
</ItemGroup>-->
</ItemGroup>
</When>
<When Condition="'$(MSBuildProjectExtension)'=='.vcxproj'">
<!-- vcxproj uses a different pattern for output paths -->
Expand Down
25 changes: 10 additions & 15 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,30 @@
Global references are included in ALL projects in this repository
-->
<ItemGroup>
<GlobalPackageReference Include="CSemVer.Build.Tasks" Version="2.0.5" />
<GlobalPackageReference Include="Ubiquity.NET.Versioning.Build.Tasks" Version="5.0.0-rc" />
<GlobalPackageReference Include="IDisposableAnalyzers" Version="4.0.8" Condition="'$(NoCommonAnalyzers)' !=' true'" />
<GlobalPackageReference Include="MustUseRetVal" Version="0.0.2" />
<!--
While some aspects of this analyzer are helpful, it hasn't been without issues. Worse, the last non-preview release
was Apr of 2019, That's a LONG time ago. Even the most recent preview (beta) was back in Dec. of 2023. So not much
sign of life/activity nor hope of updates to bug fixes. It's sad to see this go as relying on a developer/reviewers
to follow the rules is a recipe for failures. Automation is how that works. (With occasional overrides that should
get the attention of a reviewer).
-->
<!--<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.1.118" Condition="'$(NoCommonAnalyzers)' != 'true'" />-->
NOTE: This analyzer is sadly, perpetually in "pre-release mode". There have been many issues/discussion on the point
and it has all fallen on deaf ears. So policies regarding "NO-Prerelease" components need to be overruled on this one
-->
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" Condition="'$(UseStyleCop)' != 'false'" />
</ItemGroup>
<!--
Package versions made consistent across all packages referenced in this repository
-->
<ItemGroup>
<PackageVersion Include="Polyfill" Version="7.26.0" />
<PackageVersion Include="System.IO.Hashing" Version="9.0.4" />
<PackageVersion Include="System.CodeDom" Version="9.0.2" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="CppSharp" Version="1.1.5.3168" />
<PackageVersion Include="Antlr4BuildTasks" Version="12.10.0" />
<PackageVersion Include="Antlr4.Runtime.Standard" Version="4.13.1" />
<PackageVersion Include="OpenSoftware.DgmlBuilder" Version="2.1.0" />
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<!-- Tests all use the same framework versions -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.8.3" />
<PackageVersion Include="MSTest.TestFramework" Version="3.8.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.9.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.9.1" />
<PackageVersion Include="Tmds.ExecFunction" Version="0.8.0" />
<PackageVersion Include="Ubiquity.NET.Versioning" Version="5.0.0-rc" />
</ItemGroup>
</Project>
</Project>
2 changes: 2 additions & 0 deletions IgnoredWords.dic
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ github
Globalization
Hashtable
Identifier
Impl
inline
inlined
Interop
jit
len
Lexer
LibLLVM
Llilum
Expand Down
44 changes: 26 additions & 18 deletions src/Interop/InteropTests/ABI/libllvm-c/AnalysisBindingsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
// -----------------------------------------------------------------------
// <copyright file="AnalysisBindingsTests.cs" company="Ubiquity.NET Contributors">
// Copyright (c) Ubiquity.NET Contributors. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

using Microsoft.VisualStudio.TestTools.UnitTesting;

using static Ubiquity.NET.Llvm.Interop.ABI.libllvm_c.AnalysisBindings;
using static Ubiquity.NET.Llvm.Interop.ABI.llvm_c.Core;
Expand All @@ -18,44 +24,46 @@ public void LibLLVMVerifyFunctionExTest( )

// declare a test func to work with and create an entry block for it...
LLVMValueRef goodFunc = LLVMAddFunction(module, "goodfunc"u8, funcType);
ImplementFunction(goodFunc, intType, createBroken: false);
ImplementFunction( goodFunc, intType, createBroken: false );
LLVMStatus goodStatus = LibLLVMVerifyFunctionEx(goodFunc, llvm_c.LLVMVerifierFailureAction.LLVMPrintMessageAction, out string goodmsg);
Assert.AreEqual(0, goodStatus.ErrorCode);
Assert.IsFalse(goodStatus.Failed);
Assert.IsTrue(goodStatus.Succeeded);
Assert.AreEqual( 0, goodStatus.ErrorCode );
Assert.IsFalse( goodStatus.Failed );
Assert.IsTrue( goodStatus.Succeeded );

// test for each state of a string in order to produce a distinct failure point for each condition
Assert.IsNotNull(goodmsg, "Error message should not be null");
Assert.IsTrue(string.IsNullOrEmpty(goodmsg), "Error message should be empty, for successful validation");
Assert.IsNotNull( goodmsg, "Error message should not be null" );
Assert.IsTrue( string.IsNullOrEmpty( goodmsg ), "Error message should be empty, for successful validation" );

LLVMValueRef badFunc = LLVMAddFunction(module, "badfunc"u8, funcType);
ImplementFunction(badFunc, intType, createBroken: true);
ImplementFunction( badFunc, intType, createBroken: true );
LLVMStatus badStatus = LibLLVMVerifyFunctionEx(badFunc, llvm_c.LLVMVerifierFailureAction.LLVMPrintMessageAction, out string badmsg);
Assert.AreNotEqual(0, badStatus.ErrorCode);
Assert.IsTrue(badStatus.Failed);
Assert.IsFalse(badStatus.Succeeded);
Assert.AreNotEqual( 0, badStatus.ErrorCode );
Assert.IsTrue( badStatus.Failed );
Assert.IsFalse( badStatus.Succeeded );

// test for each state of a string in order to produce a distinct failure point for each condition
Assert.IsNotNull(badmsg, "Error message should not be null");
Assert.IsFalse(string.IsNullOrEmpty(badmsg), "Error message should not be empty");
Assert.IsFalse(string.IsNullOrWhiteSpace(badmsg), "Error message should not be all whitespace");
Assert.IsNotNull( badmsg, "Error message should not be null" );
Assert.IsFalse( string.IsNullOrEmpty( badmsg ), "Error message should not be empty" );
Assert.IsFalse( string.IsNullOrWhiteSpace( badmsg ), "Error message should not be all whitespace" );
}

private static void ImplementFunction(LLVMValueRef func, LLVMTypeRef intType, bool createBroken = false)
private static void ImplementFunction( LLVMValueRef func, LLVMTypeRef intType, bool createBroken = false )
{
LLVMContextRefAlias ctx = LLVMGetValueContext(func);

// Create an instruction builder to work with and connect it to
// a new entry block for the test function
using LLVMBuilderRef testBuilder = LLVMCreateBuilderInContext(ctx);
LLVMPositionBuilderAtEnd(testBuilder, LLVMAppendBasicBlockInContext(ctx, func, "entry"u8));
LLVMPositionBuilderAtEnd( testBuilder, LLVMAppendBasicBlockInContext( ctx, func, "entry"u8 ) );

// Now build out some code...
LLVMValueRef constOne = LLVMConstInt(intType, 1, false);
LLVMValueRef r0 = LLVMBuildAdd(testBuilder, constOne, constOne, string.Empty);

// BB without terminator is a good example of a bad function
if (!createBroken)
if(!createBroken)
{
LLVMBuildRet(testBuilder, r0);
LLVMBuildRet( testBuilder, r0 );
}
}
}
Expand Down
60 changes: 37 additions & 23 deletions src/Interop/InteropTests/ABI/libllvm-c/AttributeBindingsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
using System;
// -----------------------------------------------------------------------
// <copyright file="AttributeBindingsTests.cs" company="Ubiquity.NET Contributors">
// Copyright (c) Ubiquity.NET Contributors. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand All @@ -22,13 +29,15 @@ public class AttributeBindingsTests
public void LibLLVMGetNumKnownAttribsTest( )
{
int len = checked((int)LibLLVMGetNumKnownAttribs());

// Known count of attributes at time of this test
// Changes are flagged by this test so that updates to consumers or release notes
// can be made if applicable.
Assert.AreEqual(KnownAttributes.Count, len);
Assert.AreEqual( KnownAttributes.Count, len );
}

[TestMethod]
[SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1305:Field names should not use Hungarian notation", Justification = "ppData makes sense and matches the api" )]
public void LibLLVMGetKnownAttributeNamesTest( )
{
int len = checked((int)LibLLVMGetNumKnownAttribs());
Expand All @@ -44,17 +53,17 @@ public void LibLLVMGetKnownAttributeNamesTest( )
{
// https://github.com/microsoft/testfx/issues/5543
#pragma warning disable MSTEST0037 // Use proper 'Assert' methods
Assert.IsTrue(ppData[i] is not null);
Assert.IsTrue( ppData[ i ] is not null );
#pragma warning restore MSTEST0037 // Use proper 'Assert' methods

var les = LazyEncodedString.FromUnmanaged(ppData[i]);

actualNames[i] = LazyEncodedString.FromUnmanaged(ppData[i])!;
actualNames[ i ] = LazyEncodedString.FromUnmanaged( ppData[ i ] )!;
}

foreach(var name in actualNames)
{
Assert.IsTrue(KnownAttributes.ContainsKey(name), $"Attribute name not known: '{name}'");
Assert.IsTrue( KnownAttributes.ContainsKey( name ), $"Attribute name not known: '{name}'" );
}
}
}
Expand All @@ -67,10 +76,10 @@ public void LibLLVMAttributeToStringTest( )
LazyEncodedString value = "custom value"u8;

LLVMAttributeRef attribValue = LLVMCreateStringAttribute(ctx, name, value);
Assert.IsFalse(attribValue.IsNull);
Assert.IsFalse( attribValue.IsNull );

string result = LibLLVMAttributeToString(attribValue);
Assert.AreEqual("\"custom\"=\"custom value\"", result);
Assert.AreEqual( "\"custom\"=\"custom value\"", result );
}

[TestMethod]
Expand All @@ -80,20 +89,21 @@ public void LibLLVMIsConstantRangeAttributeTest( )

// create and validate a known constant range attribute
LLVMAttributeRef knownConstRangeAttrib = LLVMCreateConstantRangeAttribute(ctx, LLVMGetEnumAttributeKindForName("range"u8), 32, [0], [0x12345678]);
Assert.IsFalse(knownConstRangeAttrib.IsNull);
Assert.IsFalse( knownConstRangeAttrib.IsNull );
string knownConstRangeAttribAsString = LibLLVMAttributeToString(knownConstRangeAttrib);

// 0x12345678 = 305419896
Assert.AreEqual("range(i32 0, 305419896)", knownConstRangeAttribAsString);
Assert.AreEqual( "range(i32 0, 305419896)", knownConstRangeAttribAsString );

// Create and validate an attribute that is known NOT to be a constant range
LLVMAttributeRef enumAttrib = LLVMCreateEnumAttribute(ctx, LLVMGetEnumAttributeKindForName("builtin"u8), 0);
Assert.IsFalse(enumAttrib.IsNull);
Assert.IsFalse( enumAttrib.IsNull );
string enumAttribAsString = LibLLVMAttributeToString(enumAttrib);
Assert.AreEqual("builtin", enumAttribAsString);
Assert.AreEqual( "builtin", enumAttribAsString );

// Now actually test the API in question.
Assert.IsTrue(LibLLVMIsConstantRangeAttribute(knownConstRangeAttrib));
Assert.IsFalse(LibLLVMIsConstantRangeAttribute(enumAttrib));
Assert.IsTrue( LibLLVMIsConstantRangeAttribute( knownConstRangeAttrib ) );
Assert.IsFalse( LibLLVMIsConstantRangeAttribute( enumAttrib ) );
}

[SkipTestMethod]
Expand All @@ -116,9 +126,11 @@ select kvp
[TestMethod]
public void LibLLVMGetAttributeInfoTest( )
{
foreach(var kvp in KnownAttributes.OrderBy(kvp=>kvp.Value.ID))
foreach(var kvp in KnownAttributes.OrderBy( kvp => kvp.Value.ID ))
{
LibLLVMGetAttributeInfo( kvp.Key, out LibLLVMAttributeInfo info ).ThrowIfFailed();
using var err = LibLLVMGetAttributeInfo( kvp.Key, out LibLLVMAttributeInfo info );
err.ThrowIfFailed();

Assert.AreEqual( kvp.Value, info );
if(info.ID == 0)
{
Expand All @@ -134,9 +146,9 @@ public void LibLLVMGetAttributeInfoTest( )
using LLVMErrorRef errorRef = LibLLVMGetAttributeInfo("custom"u8, out LibLLVMAttributeInfo customAttribinfo);
errorRef.ThrowIfFailed();

Assert.AreEqual(0u, customAttribinfo.ID);
Assert.AreEqual(LibLLVMAttributeArgKind.LibLLVMAttributeArgKind_String, customAttribinfo.ArgKind);
Assert.AreEqual(LibLLVMAttributeAllowedOn.LibLLVMAttributeAllowedOn_All, customAttribinfo.AllowedOn);
Assert.AreEqual( 0u, customAttribinfo.ID );
Assert.AreEqual( LibLLVMAttributeArgKind.LibLLVMAttributeArgKind_String, customAttribinfo.ArgKind );
Assert.AreEqual( LibLLVMAttributeAllowedOn.LibLLVMAttributeAllowedOn_All, customAttribinfo.AllowedOn );
}

[TestMethod]
Expand All @@ -149,13 +161,14 @@ where kvp.Value.ID > 0
foreach(var kvp in knownEnumAttribs)
{
var actualName = LibLLVMGetAttributeNameFromID(kvp.Value.ID);
Assert.IsNotNull(actualName, $"Name should not be null for ID: {kvp.Value.ID})");
Assert.AreEqual(kvp.Key, actualName, $"Name for ID: {kvp.Value.ID} should be '{kvp.Key})'");
Assert.IsNotNull( actualName, $"Name should not be null for ID: {kvp.Value.ID})" );
Assert.AreEqual( kvp.Key, actualName, $"Name for ID: {kvp.Value.ID} should be '{kvp.Key})'" );
}
}

private readonly static ImmutableDictionary<LazyEncodedString, LibLLVMAttributeInfo> KnownAttributes
= new DictionaryBuilder<LazyEncodedString, LibLLVMAttributeInfo> {
private static readonly ImmutableDictionary<LazyEncodedString, LibLLVMAttributeInfo> KnownAttributes
= new DictionaryBuilder<LazyEncodedString, LibLLVMAttributeInfo>
{
["no-infs-fp-math"u8] = new(0, LibLLVMAttributeArgKind.LibLLVMAttributeArgKind_String, LibLLVMAttributeAllowedOn.LibLLVMAttributeAllowedOn_All),
["approx-func-fp-math"u8] = new(0, LibLLVMAttributeArgKind.LibLLVMAttributeArgKind_String, LibLLVMAttributeAllowedOn.LibLLVMAttributeAllowedOn_All),
["no-jump-tables"u8] = new(0, LibLLVMAttributeArgKind.LibLLVMAttributeArgKind_String, LibLLVMAttributeAllowedOn.LibLLVMAttributeAllowedOn_All),
Expand All @@ -167,6 +180,7 @@ private readonly static ImmutableDictionary<LazyEncodedString, LibLLVMAttributeI
["unsafe-fp-math"u8] = new(0, LibLLVMAttributeArgKind.LibLLVMAttributeArgKind_String, LibLLVMAttributeAllowedOn.LibLLVMAttributeAllowedOn_All),
["use-sample-profile"u8] = new(0, LibLLVMAttributeArgKind.LibLLVMAttributeArgKind_String, LibLLVMAttributeAllowedOn.LibLLVMAttributeAllowedOn_All),
["no-inline-line-tables"u8] = new(0, LibLLVMAttributeArgKind.LibLLVMAttributeArgKind_String, LibLLVMAttributeAllowedOn.LibLLVMAttributeAllowedOn_All),

// First Enum attribute...
["allocalign"u8] = new(1, LibLLVMAttributeArgKind.LibLLVMAttributeArgKind_None, LibLLVMAttributeAllowedOn.LibLLVMAttributeAllowedOn_Parameter),
["allocptr"u8] = new(2, LibLLVMAttributeArgKind.LibLLVMAttributeArgKind_None, LibLLVMAttributeAllowedOn.LibLLVMAttributeAllowedOn_Parameter),
Expand Down Expand Up @@ -271,7 +285,7 @@ private readonly static ImmutableDictionary<LazyEncodedString, LibLLVMAttributeI

// for a debug build, write the element entries for the "KnownAttributes"
// This makes it easier to update that map AFTER validation of any changed values.
[Conditional("DEBUG")]
[Conditional( "DEBUG" )]
private static void ShowKnownAttributesEntry( LazyEncodedString name, LibLLVMAttributeInfo info )
{
var flagValues = from val in info.AllowedOn.ToString().Split(',')
Expand Down
Loading
Loading