From 9c3e5f72d571027689dba37cceb2a592dfcfdb5c Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Wed, 12 Apr 2023 04:55:27 -0400
Subject: [PATCH 4/7] cgo: Handle elaborated typedefs from libclang
I don't have a reference for this change in LLVM 16, so I just handled
it the same way as other elaborated types.
Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
cgo/libclang.go | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/cgo/libclang.go b/cgo/libclang.go
index 27ac1b57..95eb554a 100644
--- a/cgo/libclang.go
+++ b/cgo/libclang.go
@@ -653,6 +653,12 @@ func (p *cgoPackage) addErrorAt(position token.Position, msg string) {
func (f *cgoFile) makeDecayingASTType(typ C.CXType, pos token.Pos) ast.Expr {
// Strip typedefs, if any.
underlyingType := typ
+ if underlyingType.kind == C.CXType_Elaborated {
+ elaboratedType := C.clang_Type_getNamedType(typ)
+ if elaboratedType.kind == C.CXType_Typedef {
+ underlyingType = elaboratedType
+ }
+ }
if underlyingType.kind == C.CXType_Typedef {
c := C.tinygo_clang_getTypeDeclaration(typ)
underlyingType = C.tinygo_clang_getTypedefDeclUnderlyingType(c)
@@ -788,6 +794,8 @@ func (f *cgoFile) makeASTType(typ C.CXType, pos token.Pos) ast.Expr {
return f.makeASTType(underlying, pos)
case C.CXType_Enum:
return f.makeASTType(underlying, pos)
+ case C.CXType_Typedef:
+ return f.makeASTType(underlying, pos)
default:
typeKindSpelling := getString(C.clang_getTypeKindSpelling(underlying.kind))
f.addError(pos, fmt.Sprintf("unknown elaborated type (libclang type kind %s)", typeKindSpelling))
--
2.41.0