Code Monkey home page Code Monkey logo

Comments (4)

smaillet avatar smaillet commented on May 19, 2024

Can you provide more specific examples of your code? Empty structs are a valid concept in many languages and should be possible in LLVM (and the DWARF inspired debug info it uses).

LLVM is unfortunately not particularly good about documenting it's parameter requirements and doesn't generate errors on invalid ones - it just crashes in release builds or asserts and aborts the process in a debug build. So a lot of the work in the .NET bindings is in doing parameter checks and creating meaningful exceptions and exception messages. It's possible this is a case of overly aggressive checks in the .NET projection.

from llvm.net.

andyjansson avatar andyjansson commented on May 19, 2024

The issue is demonstrated by the following snippet:

new DebugStructType(
  module,
  "tuple",
  module.DICompileUnit,
  "tuple",
  null,
  0,
  DebugInfoFlags.None,
  Enumerable.Empty<DebugMemberInfo>()
);

Here's the relevant exception and stack trace:

Exception has occurred: CLR/System.ArgumentException
Exception thrown: 'System.ArgumentException' in Ubiquity.NET.Llvm.dll: 'Type must be sized to get target size information'
   at Ubiquity.NET.Llvm.DataLayout.VerifySized(ITypeRef type, String name)
   at Ubiquity.NET.Llvm.DataLayout.BitSizeOf(ITypeRef typeRef)
   at Ubiquity.NET.Llvm.DebugInfo.DebugStructType..ctor(BitcodeModule module, String nativeName, DIScope scope, String name, DIFile file, UInt32 line, DebugInfoFlags debugFlags, IEnumerable`1 debugElements, DIType derivedFrom, Boolean packed, Nullable`1 bitSize, UInt32 bitAlignment)

from llvm.net.

smaillet avatar smaillet commented on May 19, 2024

OK, that looks like a bug, Context.CreateStructType(string,bool,params ITypeRef[]) skips setting the body, when the element count is 0. This is unnecessary as the underlying LLVM APIs will accept the 0 length and mark the type as sized (with a size of 0).

Possible workaround: (I haven't tested it as I need to get to my day job [Been looking at this while waiting on a machine OS update]) But you should be able to create a native struct type, set the body to 0, then use that to create the DebugStruct type (e.g. attach the debug info from the existing native IR type that is a sized empty struct)

var lirType = module.Context.CreateStructType("tuple");
irType.SetBody(false);
var debugType = new DebugStructType(
  llvmType: irType,
 module: module,
 scope: null,
 name:"tuple",
 file: null,
 line: 0,
debugFlags: default
derivedFrom: null
elements: Enumerable.Empty<DIType>());

NOTE: There are two overloads of the DebugStructType constructor that take an IStructType as the first parameter. The one with fewer parameters creates a replaceable composite type, which you probably don't want. (Which is why the example above uses the named parameters to be clearer on which one you need)

from llvm.net.

andyjansson avatar andyjansson commented on May 19, 2024

That worked a treat, thank you very much.

from llvm.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.