[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
riyaz86a wrote: > One other change we should make is to document the extension explicitly in > clang/docs/LanguageExtensions.rst so users know about the functionality. Missed to handle this, will take care of it. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
riyaz86a wrote: Thanks for the suggestion, I have updated the implementation to expose `-fms-anonymous-structs` as a Clang driver option instead of CC1 only. The driver now forwards the option to CC1 and argument ordering is respected (last option wins) when `-fms-anonymous-structs`, `-fno-ms-anonymous-structs`, `-fms-extensions` and `-fms-compatibility`. > [GCC has recently talked about doing something > similar](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123623) so it would be > nice to agree on the name of the driver option. I have used `-fms-anonymous-structs` as driver option to enable anonymous structure extension. Please let me know if you would recommend a different or more appropriate option name. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a edited https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 9c01511289217c605e37ca08ee4ccc554d8a9270 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH 01/12] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 6 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 20 +
9 files changed, 132 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-optio
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
zmodem wrote: > So to me, if this is important enough for users to be able to control > explicitly, it should be a driver flag. +1, if the flag is intended to be set by users, it should be a driver flag. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
AaronBallman wrote: > LGTM with minor nits; however, we still have the open question of whether > this should be a CC1-only option. > > @MaskRay, do you have an opinion on whether this should be exposed via a > Clang driver option (with or without a negative form)? CC @rnk @zmodem as other folks interested in Windows behaviors. > I think this makes sense to leave as a `-cc1`-only option for now. It's > always easy to promote this to a driver option, but pretty much impossible to > remove once it's in the driver. FWIW, I'm starting to feel pretty strongly about this not being a cc1-only flag. We do not want to condition users to do `-Xclang -some-option` for controlling language dialects. So to me, if this is important enough for users to be able to control explicitly, it should be a driver flag. (The situation where I think a cc1-only flag would be a good idea is if your downstream driver was going to enable this automatically for users so the user doesn't have to do the `-Xclang` dance, but I don't have the impression that's the case here.) I looked through Microsoft's documentation and could not find a `/Zc` or other flag to control this behavior in cl, so I don't think a driver option would require any changes for clang-cl. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -8,6 +8,25 @@ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-compatibility // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis +// Test that explicit -fno-ms-anonymous-structs does not enable the feature +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs overrides -fms-anonymous-structs +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fms-anonymous-structs -fno-ms-anonymous-structs +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fms-anonymous-structs -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs overrides -fms-extensions AaronBallman wrote: The answer I would expect is "last flag wins", so I would expect that to enable the extension. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 9c01511289217c605e37ca08ee4ccc554d8a9270 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH 01/11] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 6 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 20 +
9 files changed, 132 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-optio
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -8,6 +8,25 @@ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-compatibility // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis +// Test that explicit -fno-ms-anonymous-structs does not enable the feature +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs overrides -fms-anonymous-structs +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fms-anonymous-structs -fno-ms-anonymous-structs +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fms-anonymous-structs -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs overrides -fms-extensions hubert-reinterpretcast wrote: > In particular, is the extension enabled with `-fno-ms-anonymous-structs > -fms-extensions`? @riyaz86a, can you answer the question? It may be helpful for other reviewers (in case they have a strong opinion on what the answer should be). https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,80 @@ +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-anonymous-structs +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-anonymous-structs +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-extensions +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-compatibility +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis +// Test that explicit -fno-ms-anonymous-structs does not enable the feature. +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs does not enable the feature. +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs overrides -earlier fms-anonymous-structs. hubert-reinterpretcast wrote: Fix typo. ```suggestion // Test that explicit -fno-ms-anonymous-structs overrides earlier -fms-anonymous-structs. ``` https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,80 @@ +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-anonymous-structs +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-anonymous-structs +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-extensions +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-compatibility +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis +// Test that explicit -fno-ms-anonymous-structs does not enable the feature. +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs does not enable the feature. +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fno-ms-anonymous-structs hubert-reinterpretcast wrote: Remove duplicate test. ```suggestion // Test that explicit -fno-ms-anonymous-structs does not enable the feature. // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ // RUN: -fno-ms-anonymous-structs ``` https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 9c01511289217c605e37ca08ee4ccc554d8a9270 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH 01/10] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 6 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 20 +
9 files changed, 132 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-optio
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -8,6 +8,25 @@ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-compatibility // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis +// Test that explicit -fno-ms-anonymous-structs does not enable the feature +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs overrides -fms-anonymous-structs +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fms-anonymous-structs -fno-ms-anonymous-structs +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fms-anonymous-structs -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs overrides -fms-extensions +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fms-extensions -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs overrides -fms-compatibility hubert-reinterpretcast wrote: Same comments as above. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -8,6 +8,25 @@ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-compatibility // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis +// Test that explicit -fno-ms-anonymous-structs does not enable the feature +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs overrides -fms-anonymous-structs hubert-reinterpretcast wrote: ```suggestion // Test that explicit -fno-ms-anonymous-structs overrides earlier // -fms-anonymous-structs. ``` https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -12,7 +12,13 @@ // RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-extensions -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ // RUN: FileCheck --check-prefix=CC1-OK %s --allow-empty -// Test rejection of the unsupported negative form. -// RUN: not %clang_cc1 -triple powerpc-ibm-aix -fno-ms-anonymous-structs %s -fsyntax-only 2>&1 | \ -// RUN: FileCheck %s -// CHECK: error: unknown argument: '-fno-ms-anonymous-structs' +// Test that -fno-ms-anonymous-structs is accepted by CC1 without error. +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fno-ms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=CC1-OK %s --allow-empty + +// Test toggling between enable and disable (last one wins) hubert-reinterpretcast wrote: This does _not_ test the "last one wins" aspect. Minor nit: Periods are not omitted for code comments in LLVM (iiuc). In any case, the comment above uses a period. ```suggestion // Test both orderings of using both the negative and positive forms. ``` https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -8,6 +8,25 @@ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-compatibility // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis +// Test that explicit -fno-ms-anonymous-structs does not enable the feature hubert-reinterpretcast wrote: ```suggestion // Test that explicit -fno-ms-anonymous-structs does not enable the feature. ``` https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -8,6 +8,25 @@ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-compatibility // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis +// Test that explicit -fno-ms-anonymous-structs does not enable the feature +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs overrides -fms-anonymous-structs +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fms-anonymous-structs -fno-ms-anonymous-structs +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fms-anonymous-structs -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs overrides -fms-extensions hubert-reinterpretcast wrote: Does the property being tested (as described) actually hold? It is ambiguously worded as to whether the ordering matters. In particular, is the extension enabled with `-fno-ms-anonymous-structs -fms-extensions`? I think either answer is fine, but the comment should accurately describe the property that it tests. For example, by adding a parenthetical: ```suggestion // Test that explicit -fno-ms-anonymous-structs overrides earlier // -fms-extensions. ``` https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -8,6 +8,25 @@ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-compatibility // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis +// Test that explicit -fno-ms-anonymous-structs does not enable the feature +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fno-ms-anonymous-structs +// Test that explicit -fno-ms-anonymous-structs overrides -fms-anonymous-structs +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fms-anonymous-structs -fno-ms-anonymous-structs +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis \ +// RUN: -fms-anonymous-structs -fno-ms-anonymous-structs hubert-reinterpretcast wrote: Minor nit: I don't think we need to duplicate RUN lines with different triples other than to validate the basic cases. ```suggestion ``` https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -8,6 +8,25 @@ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-compatibility // RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ // RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis +// Test that explicit -fno-ms-anonymous-structs does not enable the feature hubert-reinterpretcast wrote: Please add a test in the `-verify=ms-anonymous` block of RUN lines that, of the positive and negative forms of the option being added, the last one wins. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 9c01511289217c605e37ca08ee4ccc554d8a9270 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH 1/9] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 6 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 20 +
9 files changed, 132 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-options
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">, Group, Visibility<[ClangOption, CC1Option, CLOption]>, HelpText<"Accept some non-standard constructs supported by the Microsoft compiler">, MarshallingInfoFlag>, ImpliedByAnyOf<[fms_compatibility.KeyPath]>; +def fms_anonymous_structs erichkeane wrote: Yes, we should still have it negate-able. We typically like to have that since we have a 'last one wins' sorta rule, which is important for folks who use build scripts. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 9c01511289217c605e37ca08ee4ccc554d8a9270 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH 1/8] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 6 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 20 +
9 files changed, 132 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-options
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 9c01511289217c605e37ca08ee4ccc554d8a9270 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH 1/7] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 6 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 20 +
9 files changed, 132 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-options
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">, Group, Visibility<[ClangOption, CC1Option, CLOption]>, HelpText<"Accept some non-standard constructs supported by the Microsoft compiler">, MarshallingInfoFlag>, ImpliedByAnyOf<[fms_compatibility.KeyPath]>; +def fms_anonymous_structs hubert-reinterpretcast wrote: > We probably want to be able to disable this as well, so probably need to use > BoolF. @erichkeane, it looks like the consensus so far is leaning towards a CC1-only option. In that case, is there still a strong desire for being able to disable this? Do you envision being able to enable Microsoft extensions in general without this specific extension? https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">, Group, Visibility<[ClangOption, CC1Option, CLOption]>, HelpText<"Accept some non-standard constructs supported by the Microsoft compiler">, MarshallingInfoFlag>, ImpliedByAnyOf<[fms_compatibility.KeyPath]>; +def fms_anonymous_structs erichkeane wrote: We probably want to be able to disable this as well, so probably need to use BoolF. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">, Group, Visibility<[ClangOption, CC1Option, CLOption]>, HelpText<"Accept some non-standard constructs supported by the Microsoft compiler">, MarshallingInfoFlag>, ImpliedByAnyOf<[fms_compatibility.KeyPath]>; +def fms_anonymous_structs +: Flag<["-"], "fms-anonymous-structs">, + Visibility<[CC1Option]>, + MarshallingInfoFlag>, + ImpliedByAnyOf<[fms_extensions.KeyPath, fms_compatibility.KeyPath]>, erichkeane wrote: Are both of these necessary? I would expect this to cascade from compatibility -> extensions -> here? https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,56 @@ +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-anonymous-structs +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-anonymous-structs +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-extensions +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous -fms-compatibility +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \ +// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis hubert-reinterpretcast wrote: Minor nit: Please indent the continuation lines. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,20 @@ +// Test that -fms-anonymous-structs is a CC1-only option and is accepted by CC1 without error. + +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=CC1-OK %s --allow-empty +// CC1-OK-NOT: error: unknown argument + +// Test that multiple occurrences are handled +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-anonymous-structs -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=MULTI-OK %s --allow-empty +// MULTI-OK-NOT: error: unknown argument hubert-reinterpretcast wrote: Can simply reuse the `CC1-OK` prefix. ```suggestion // RUN: FileCheck --check-prefix=CC1-OK %s --allow-empty ``` https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,20 @@ +// Test that -fms-anonymous-structs is a CC1-only option and is accepted by CC1 without error. + +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=CC1-OK %s --allow-empty +// CC1-OK-NOT: error: unknown argument + +// Test that multiple occurrences are handled +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-anonymous-structs -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=MULTI-OK %s --allow-empty +// MULTI-OK-NOT: error: unknown argument + +// Test with other MS-related options +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-extensions -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=WITH-MS-EXT %s --allow-empty +// WITH-MS-EXT-NOT: error: unknown argument hubert-reinterpretcast wrote: Same comment as above. ```suggestion // RUN: FileCheck --check-prefix=CC1-OK %s --allow-empty ``` https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/hubert-reinterpretcast edited https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/hubert-reinterpretcast approved this pull request. LGTM with minor nits; however, we still have the open question of whether this should be a CC1-only option. @MaskRay, do you have an opinion on whether this should be exposed via a Clang driver option (with or without a negative form)? https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
riyaz86a wrote: > > This change needs a release note. > > @cor3ntin, the current scope only adds a CC1 option. That does not warrant a > release note, does it? We'll add a release note if this ends up being a Clang > driver option. @hubert-reinterpretcast I just added release note for this option, will remove it if it's not required. New CC1 option ``-fms-anonymous-structs`` added to enable only Microsoft's anonymous struct/union extension without enabling other ``-fms-extensions`` features [GH177607]. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 9c01511289217c605e37ca08ee4ccc554d8a9270 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH 1/6] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 6 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 20 +
9 files changed, 132 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-options
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
hubert-reinterpretcast wrote: > This change needs a release note. @cor3ntin, the current scope only adds a CC1 option. That does not warrant a release note, does it? We'll add a release note if this ends up being a Clang driver option. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 9c01511289217c605e37ca08ee4ccc554d8a9270 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH 1/5] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 6 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 20 +
9 files changed, 132 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-options
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-anonymous-structs
+// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-anonymous-structs
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-extensions
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-compatibility
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis
+
+typedef struct notnested {
+ long bad1;
+ long bad2;
+} NOTNESTED;
+
+
+typedef struct nested1 {
+ long a;
+ struct notnested var1;
+ NOTNESTED var2;
+} NESTED1;
+
+struct nested2 {
+ long b;
+ NESTED1; // ms-anonymous-warning {{anonymous structs are a Microsoft
extension}}
+// ms-anonymous-dis-warning@-1 {{declaration does not declare
anything}}
+};
+
+struct nested2 PR20573 = { .a = 3 }; // ms-anonymous-dis-error {{field
designator 'a' does not refer to any field in type 'struct nested2'}}
+
+struct nested3 {
+ long d;
+ struct nested4 { // ms-anonymous-warning {{anonymous structs are a Microsoft
extension}}
+ // ms-anonymous-dis-warning@-1 {{declaration does not
declare anything}}
+long e;
+ };
+ union nested5 { // ms-anonymous-warning {{anonymous unions are a Microsoft
extension}}
+ // ms-anonymous-dis-warning@-1 {{declaration does not
declare anything}}
+long f;
+ };
+};
+
+typedef union nested6 {
+ long f;
+} NESTED6;
+
+struct test {
+ int c;
+ struct nested2; // ms-anonymous-warning {{anonymous structs are a
Microsoft extension}}
+// ms-anonymous-dis-warning@-1 {{declaration does not
declare anything}}
+ NESTED6; // ms-anonymous-warning {{anonymous unions are a Microsoft
extension}}
+// ms-anonymous-dis-warning@-1 {{declaration does not declare
anything}}
+};
+
+void foo(void)
+{
+ struct test var;
+ var.a; // ms-anonymous-dis-error {{no member named 'a' in 'struct
test'}}
+ var.b; // ms-anonymous-dis-error {{no member named 'b' in 'struct
test'}}
+ var.c;
+ var.bad1; // ms-anonymous-error {{no member named 'bad1' in 'struct test'}}
+ // ms-anonymous-dis-error@-1 {{no member named 'bad1' in 'struct
test'}}
+ var.bad2; // ms-anonymous-error {{no member named 'bad2' in 'struct test'}}
+ // ms-anonymous-dis-error@-1 {{no member named 'bad2' in 'struct
test'}}
+}
+
+// Enumeration types with a fixed underlying type.
+const int seventeen = 17;
+typedef int Int;
riyaz86a wrote:
removed this.
https://github.com/llvm/llvm-project/pull/176551
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-anonymous-structs
+// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-anonymous-structs
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-extensions
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-compatibility
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis
+
+typedef struct notnested {
+ long bad1;
+ long bad2;
+} NOTNESTED;
+
+
+typedef struct nested1 {
+ long a;
+ struct notnested var1;
+ NOTNESTED var2;
riyaz86a wrote:
I have reduced the test as per suggestion.
1. Simple MS anonymous structure case.
2. Simple MS anonymous union case.
3. One transitive case.
4. Access failure to anonymous structure member when Microsoft extension
disabled (-fms-anonymous-structs or -fms-extensions).
https://github.com/llvm/llvm-project/pull/176551
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-anonymous-structs
+// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-anonymous-structs
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-extensions
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-compatibility
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis
+
+typedef struct notnested {
+ long bad1;
+ long bad2;
+} NOTNESTED;
+
+
+typedef struct nested1 {
+ long a;
+ struct notnested var1;
+ NOTNESTED var2;
+} NESTED1;
+
+struct nested2 {
+ long b;
+ NESTED1; // ms-anonymous-warning {{anonymous structs are a Microsoft
extension}}
+// ms-anonymous-dis-warning@-1 {{declaration does not declare
anything}}
+};
+
+struct nested2 PR20573 = { .a = 3 }; // ms-anonymous-dis-error {{field
designator 'a' does not refer to any field in type 'struct nested2'}}
+
+struct nested3 {
+ long d;
+ struct nested4 { // ms-anonymous-warning {{anonymous structs are a Microsoft
extension}}
+ // ms-anonymous-dis-warning@-1 {{declaration does not
declare anything}}
+long e;
+ };
+ union nested5 { // ms-anonymous-warning {{anonymous unions are a Microsoft
extension}}
+ // ms-anonymous-dis-warning@-1 {{declaration does not
declare anything}}
+long f;
+ };
+};
+
+typedef union nested6 {
+ long f;
+} NESTED6;
+
+struct test {
+ int c;
+ struct nested2; // ms-anonymous-warning {{anonymous structs are a
Microsoft extension}}
+// ms-anonymous-dis-warning@-1 {{declaration does not
declare anything}}
+ NESTED6; // ms-anonymous-warning {{anonymous unions are a Microsoft
extension}}
+// ms-anonymous-dis-warning@-1 {{declaration does not declare
anything}}
+};
+
+void foo(void)
+{
+ struct test var;
+ var.a; // ms-anonymous-dis-error {{no member named 'a' in 'struct
test'}}
+ var.b; // ms-anonymous-dis-error {{no member named 'b' in 'struct
test'}}
+ var.c;
+ var.bad1; // ms-anonymous-error {{no member named 'bad1' in 'struct test'}}
+ // ms-anonymous-dis-error@-1 {{no member named 'bad1' in 'struct
test'}}
+ var.bad2; // ms-anonymous-error {{no member named 'bad2' in 'struct test'}}
+ // ms-anonymous-dis-error@-1 {{no member named 'bad2' in 'struct
test'}}
+}
+
+// Enumeration types with a fixed underlying type.
+const int seventeen = 17;
+typedef int Int;
+
+void pointer_to_integral_type_conv(char* ptr) {
+ char ch = (char)ptr;
+ short sh = (short)ptr;
+ ch = (char)ptr;
+ sh = (short)ptr;
+
+ // This is valid ISO C.
+ _Bool b = (_Bool)ptr;
+}
riyaz86a wrote:
Removed this block.
https://github.com/llvm/llvm-project/pull/176551
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 9c01511289217c605e37ca08ee4ccc554d8a9270 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH 1/4] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 6 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 20 +
9 files changed, 132 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-options
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-anonymous-structs
+// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-anonymous-structs
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-extensions
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-compatibility
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis
+
+typedef struct notnested {
+ long bad1;
+ long bad2;
+} NOTNESTED;
+
+
+typedef struct nested1 {
+ long a;
+ struct notnested var1;
+ NOTNESTED var2;
hubert-reinterpretcast wrote:
The functional changes in the PR do not warrant testing in so much detail (that
members of non-anonymous structs cannot be referenced as members of the
containing struct). On the other hand, if we were interested in testing for
that, the more interesting case is if there were only one non-anonymous struct
member of each struct type.
I suggest reducing the test to only one simple MS anonymous struct case, one
simple MS anonymous union case, and one transitive case. In particular, omit
the cases where an error is expected even when the extension is enabled.
https://github.com/llvm/llvm-project/pull/176551
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-anonymous-structs
+// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-anonymous-structs
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-extensions
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-compatibility
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis
+
+typedef struct notnested {
+ long bad1;
+ long bad2;
+} NOTNESTED;
+
+
+typedef struct nested1 {
+ long a;
+ struct notnested var1;
+ NOTNESTED var2;
+} NESTED1;
+
+struct nested2 {
+ long b;
+ NESTED1; // ms-anonymous-warning {{anonymous structs are a Microsoft
extension}}
+// ms-anonymous-dis-warning@-1 {{declaration does not declare
anything}}
+};
+
+struct nested2 PR20573 = { .a = 3 }; // ms-anonymous-dis-error {{field
designator 'a' does not refer to any field in type 'struct nested2'}}
+
+struct nested3 {
+ long d;
+ struct nested4 { // ms-anonymous-warning {{anonymous structs are a Microsoft
extension}}
+ // ms-anonymous-dis-warning@-1 {{declaration does not
declare anything}}
+long e;
+ };
+ union nested5 { // ms-anonymous-warning {{anonymous unions are a Microsoft
extension}}
+ // ms-anonymous-dis-warning@-1 {{declaration does not
declare anything}}
+long f;
+ };
+};
+
+typedef union nested6 {
+ long f;
+} NESTED6;
+
+struct test {
+ int c;
+ struct nested2; // ms-anonymous-warning {{anonymous structs are a
Microsoft extension}}
+// ms-anonymous-dis-warning@-1 {{declaration does not
declare anything}}
+ NESTED6; // ms-anonymous-warning {{anonymous unions are a Microsoft
extension}}
+// ms-anonymous-dis-warning@-1 {{declaration does not declare
anything}}
+};
+
+void foo(void)
+{
+ struct test var;
+ var.a; // ms-anonymous-dis-error {{no member named 'a' in 'struct
test'}}
+ var.b; // ms-anonymous-dis-error {{no member named 'b' in 'struct
test'}}
+ var.c;
+ var.bad1; // ms-anonymous-error {{no member named 'bad1' in 'struct test'}}
+ // ms-anonymous-dis-error@-1 {{no member named 'bad1' in 'struct
test'}}
+ var.bad2; // ms-anonymous-error {{no member named 'bad2' in 'struct test'}}
+ // ms-anonymous-dis-error@-1 {{no member named 'bad2' in 'struct
test'}}
+}
+
+// Enumeration types with a fixed underlying type.
+const int seventeen = 17;
+typedef int Int;
+
+void pointer_to_integral_type_conv(char* ptr) {
+ char ch = (char)ptr;
+ short sh = (short)ptr;
+ ch = (char)ptr;
+ sh = (short)ptr;
+
+ // This is valid ISO C.
+ _Bool b = (_Bool)ptr;
+}
hubert-reinterpretcast wrote:
This block seems irrelevant to the topic of this PR (albeit less confused).
https://github.com/llvm/llvm-project/pull/176551
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,99 @@
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-anonymous-structs
+// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-anonymous-structs
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-extensions
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous
-fms-compatibility
+// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value \
+// RUN: -Wno-pointer-to-int-cast -Wmicrosoft -verify=ms-anonymous-dis
+
+typedef struct notnested {
+ long bad1;
+ long bad2;
+} NOTNESTED;
+
+
+typedef struct nested1 {
+ long a;
+ struct notnested var1;
+ NOTNESTED var2;
+} NESTED1;
+
+struct nested2 {
+ long b;
+ NESTED1; // ms-anonymous-warning {{anonymous structs are a Microsoft
extension}}
+// ms-anonymous-dis-warning@-1 {{declaration does not declare
anything}}
+};
+
+struct nested2 PR20573 = { .a = 3 }; // ms-anonymous-dis-error {{field
designator 'a' does not refer to any field in type 'struct nested2'}}
+
+struct nested3 {
+ long d;
+ struct nested4 { // ms-anonymous-warning {{anonymous structs are a Microsoft
extension}}
+ // ms-anonymous-dis-warning@-1 {{declaration does not
declare anything}}
+long e;
+ };
+ union nested5 { // ms-anonymous-warning {{anonymous unions are a Microsoft
extension}}
+ // ms-anonymous-dis-warning@-1 {{declaration does not
declare anything}}
+long f;
+ };
+};
+
+typedef union nested6 {
+ long f;
+} NESTED6;
+
+struct test {
+ int c;
+ struct nested2; // ms-anonymous-warning {{anonymous structs are a
Microsoft extension}}
+// ms-anonymous-dis-warning@-1 {{declaration does not
declare anything}}
+ NESTED6; // ms-anonymous-warning {{anonymous unions are a Microsoft
extension}}
+// ms-anonymous-dis-warning@-1 {{declaration does not declare
anything}}
+};
+
+void foo(void)
+{
+ struct test var;
+ var.a; // ms-anonymous-dis-error {{no member named 'a' in 'struct
test'}}
+ var.b; // ms-anonymous-dis-error {{no member named 'b' in 'struct
test'}}
+ var.c;
+ var.bad1; // ms-anonymous-error {{no member named 'bad1' in 'struct test'}}
+ // ms-anonymous-dis-error@-1 {{no member named 'bad1' in 'struct
test'}}
+ var.bad2; // ms-anonymous-error {{no member named 'bad2' in 'struct test'}}
+ // ms-anonymous-dis-error@-1 {{no member named 'bad2' in 'struct
test'}}
+}
+
+// Enumeration types with a fixed underlying type.
+const int seventeen = 17;
+typedef int Int;
hubert-reinterpretcast wrote:
This block seems irrelevant to the topic of this PR and (based on the comment)
otherwise confused.
https://github.com/llvm/llvm-project/pull/176551
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -350,6 +350,9 @@ // WJoined: "-cc1" // WJoined: "-Wunused-pragmas" +// RUN: %clang_cl -c -fms-extensions -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-MS-ANON-STRUCT %s +// CHECK-MS-ANON-STRUCT: "-fms-extensions" "-fms-anonymous-structs" + riyaz86a wrote: removed this test. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -7156,8 +7156,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
riyaz86a wrote:
addressed this comment.
https://github.com/llvm/llvm-project/pull/176551
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,15 @@ +// Test that -fms-anonymous-structs is a CC1-only option and properly rejected by driver riyaz86a wrote: addressed this comment. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a edited https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,81 @@ +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value -Wno-pointer-to-int-cast -Wmicrosoft -verify -fms-anonymous-structs +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value -Wno-pointer-to-int-cast -Wmicrosoft -verify -fms-anonymous-structs riyaz86a wrote: > Add a RUN line that shows that explicitly using the negative form disables > the extension when the extension is otherwise enabled by some other mechanism. Regarding this test, As there is negative form of this option, Hence this test is not covered. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,81 @@ +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value -Wno-pointer-to-int-cast -Wmicrosoft -verify -fms-anonymous-structs +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value -Wno-pointer-to-int-cast -Wmicrosoft -verify -fms-anonymous-structs riyaz86a wrote: Added test for` -fms-compatibility` as well https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 9c01511289217c605e37ca08ee4ccc554d8a9270 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH 1/3] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 6 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 20 +
9 files changed, 132 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-options
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,15 @@ +// Test that -fms-anonymous-structs is a CC1-only option and properly rejected by driver + +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=CC1-OK %s --allow-empty +// CC1-OK-NOT: error: unknown argument + +// Test that multiple occurrences are handled +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-anonymous-structs -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=MULTI-OK %s --allow-empty +// MULTI-OK-NOT: error: unknown argument + +// Test with other MS-related options +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-extensions -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=WITH-MS-EXT %s --allow-empty +// WITH-MS-EXT-NOT: error: unknown argument hubert-reinterpretcast wrote: For the usage we intend to enable, I don't think we need to add a negative form if there isn't one. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a edited https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,15 @@ +// Test that -fms-anonymous-structs is a CC1-only option and properly rejected by driver + +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=CC1-OK %s --allow-empty +// CC1-OK-NOT: error: unknown argument + +// Test that multiple occurrences are handled +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-anonymous-structs -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=MULTI-OK %s --allow-empty +// MULTI-OK-NOT: error: unknown argument + +// Test with other MS-related options +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-extensions -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=WITH-MS-EXT %s --allow-empty +// WITH-MS-EXT-NOT: error: unknown argument riyaz86a wrote: There is no form of the option, can we add negative for on this option `-fno-ms-anonymous-structs` ? https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -350,6 +350,9 @@ // WJoined: "-cc1" // WJoined: "-Wunused-pragmas" +// RUN: %clang_cl -c -fms-extensions -### -- %s 2>&1 | FileCheck -check-prefix=CHECK-MS-ANON-STRUCT %s +// CHECK-MS-ANON-STRUCT: "-fms-extensions" "-fms-anonymous-structs" + hubert-reinterpretcast wrote: @riyaz86a, please remove this driver test too. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,15 @@ +// Test that -fms-anonymous-structs is a CC1-only option and properly rejected by driver + +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=CC1-OK %s --allow-empty +// CC1-OK-NOT: error: unknown argument + +// Test that multiple occurrences are handled +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-anonymous-structs -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=MULTI-OK %s --allow-empty +// MULTI-OK-NOT: error: unknown argument + +// Test with other MS-related options +// RUN: %clang_cc1 -triple powerpc-ibm-aix -fms-extensions -fms-anonymous-structs %s -fsyntax-only 2>&1 | \ +// RUN: FileCheck --check-prefix=WITH-MS-EXT %s --allow-empty +// WITH-MS-EXT-NOT: error: unknown argument hubert-reinterpretcast wrote: Is there a negative form of the option? Either we expect that it does not exist (and generates an error) or it should be tested as being accepted. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -25,6 +25,7 @@ // This needs to exit non-0, for configure scripts. // RUN: not %clang /GR- +// RUN: not %clang %s -fms-anonymous-structs -### 2>&1 | FileCheck %s --check-prefix=CL-MS-ERROR riyaz86a wrote: removed this test. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 9c01511289217c605e37ca08ee4ccc554d8a9270 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH 1/2] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 6 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 20 +
9 files changed, 132 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-options
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
hubert-reinterpretcast wrote:
@riyaz86a, thanks for confirming in our "offline" discussion that the
implication mechanism of `ImpliedByAnyOf` is sufficient. As discussed, please
remove the driver and driver test changes. Thanks.
https://github.com/llvm/llvm-project/pull/176551
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/hubert-reinterpretcast edited https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -0,0 +1,81 @@ +// RUN: %clang_cc1 -triple i686-windows %s -fsyntax-only -Wno-unused-value -Wno-pointer-to-int-cast -Wmicrosoft -verify -fms-anonymous-structs +// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -fsyntax-only -Wno-unused-value -Wno-pointer-to-int-cast -Wmicrosoft -verify -fms-anonymous-structs hubert-reinterpretcast wrote: If we can expect that `-fms-extensions` as a CC1 option enables the anonymous struct extension, then please test it here. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -190,6 +190,26 @@ TEST_F(CommandLineTest,
BoolOptionDefaultTrueSingleFlagPresent) {
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fno-temp-file")));
}
+TEST_F(CommandLineTest, MSAnonymousStructsFlagPresent) {
+ const char *Args[] = {"-cc1", "-fms-anonymous-structs"};
+
+ ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
+
+ EXPECT_TRUE(Invocation.getLangOpts().MSAnonymousStructs);
+
+ Invocation.generateCC1CommandLine(GeneratedArgs, *this);
+
+ ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fms-anonymous-structs")));
+}
+
+TEST_F(CommandLineTest, MSAnonymousStructsEnabledByMSExtensions) {
+ const char *Args[] = {"clang", "-fms-extensions"};
+
+ ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags));
+
+ EXPECT_TRUE(Invocation.getLangOpts().MSAnonymousStructs);
+}
+
hubert-reinterpretcast wrote:
Same comment as above re: not needing to update this test.
https://github.com/llvm/llvm-project/pull/176551
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/hubert-reinterpretcast commented: Some initial comments. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
@@ -25,6 +25,7 @@ // This needs to exit non-0, for configure scripts. // RUN: not %clang /GR- +// RUN: not %clang %s -fms-anonymous-structs -### 2>&1 | FileCheck %s --check-prefix=CL-MS-ERROR hubert-reinterpretcast wrote: I don't think updating this test is necessary. It is not commonly updated when new options are added. https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
llvmbot wrote:
@llvm/pr-subscribers-clang
Author: Riyaz Ahmad (riyaz86a)
Changes
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
Full diff: https://github.com/llvm/llvm-project/pull/176551.diff
9 Files Affected:
- (modified) clang/include/clang/Basic/LangOptions.def (+1)
- (modified) clang/include/clang/Options/Options.td (+6)
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+3-1)
- (modified) clang/lib/Sema/SemaDecl.cpp (+1-1)
- (modified) clang/test/Driver/cl-options.c (+3)
- (modified) clang/test/Driver/unknown-arg.c (+2)
- (added) clang/test/Frontend/ms-anon-structs-args.c (+15)
- (added) clang/test/Sema/MicrosoftAnonymousStructs.c (+81)
- (modified) clang/unittests/Frontend/CompilerInvocationTest.cpp (+20)
``diff
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 611d0d2927c43..f4ee39d3fc7d9 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -350,6 +350,9 @@
// WJoined: "-cc1"
// WJoined: "-Wunused-pragmas"
+// RUN: %clang_cl -c -fms-extensions -### -- %s 2>&1 | FileCheck
-check-prefix=CHECK-MS-ANON-S
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a ready_for_review https://github.com/llvm/llvm-project/pull/176551 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 13e881b2949f986dbd3cf82f8358c4aff0737f57 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 6 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 20 +
9 files changed, 132 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..5cdca7132e779 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ MarshallingInfoFlag>,
+ ImpliedByAnyOf<[fms_extensions.KeyPath]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..4f030c6ec649f 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if (Record && getLangOpts().MSAnonymousStructs) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-options.c b
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
github-actions[bot] wrote:
# :penguin: Linux x64 Test Results
* 85462 tests passed
* 1213 tests skipped
* 1 test failed
## Failed Tests
(click on a test name to see its output)
### Clang-Unit
Clang-Unit._/AllClangUnitTests/CommandLineTest/MSAnonymousStructsEnabledByMSExtensions
```
Script:
--
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/unittests/./AllClangUnitTests
--gtest_filter=CommandLineTest.MSAnonymousStructsEnabledByMSExtensions
--
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/unittests/Frontend/CompilerInvocationTest.cpp:210
Value of: Invocation.getLangOpts().MSAnonymousStructs
Actual: false
Expected: true
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/unittests/Frontend/CompilerInvocationTest.cpp:214
Value of: GeneratedArgs
Expected: contains at least one element that is equal to
"-fms-anonymous-structs"
Actual: { 0x38dde930 pointing to "-fsyntax-only", 0x38dde93e pointing to
"-x", 0x38dde941 pointing to "c", 0x38dde943 pointing to "clang", 0x38dde949
pointing to "-triple", 0x38dde951 pointing to "x86_64-unknown-linux-gnu",
0x38dde96a pointing to "-std=gnu17", 0x38dde975 pointing to "-fms-extensions",
0x38dde985 pointing to "-fno-convergent-functions", 0x38dde99f pointing to
"-ffp-contract=off", 0x38dde9b1 pointing to
"-fno-experimental-relative-c++-abi-vtables", 0x38dde9dc pointing to
"-fno-file-reproducible", 0x38dde9f3 pointing to "-O0", 0x38dde9f7 pointing to
"-fno-loop-interchange", 0x38ddea0d pointing to "-save-temps=obj", 0x38ddea1d
pointing to "-fdiagnostics-hotness-threshold=0", 0x38ddea3f pointing to
"-fdiagnostics-misexpect-tolerance=0" }
```
If these failures are unrelated to your changes (for example tests are broken
or flaky at HEAD), please open an issue at
https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.
https://github.com/llvm/llvm-project/pull/176551
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
github-actions[bot] wrote:
# :window: Windows x64 Test Results
* 51862 tests passed
* 908 tests skipped
* 1 test failed
## Failed Tests
(click on a test name to see its output)
### Clang-Unit
Clang-Unit._/AllClangUnitTests_exe/CommandLineTest/MSAnonymousStructsEnabledByMSExtensions
```
Script:
--
C:\_work\llvm-project\llvm-project\build\tools\clang\unittests\.\AllClangUnitTests.exe
--gtest_filter=CommandLineTest.MSAnonymousStructsEnabledByMSExtensions
--
C:\_work\llvm-project\llvm-project\clang\unittests\Frontend\CompilerInvocationTest.cpp:210
Value of: Invocation.getLangOpts().MSAnonymousStructs
Actual: false
Expected: true
C:\_work\llvm-project\llvm-project\clang\unittests\Frontend\CompilerInvocationTest.cpp:214
Value of: GeneratedArgs
Expected: contains at least one element that is equal to
"-fms-anonymous-structs"
Actual: { 023E9AA586B8 pointing to "-fsyntax-only", 023E9AA586C6
pointing to "-x", 023E9AA586C9 pointing to "c", 023E9AA586CB pointing
to "clang", 023E9AA586D1 pointing to "-triple", 023E9AA586D9 pointing
to "x86_64-pc-windows-msvc", 023E9AA586F0 pointing to "-std=gnu17",
023E9AA586FB pointing to "-fms-extensions", 023E9AA5870B pointing to
"-fno-convergent-functions", 023E9AA58725 pointing to "-ffp-contract=off",
023E9AA58737 pointing to "-fno-experimental-relative-c++-abi-vtables",
023E9AA58762 pointing to "-fno-file-reproducible", 023E9AA58779
pointing to "-O0", 023E9AA5877D pointing to "-fno-loop-interchange",
023E9AA58793 pointing to "-save-temps=obj", 023E9AA587A3 pointing to
"-fdiagnostics-hotness-threshold=0", 023E9AA587C5 pointing to
"-fdiagnostics-misexpect-tolerance=0" }
```
If these failures are unrelated to your changes (for example tests are broken
or flaky at HEAD), please open an issue at
https://github.com/llvm/llvm-project/issues and add the `infrastructure` label.
https://github.com/llvm/llvm-project/pull/176551
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From d1f68b116134570b1c826f9532a2a7ddf1e9b348 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 5 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 3 +-
clang/test/Driver/cl-options.c| 3 +
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 24 ++
9 files changed, 136 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..f6d128a4dd916 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,11 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">,
+ MarshallingInfoFlag>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..c2359c6c549d0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,8 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if ((Record && getLangOpts().MicrosoftExt) ||
+ (Record && getLangOpts().MSAnonymousStructs)) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-opti
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a updated
https://github.com/llvm/llvm-project/pull/176551
>From 94c0474bb850f65c62b8c75258118838fbec8434 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 5 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 3 +-
clang/test/Driver/cl-options.c| 5 +-
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 24 ++
9 files changed, 136 insertions(+), 4 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..f6d128a4dd916 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,11 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">,
+ MarshallingInfoFlag>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..c2359c6c549d0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5342,7 +5342,8 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S,
AccessSpecifier AS,
DS.getTypeSpecType() == DeclSpec::TST_typename) {
RecordDecl *Record = Tag ? dyn_cast(Tag)
: DS.getRepAsType().get()->getAsRecordDecl();
- if (Record && getLangOpts().MicrosoftExt) {
+ if ((Record && getLangOpts().MicrosoftExt) ||
+ (Record && getLangOpts().MSAnonymousStructs)) {
Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
diff --git a/clang/test/Driver/cl-opt
[clang] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to enable Microsoft anonymous struct/union feature (PR #176551)
https://github.com/riyaz86a created
https://github.com/llvm/llvm-project/pull/176551
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
>From 2c74e55d1695a5dc01c5380ae2d3ace1fbf2c9b6 Mon Sep 17 00:00:00 2001
From: Riyaz Ahmad
Date: Sat, 17 Jan 2026 04:16:28 -0500
Subject: [PATCH] [Frontend][Sema] Add CC1-only -fms-anonymous-structs to
enable Microsoft anonymous struct/union feature
Add a CC1-only option `-fms-anonymous-structs` to enable Microsoft anonymous
struct/union feature without enabling full Microsoft extensions.
Motivation:
- On AIX, some Microsoft extensions (e.g _ptr32) conflict with system headers.
- Certain code bases rely on Microsoft anonymous structs/unions behavior.
This new option allows selectively enabling the anonymous struct/union features
in
the front-end without triggering other Microsoft extensions features.
CC1 option can be passed via clang "-Xclang -fms-anonymous-structs".
Implementation:
- Introduced CC1-only option `-fms-anonymous-structs`.
- The option updates LangOpts::MSAnonymousStructs and Updated Sema to use
this flag.
- Added frontend, driver, and Sema tests.
---
clang/include/clang/Basic/LangOptions.def | 1 +
clang/include/clang/Options/Options.td| 5 ++
clang/lib/Driver/ToolChains/Clang.cpp | 4 +-
clang/lib/Sema/SemaDecl.cpp | 3 +-
clang/test/Driver/cl-options.c| 5 +-
clang/test/Driver/unknown-arg.c | 2 +
clang/test/Frontend/ms-anon-structs-args.c| 15
clang/test/Sema/MicrosoftAnonymousStructs.c | 81 +++
.../Frontend/CompilerInvocationTest.cpp | 24 ++
9 files changed, 136 insertions(+), 4 deletions(-)
create mode 100644 clang/test/Frontend/ms-anon-structs-args.c
create mode 100644 clang/test/Sema/MicrosoftAnonymousStructs.c
diff --git a/clang/include/clang/Basic/LangOptions.def
b/clang/include/clang/Basic/LangOptions.def
index 36fec24638363..4420cd942cac0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -47,6 +47,7 @@ LANGOPT(MSVCCompat, 1, 0, NotCompatible, "Microsoft
Visual C++ full comp
LANGOPT(Kernel, 1, 0, NotCompatible, "Kernel mode")
LANGOPT(MicrosoftExt , 1, 0, NotCompatible, "Microsoft C++ extensions")
LANGOPT(ZOSExt, 1, 0, NotCompatible, "z/OS extensions")
+LANGOPT(MSAnonymousStructs, 1, 0, NotCompatible, "Microsoft anonymous struct
and union extension")
LANGOPT(AsmBlocks , 1, 0, NotCompatible, "Microsoft inline asm blocks")
LANGOPT(Borland , 1, 0, NotCompatible, "Borland extensions")
LANGOPT(CPlusPlus , 1, 0, NotCompatible, "C++")
diff --git a/clang/include/clang/Options/Options.td
b/clang/include/clang/Options/Options.td
index 188739e72434a..f6d128a4dd916 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -3327,6 +3327,11 @@ def fms_extensions : Flag<["-"], "fms-extensions">,
Group,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Accept some non-standard constructs supported by the Microsoft
compiler">,
MarshallingInfoFlag>,
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_anonymous_structs
+: Flag<["-"], "fms-anonymous-structs">,
+ Visibility<[CC1Option]>,
+ HelpText<"Enable Microsoft anonymous struct/union extension.">,
+ MarshallingInfoFlag>;
defm asm_blocks : BoolFOption<"asm-blocks",
LangOpts<"AsmBlocks">, Default,
PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp
b/clang/lib/Driver/ToolChains/Clang.cpp
index 41ee88fd5501a..b0fd41e0a026e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7156,8 +7156,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction
&JA,
// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
- IsWindowsMSVC || IsUEFI))
+ IsWindowsMSVC || IsUEFI)) {
CmdArgs.push_back("-fms-extensions");
+CmdArgs.push_back("-fms-anonymous-structs");
+ }
// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ae779d6830d9b..c2359
