Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator uses underlying type of typedef when used as a parameter #146

Open
waj334 opened this issue Apr 3, 2023 · 0 comments
Open

Generator uses underlying type of typedef when used as a parameter #146

waj334 opened this issue Apr 3, 2023 · 0 comments

Comments

@waj334
Copy link

waj334 commented Apr 3, 2023

Consider the following C:

typedef struct LLVMOpaqueContext *LLVMContextRef;
void *LLVMContextGetDiagnosticContext(LLVMContextRef C);

and the following config:

GENERATOR:
  PackageName: llvm
  PackageDescription: "LLVM bindings for Go"
  PackageLicense: "Apache License v2.0 with LLVM Exceptions"
  Options:
      SafeStrings: true
PARSER:
  IncludePaths:
    - ./thirdparty/llvm-project/llvm/include
    - ./build/llvm-build/include
  SourcesPaths:
    - ./test.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Analysis.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/BitReader.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/BitWriter.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/blake3.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Comdat.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Core.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/DataTypes.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/DebugInfo.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Deprecated.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Disassembler.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/DisassemblerTypes.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Error.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/ErrorHandling.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/ExecutionEngine.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/ExternC.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Initialization.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/IRReader.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Linker.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/LLJIT.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/lto.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Object.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Orc.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/OrcEE.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Remarks.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Support.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Target.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/TargetMachine.h
    #- ./thirdparty/llvm-project/llvm/include/llvm-c/Types.h
TRANSLATOR:
  ConstCharIsString: true
  ConstUCharIsString: true
  ConstRules:
    defines: eval
  Rules:
    global:
      - {action: accept, from: "^LLVM"}
      - {transform: export}
    const:
      - {action: accept, from: "^LLVM"}
      - {transform: export}
    type:
      - {action: accept, from: "^LLVM"}
      - {transform: export}
    private:
      - {transform: unexport}

The produces the following:
types.go

// Apache License v2.0 with LLVM Exceptions

// WARNING: This file has automatically been generated
// Code generated by https://git.io/c-for-go. DO NOT EDIT.

package llvm

/*
#include <stdlib.h>
#include "cgo_helpers.h"
*/
import "C"

// LLVMContextRef as declared in sigo/test.h:1
type LLVMContextRef C.struct_LLVMOpaqueContext

llvm.go

// Apache License v2.0 with LLVM Exceptions

// WARNING: This file has automatically been generated
// Code generated by https://git.io/c-for-go. DO NOT EDIT.

package llvm

/*
#include <stdlib.h>
#include "cgo_helpers.h"
*/
import "C"
import (
	"runtime"
	"unsafe"
)

// LLVMContextGetDiagnosticContext function as declared in sigo/test.h:3
func LLVMContextGetDiagnosticContext(c LLVMOpaqueContext) unsafe.Pointer {
	cc, ccAllocMap := *(*C.struct_LLVMOpaqueContext)(unsafe.Pointer(&c)), cgoAllocsUnknown
	__ret := C.LLVMContextGetDiagnosticContext(cc)
	runtime.KeepAlive(ccAllocMap)
	__v := *(*unsafe.Pointer)(unsafe.Pointer(&__ret))
	return __v
}

In LLVMContextGetDiagnosticContext I expected the parameter to be of type LLVMContextRef, not LLVMOpaqueContext which is not directly defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant