tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Patch: win: ignore dllimport/dllexport for typedef with w


From: Yuxi Hao
Subject: [Tinycc-devel] Patch: win: ignore dllimport/dllexport for typedef with warning instead of error
Date: Sat, 29 Jun 2019 11:11:13 +0800

Dear there,

 

I have created a patch as the title says.

The issue was caught when I use tcc together with the latest MinGW-w64 headers (my mod: https://github.com/lifenjoiner/MinGW-w64-tcc).

I think the patch won’t break the mob. If nobody gets any new issue, I’ll push it in a few days. J

 

And the summary is as bellow (and attachment) in Markdown:

 

# Typedef Function Type in c

 

## Example

 

```c

#define _WIN32_WINNT 0x501

#include <windows.h>

int main() {

    return 0;

}

```

 

## TCC Error

 

d:/build/tcc/include/winapi/winuser.h:2171: error: cannot have dll linkage with static or typedef

 

```c

#if _WIN32_WINNT < 0x0502

  typedef

#endif

  WINUSERAPI WINBOOL WINAPI UpdateLayeredWindowIndirect (HWND hWnd, const UPDATELAYEREDWINDOWINFO *pULWInfo);

```

 

## Preprocess

 

```c

  typedef

 

  __attribute__((dllimport)) WINBOOL __attribute__((__stdcall__)) UpdateLayeredWindowIndirect (HWND hWnd, const UPDATELAYEREDWINDOWINFO *pULWInfo);

```

 

## About `UpdateLayeredWindowIndirect`

 

https://github.com/mirror/mingw-w64/blob/d793e0ef20875aaeee457e83163aeb267d87d125/mingw-w64-headers/include/winuser.h#L2169

 

And it is based on `winuser.h` of msvc.

 

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms633557(v=vs.85)

 

## Further Explanation

 

http://www.iso-9899.info/wiki/Typedef_Function_Type

 

https://riptutorial.com/c/example/31818/typedef-for-function-pointers

 

## TCC Source Code

 

https://repo.or.cz/tinycc.git/blob/f2fd56a27dc0abf9f34c9a950456853ad13c4f96:/tccgen.c#l7547

 

```c

#ifdef TCC_TARGET_PE

            if (ad.a.dllimport || ad.a.dllexport) {

                if (type.t & (VT_STATIC|VT_TYPEDEF))

                    tcc_error("cannot have dll linkage with static or typedef");

                if (ad.a.dllimport) {

                    if ((type.t & VT_BTYPE) == VT_FUNC)

                        ad.a.dllimport = 0;

                    else

                        type.t |= VT_EXTERN;

                }

            }

#endif

```

 

## Patched

 

```c

#ifdef TCC_TARGET_PE

            if (ad.a.dllimport || ad.a.dllexport) {

                if (type.t & VT_STATIC)

                    tcc_error("cannot have dll linkage with static");

                if (type.t & VT_TYPEDEF) {

                    tcc_warning("'%s' attribute ignored for typedef",

                        ad.a.dllimport ? (ad.a.dllimport = 0, "dllimport") :

                        (ad.a.dllexport = 0, "dllexport"));

                } else if (ad.a.dllimport) {

                    if ((type.t & VT_BTYPE) == VT_FUNC)

                        ad.a.dllimport = 0;

                    else

                        type.t |= VT_EXTERN;

                }

            }

#endif

```

 

## Test File

 

`test_dllimport.c`

 

```c

#include <stdio.h>

 

typedef __attribute__((dllimport)) int __attribute__((__stdcall__)) UpdateLayeredWindowIndirect (int a, int b);

 

int main() {

    printf("1\n");

    return 0;

}

```

 

`test_dllexport.c`

 

```

#include <stdio.h>

 

typedef __attribute__((dllexport)) int __attribute__((__stdcall__)) UpdateLayeredWindowIndirect_2 (int a, int b);

 

int main() {

    printf("1\n");

    return 0;

}

```

 

## Referer

 

- clang

 

   `static`, error:

 

   https://github.com/llvm-mirror/clang/blob/c760628a81bf9f7b4dc75d4f8c1d178f7c68fe2f/test/Sema/dllimport.c#L224

 

   https://github.com/llvm-mirror/clang/blob/c760628a81bf9f7b4dc75d4f8c1d178f7c68fe2f/test/Sema/dllexport.c#L116

 

   `typedef`, warning:

 

   https://github.com/llvm-mirror/clang/blob/c760628a81bf9f7b4dc75d4f8c1d178f7c68fe2f/test/Sema/dllimport.c#L14

 

   https://github.com/llvm-mirror/clang/blob/c760628a81bf9f7b4dc75d4f8c1d178f7c68fe2f/test/Sema/dllexport.c#L13

 

- gcc

 

  `static`, error:

 

  https://github.com/gcc-mirror/gcc/blob/41d6b10e96a1de98e90a7c0378437c3255814b16/gcc/testsuite/g%2B%2B.dg/ext/dllimport5.C#L7

 

  https://github.com/gcc-mirror/gcc/blob/41d6b10e96a1de98e90a7c0378437c3255814b16/gcc/testsuite/g%2B%2B.dg/ext/dllimport5.C#L10

 

  `typedef`, warning:

 

  Haven't located the code.

 

## Extra issue

 

Tcc still doesn't support all the above related clang tests.

 

 

 

Best Regards,

YX Hao

 

Attachment: tcc_typedef_function-type.md
Description: Binary data

Attachment: tcc_typedef_function-type.patch
Description: Binary data

Attachment: test_dllimport.c
Description: Binary data

Attachment: test_dllexport.c
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]