jacob-carlborg / dstep

A tool for converting C and Objective-C headers to D modules
204 stars 37 forks source link

Assertion Failure when defining a cast from int to function pointer #281

Open Ssamm45 opened 2 years ago

Ssamm45 commented 2 years ago

I was trying to run dstep on the latest version of the tcl header and ran into an assertion error. I figured out that the error was comming from tcl.h:902-904 where three macros are defined.

#define TCL_VOLATILE        ((Tcl_FreeProc *) 1)
#define TCL_STATIC      ((Tcl_FreeProc *) 0)
#define TCL_DYNAMIC     ((Tcl_FreeProc *) 3)

If those three lines are removed the file is successfully translated.

The issue can be reproduced with the following two lines in a C file. The full error message is at the bottom of this post

typedef void (Tcl_FreeProc) (void *blockPtr);

#define TCL_VOLATILE        ((Tcl_FreeProc *) 1)

dstep --version - 1.0.3-2-g2f6e8ae

dstep --clang-version - clang version 13.0.1

The error message

dstep: an unknown error occurred: core.exception.AssertError@dstep/translator/Type.d(32): Assertion failure
----------------
??:? _d_assertp [0x557bc7acaebc]
dstep/translator/Type.d:32 dstep.translator.Output.SourceNode dstep.translator.Type.translateType(dstep.translator.Context.Context, clang.Cursor.Cursor, clang.Type.Type, bool, bool) [0x557bc7ab3175]
dstep/translator/Type.d:529 dstep.translator.Output.SourceNode dstep.translator.Type.translateFunctionPointerType(dstep.translator.Context.Context, clang.Cursor.Cursor, clang.Type.FuncType) [0x557bc7ab579e]
dstep/translator/Type.d:41 dstep.translator.Output.SourceNode dstep.translator.Type.translateType(dstep.translator.Context.Context, clang.Cursor.Cursor, clang.Type.Type, bool, bool) [0x557bc7ab3203]
dstep/translator/MacroDefinition.d:333 immutable(char)[] dstep.translator.MacroDefinition.translate(std.variant.VariantN!(64uL, dstep.translator.MacroParser.Identifier, dstep.translator.MacroParser.TypeIdentifier, dstep.translator.MacroParser.Literal, dstep.translator.MacroParser.StringLiteral, dstep.translator.MacroParser.StringifyExpr, dstep.translator.MacroParser.StringConcat, dstep.translator.MacroParser.TokenConcat, dstep.translator.MacroParser.IndexExpr, dstep.translator.MacroParser.CallExpr, dstep.translator.MacroParser.DotExpr, dstep.translator.MacroParser.ArrowExpr, dstep.translator.MacroParser.SubExpr, dstep.translator.MacroParser.UnaryExpr, dstep.translator.MacroParser.DefinedExpr, dstep.translator.MacroParser.SizeofType, dstep.translator.MacroParser.CastExpr, dstep.translator.MacroParser.MulExpr, dstep.translator.MacroParser.AddExpr, dstep.translator.MacroParser.SftExpr, dstep.translator.MacroParser.RelExpr, dstep.translator.MacroParser.EqlExpr, dstep.translator.MacroParser.AndExpr, dstep.translator.MacroParser.XorExpr, dstep.translator.MacroParser.OrExpr, dstep.translator.MacroParser.LogicalAndExpr, dstep.translator.MacroParser.LogicalOrExpr, dstep.translator.MacroParser.CondExpr).VariantN, dstep.translator.MacroDefinition.ExpressionContext).__dgliteral19(dstep.translator.MacroParser.CastExpr) [0x557bc7a7c316]
/usr/include/dlang/dmd/std/variant.d:2745 immutable(char)[] std.variant.visitImpl!(true, std.variant.VariantN!(64uL, dstep.translator.MacroParser.Identifier, dstep.translator.MacroParser.TypeIdentifier, dstep.translator.MacroParser.Literal, dstep.translator.MacroParser.StringLiteral, dstep.translator.MacroParser.StringifyExpr, dstep.translator.MacroParser.StringConcat, dstep.translator.MacroParser.TokenConcat, dstep.translator.MacroParser.IndexExpr, dstep.translator.MacroParser.CallExpr, dstep.translator.MacroParser.DotExpr, dstep.translator.MacroParser.ArrowExpr, dstep.translator.MacroParser.SubExpr, dstep.translator.MacroParser.UnaryExpr, dstep.translator.MacroParser.DefinedExpr, dstep.translator.MacroParser.SizeofType, dstep.translator.MacroParser.CastExpr, dstep.translator.MacroParser.MulExpr, dstep.translator.MacroParser.AddExpr, dstep.translator.MacroParser.SftExpr, dstep.translator.MacroParser.RelExpr, dstep.translator.MacroParser.EqlExpr, dstep.translator.MacroParser.AndExpr, dstep.translator.MacroParser.XorExpr, dstep.translator.MacroParser.OrExpr, dstep.translator.MacroParser.LogicalAndExpr, dstep.translator.MacroParser.LogicalOrExpr, dstep.translator.MacroParser.CondExpr).VariantN, dstep.translator.MacroDefinition.translate(std.variant.VariantN!(64uL, dstep.translator.MacroParser.Identifier, dstep.translator.MacroParser.TypeIdentifier, dstep.translator.MacroParser.Literal, dstep.translator.MacroParser.StringLiteral, dstep.translator.MacroParser.StringifyExpr, dstep.translator.MacroParser.StringCon...
/usr/include/dlang/dmd/std/variant.d:2415 immutable(char)[] std.variant.visit!(dstep.translator.MacroDefinition.translate(std.variant.VariantN!(64uL, dstep.translator.MacroParser.Identifier, dstep.translator.MacroParser.TypeIdentifier, dstep.translator.MacroParser.Literal, dstep.translator.MacroParser.StringLiteral, dstep.translator.MacroParser.StringifyExpr, dstep.translator.MacroParser.StringConcat, dstep.translator.MacroParser.TokenConcat, dstep.translator.MacroParser.IndexExpr, dstep.translator.MacroParser.CallExpr, dstep.translator.MacroParser.DotExpr, dstep.translator.MacroParser.ArrowExpr, dstep.translator.MacroParser.SubExpr, dstep.translator.MacroParser.UnaryExpr, dstep.translator.MacroParser.DefinedExpr, dstep.translator.MacroParser.SizeofType, dstep.translator.MacroParser.CastExpr, dstep.translator.MacroParser.MulExpr, dstep.translator.MacroParser.AddExpr, dstep.translator.MacroParser.SftExpr, dstep.translator.MacroParser.RelExpr, dstep.translator.MacroParser.EqlExpr, dstep.translator.MacroParser.AndExpr, dstep.translator.MacroParser.XorExpr, dstep.translator.MacroParser.OrExpr, dstep.translator.MacroParser.LogicalAndExpr, dstep.translator.MacroParser.LogicalOrExpr, dstep.translator.MacroParser.CondExpr).VariantN, dstep.translator.MacroDefinition.ExpressionContext).__dgliteral4(dstep.translator.MacroParser.Identifier), dstep.translator.MacroDefinition.translate(std.variant.VariantN!(64uL, dstep.translator.MacroParser.Identifier, dstep.translator.MacroParser.TypeIdentifier, dstep.translator.MacroPa...
dstep/translator/MacroDefinition.d:207 immutable(char)[] dstep.translator.MacroDefinition.translate(std.variant.VariantN!(64uL, dstep.translator.MacroParser.Identifier, dstep.translator.MacroParser.TypeIdentifier, dstep.translator.MacroParser.Literal, dstep.translator.MacroParser.StringLiteral, dstep.translator.MacroParser.StringifyExpr, dstep.translator.MacroParser.StringConcat, dstep.translator.MacroParser.TokenConcat, dstep.translator.MacroParser.IndexExpr, dstep.translator.MacroParser.CallExpr, dstep.translator.MacroParser.DotExpr, dstep.translator.MacroParser.ArrowExpr, dstep.translator.MacroParser.SubExpr, dstep.translator.MacroParser.UnaryExpr, dstep.translator.MacroParser.DefinedExpr, dstep.translator.MacroParser.SizeofType, dstep.translator.MacroParser.CastExpr, dstep.translator.MacroParser.MulExpr, dstep.translator.MacroParser.AddExpr, dstep.translator.MacroParser.SftExpr, dstep.translator.MacroParser.RelExpr, dstep.translator.MacroParser.EqlExpr, dstep.translator.MacroParser.AndExpr, dstep.translator.MacroParser.XorExpr, dstep.translator.MacroParser.OrExpr, dstep.translator.MacroParser.LogicalAndExpr, dstep.translator.MacroParser.LogicalOrExpr, dstep.translator.MacroParser.CondExpr).VariantN, dstep.translator.MacroDefinition.ExpressionContext) [0x557bc7a77d12]
dstep/translator/MacroDefinition.d:618 void dstep.translator.MacroDefinition.translateMacroDefinitionAliasOrConst(dstep.translator.Output.Output, dstep.translator.Context.Context, dstep.translator.TypeInference.TypedMacroDefinition) [0x557bc7a78553]
dstep/translator/MacroDefinition.d:634 void dstep.translator.MacroDefinition.translateMacroDefinition(dstep.translator.Output.Output, dstep.translator.Context.Context, dstep.translator.TypeInference.TypedMacroDefinition) [0x557bc7a7860f]
dstep/translator/Translator.d:323 void dstep.translator.Translator.Translator.translateMacroDefinition(dstep.translator.Output.Output, clang.Cursor.Cursor, clang.Cursor.Cursor) [0x557bc7ab202a]
dstep/translator/Translator.d:193 void dstep.translator.Translator.Translator.translate(dstep.translator.Output.Output, clang.Cursor.Cursor, clang.Cursor.Cursor) [0x557bc7ab1731]
dstep/translator/Translator.d:131 void dstep.translator.Translator.Translator.translateInGlobalScope(dstep.translator.Output.Output, clang.Cursor.Cursor, clang.Cursor.Cursor) [0x557bc7ab1352]
dstep/translator/Translator.d:98 int dstep.translator.Translator.Translator.translateCursors().__foreachbody3(ref clang.Cursor.Cursor, ref clang.Cursor.Cursor) [0x557bc7ab123b]
clang/Visitor.d:179 int clang.Visitor.InOrderVisitor.opApply(int delegate(ref clang.Cursor.Cursor, ref clang.Cursor.Cursor)) [0x557bc7a55137]
dstep/translator/Translator.d:85 dstep.translator.Output.Output dstep.translator.Translator.Translator.translateCursors() [0x557bc7ab1066]
dstep/translator/Translator.d:117 immutable(char)[] dstep.translator.Translator.Translator.translateToString() [0x557bc7ab125e]
dstep/translator/Translator.d:75 void dstep.translator.Translator.Translator.translate() [0x557bc7ab0f79]
dstep/driver/Application.d:67 int dstep.driver.Application.Application.run().__foreachbody5(std.typecons.Tuple!(immutable(char)[], immutable(char)[], clang.TranslationUnit.TranslationUnit).Tuple) [0x557bc7a576dd]
/usr/include/dlang/dmd/std/parallelism.d-mixin-4093:4139 void std.parallelism.ParallelForeach!(std.range.ZipShortest!(1, immutable(char)[][], immutable(char)[][], clang.TranslationUnit.TranslationUnit[]).ZipShortest).ParallelForeach.opApply(scope int delegate(std.typecons.Tuple!(immutable(char)[], immutable(char)[], clang.TranslationUnit.TranslationUnit).Tuple)).doIt() [0x557bc7a57e24]
??:? void std.parallelism.run!(void delegate()).run(void delegate()) [0x557bc7ae0b43]
??:? void std.parallelism.Task!(std.parallelism.run, void delegate()).Task.impl(void*) [0x557bc7ae0623]
??:? void std.parallelism.AbstractTask.job() [0x557bc7b027f2]
??:? void std.parallelism.submitAndExecute(std.parallelism.TaskPool, void delegate()) [0x557bc7ae0243]
/usr/include/dlang/dmd/std/parallelism.d:4089 int std.parallelism.ParallelForeach!(std.range.ZipShortest!(1, immutable(char)[][], immutable(char)[][], clang.TranslationUnit.TranslationUnit[]).ZipShortest).ParallelForeach.opApply(scope int delegate(std.typecons.Tuple!(immutable(char)[], immutable(char)[], clang.TranslationUnit.TranslationUnit).Tuple)) [0x557bc7a57d17]
dstep/driver/Application.d:57 void dstep.driver.Application.Application.run() [0x557bc7a575c4]
dstep/driver/CommandLine.d:181 int dstep.driver.CommandLine.run(immutable(char)[][]) [0x557bc7a68a08]
dstep/main.d:18 _Dmain [0x557bc7a6b82f]