llvm / llvm/llvm-project

[Clang] Add Clang Driver option to control Microsoft anonymous struct/union extensions

Open
#177,607 1 comment 0 reactions 0 assignees View on GitHub
clang extension:microsoft
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Add a new Clang Driver option `-fms-anonymous-structs` to enable Microsoft anonymous struct/union support independently from `-fms-extensions`.

This is needed to support code that uses anonymous structs extensively while avoiding conflicts with other Microsoft extensions (particularly `__ptr32`/`__ptr64` keywords).

The following program demonstrates this issue:

```c
#include
struct wInode
{
int x;
};
struct inode {
struct wInode;
};
int main()
{
struct inode p;
p.x = 20;
printf ("%d\n",p.x);
return 0;
}
```

```console
# clang -m64 -pthread -o out unnamed_struct.c -fms-extensions
In file included from unnamed_struct.c:1:
In file included from /usr/include/stdio.h:482:
/usr/include/sys/types.h:260:9: error: '__ptr32' attribute only applies to pointer arguments
260 | typedef __ptr32 mid_t; /* module ID */
| ^
/usr/include/sys/types.h:551:23: error: expected identifier or '('
551 | typedef void * __ptr64;
| ^
unnamed_struct.c:9:2: warning: anonymous structs are a Microsoft extension [-Wmicrosoft-anon-tag]
9 | struct wInode;
| ^
1 warning and 2 errors generated.
```

**Desired Behavior**:
Enable only the anonymous struct and union feature from Microsoft extensions.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.