[PATCH] D127706: [Clang] Enable MSVC embedded records for Plan 9
Keegan Saunders via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 13 18:56:19 PDT 2022
ksaunders created this revision.
ksaunders added a reviewer: rsmith.
ksaunders added a project: clang.
Herald added a project: All.
ksaunders requested review of this revision.
Herald added a subscriber: cfe-commits.
This diff enables MSVC embedded records when Plan 9 extensions are enabled. As well, it creates the Plan 9 warning group.
Please see the initial Plan 9 diff for more details about this extension and more: https://reviews.llvm.org/D127462.
Aside: It's not clear if Clang developers prefer these incremental diffs, or one big diff. Let me know.
Depends On: https://reviews.llvm.org/D127462
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D127706
Files:
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/test/Sema/2c-anon-record.c
Index: clang/test/Sema/2c-anon-record.c
===================================================================
--- /dev/null
+++ clang/test/Sema/2c-anon-record.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wplan9 -verify -fplan9-extensions
+
+struct A {
+ int x;
+};
+
+struct B {
+ struct A; // expected-warning {{anonymous structs are a Plan 9 extension}}
+};
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -4989,8 +4989,10 @@
else if (const RecordType *UT = DS.getRepAsType().get()->getAsUnionType())
Record = UT->getDecl();
- if (Record && getLangOpts().MicrosoftExt) {
- Diag(DS.getBeginLoc(), diag::ext_ms_anonymous_record)
+ if (Record && (getLangOpts().MicrosoftExt || getLangOpts().Plan9)) {
+ Diag(DS.getBeginLoc(), getLangOpts().MicrosoftExt
+ ? diag::ext_ms_anonymous_record
+ : diag::ext_plan9_anonymous_record)
<< Record->isUnion() << DS.getSourceRange();
return BuildMicrosoftCAnonymousStruct(S, DS, Record);
}
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9011,6 +9011,9 @@
def ext_ms_anonymous_record : ExtWarn<
"anonymous %select{structs|unions}0 are a Microsoft extension">,
InGroup<MicrosoftAnonTag>;
+def ext_plan9_anonymous_record : ExtWarn<
+ "anonymous %select{structs|unions}0 are a Plan 9 extension">,
+ InGroup<Plan9AnonTag>;
// C++ local classes
def err_reference_to_local_in_enclosing_context : Error<
Index: clang/include/clang/Basic/DiagnosticGroups.td
===================================================================
--- clang/include/clang/Basic/DiagnosticGroups.td
+++ clang/include/clang/Basic/DiagnosticGroups.td
@@ -1133,6 +1133,12 @@
// A warning group for warnings about code that may be incompatible on AIX.
def AIXCompat : DiagGroup<"aix-compat">;
+// Warnings for Plan 9 extensions.
+def Plan9AnonTag : DiagGroup<"plan9-anon-tag">;
+
+// Warnings group for warnings about Plan 9 extensions.
+def Plan9 : DiagGroup<"plan9", [Plan9AnonTag]>;
+
// Warnings for Microsoft extensions.
def MicrosoftCharize : DiagGroup<"microsoft-charize">;
def MicrosoftDrectveSection : DiagGroup<"microsoft-drectve-section">;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127706.436619.patch
Type: text/x-patch
Size: 2529 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220614/c28a0e5e/attachment.bin>
More information about the cfe-commits
mailing list