jextract fails to parse stdatomic.h

Artem Ananev artem.ananev at swirldslabs.com
Thu Oct 19 23:42:02 UTC 2023


Hi,

I use jextract version "JDK version 21+35-LTS-2513” on a Ubuntu 22.04.3 box. It fails with the following error:

```
java.lang.AssertionError: Unexpected size for layout []. Found 0 ; expected 1
	at org.openjdk.jextract at 21/org.openjdk.jextract.impl.RecordLayoutComputer.checkSize(RecordLayoutComputer.java:198)
	at org.openjdk.jextract at 21/org.openjdk.jextract.impl.StructLayoutComputer.finishRecord(StructLayoutComputer.java:142)
	at org.openjdk.jextract at 21/org.openjdk.jextract.impl.RecordLayoutComputer.compute(RecordLayoutComputer.java:114)
	at org.openjdk.jextract at 21/org.openjdk.jextract.impl.RecordLayoutComputer.computeInternal(RecordLayoutComputer.java:89)
	at org.openjdk.jextract at 21/org.openjdk.jextract.impl.RecordLayoutComputer.compute(RecordLayoutComputer.java:71)
	at org.openjdk.jextract at 21/org.openjdk.jextract.impl.TreeMaker.createRecord(TreeMaker.java:205)
	at org.openjdk.jextract at 21/org.openjdk.jextract.impl.TreeMaker.createTreeInternal(TreeMaker.java:104)
	at org.openjdk.jextract at 21/org.openjdk.jextract.impl.TreeMaker.createTree(TreeMaker.java:93)
	at org.openjdk.jextract at 21/org.openjdk.jextract.impl.Parser.lambda$parse$2(Parser.java:86)
	at org.openjdk.jextract at 21/org.openjdk.jextract.clang.Cursor$CursorChildren$Context.visit(Cursor.java:223)
	at org.openjdk.jextract at 21/org.openjdk.jextract.clang.Cursor$CursorChildren.lambda$static$0(Cursor.java:242)
	at org.openjdk.jextract at 21/org.openjdk.jextract.clang.libclang.Index_h.clang_visitChildren(Index_h.java:5108)
	at org.openjdk.jextract at 21/org.openjdk.jextract.clang.Cursor$CursorChildren.forEach(Cursor.java:254)
	at org.openjdk.jextract at 21/org.openjdk.jextract.clang.Cursor.forEach(Cursor.java:194)
	at org.openjdk.jextract at 21/org.openjdk.jextract.impl.Parser.parse(Parser.java:64)
	at org.openjdk.jextract at 21/org.openjdk.jextract.JextractTool.parse(JextractTool.java:116)
	at org.openjdk.jextract at 21/org.openjdk.jextract.JextractTool.run(JextractTool.java:466)
	at org.openjdk.jextract at 21/org.openjdk.jextract.JextractTool.main(JextractTool.java:174)
Unrecoverable uncaught exception encountered. The VM will now exit
```

There is no way to understand where exactly it fails, so I downloaded jextract sources, ran it in debug mode, and found the error happens when it’s parsing <stdatomic.h>, in particular this line:

```
typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
```

If I comment out this line (and all other declarations in the same header that depend on atomic_flag), jextract no longer fails. Note that this header is a part of jextract distribution, it’s in <jextract home>/conf/jextract/stdatomic.h

Steps to reproduce:

```
echo '#include <stdatomic.h>' >/tmp/test.h && jextract --source /tmp/test.h
```

Thanks,
Artem



More information about the panama-dev mailing list