Comments (4)
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.
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.
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.
That worked a treat, thank you very much.
from llvm.net.
Related Issues (20)
- [llvm10 docs] Docs links from articles/index page and TOC are wrong
- [Bug] ContextCache.GetContextFor is not thread safe HOT 1
- [Feature] - Add Support for creating DIFile with checksum information and source text.
- DebugStructType for anonymous structures? HOT 3
- Incompatible types when nesting anonymous structs HOT 5
- [Feature] - Add support for cross-platform use HOT 9
- [BUG] - CreateConstantString fails when given an empty string HOT 2
- [BUG] - Error occurred while restoring NuGet packages: The local source 'BuildOutput\Nuget' doesn't exist HOT 1
- [Feature] - Create MemoryBuffer from byte array HOT 2
- [BUG] - Error building interop HOT 5
- [Feature] - ConstantDataSequential does not have a way of accessing non-string data HOT 3
- [BUG] - CommonBuild.psd1 has UTF-16 BLE BOM, causing git to treat it as binary HOT 2
- [Feature] - Replace bindingsConfig.yml FunctionBindings with direct manual P/Invoke
- [Feature] - Split da Jit
- [BUG] - Ubiquity.NET.LLVM.Props appears redundant
- [BUG] - [Build break] Official build on Develop failed
- Hyperlink leads to unrelated site HOT 1
- InstructionBuilder.SDiv creates UDiv instead of SDiv HOT 1
- [BUG] - External linkage doesn't seem to work. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llvm.net.