[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From 5fb6768149bf2b4e7d74c4874e17dbf4e0e656b7 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Fri, 3 Nov 2023 21:18:06 -0400 Subject: [PATCH 1/2] [clang] Stub out gcc_struct attribute This commit implements gcc_struct attribute with the behavior similar to one in GCC. Current behavior is as follows: When C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This should provide enough compatibility with GCC. If C++ ABI is "Microsoft", [[gcc_struct]] will currently always be a no-op, since support for it is not yet implemented in MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure is ready for the future implementation. In particular, check for default value of -mms-bitfield is moved from a driver to TargetInfo, since it now non-trivially depends on other supplied flags. Also, unfortunately, this makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfield`. The patch doesn't introduce any not backwards-compatible changes, except for situations when cc1 is called directly on a target with -mms-bitfields being a default option. --- clang/include/clang/Basic/Attr.td | 7 + clang/include/clang/Basic/LangOptions.def | 1 - clang/include/clang/Basic/LangOptions.h | 2 ++ clang/include/clang/Basic/TargetInfo.h| 4 +++ clang/include/clang/Driver/Options.td | 4 +-- clang/lib/AST/Decl.cpp| 7 - clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 5 +--- clang/lib/Driver/ToolChains/Clang.cpp | 10 --- clang/lib/Frontend/CompilerInvocation.cpp | 12 + clang/lib/Sema/SemaDecl.cpp | 4 +-- clang/lib/Sema/SemaDeclCXX.cpp| 27 --- clang/test/Driver/ms-bitfields.c | 11 +--- clang/test/Layout/itanium-union-bitfield.cpp | 2 +- ...a-attribute-supported-attributes-list.test | 1 + 14 files changed, 69 insertions(+), 28 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 31434565becaec6..2685f6e0bc84f25 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3647,6 +3647,13 @@ def MSStruct : InheritableAttr { let SimpleHandler = 1; } +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; +} + def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index c541ccefdd5fbe1..1ac1e5c9eeffcf6 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -149,7 +149,6 @@ LANGOPT(AssumeNothrowExceptionDtor , 1, 0, "Assume exception object's destructor LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") -LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout") LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and stores") LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index ae99357eeea7f41..13277b253307093 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -502,6 +502,8 @@ class LangOptions : public LangOptionsBase { // received as a result of a standard operator new (-fcheck-new) bool CheckNew = false; + std::optional MSBitfields; + LangOptions(); /// Set language defaults for the given input language and diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 41f3c2e403cbef6..fc9555cf29cec7b 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1738,6 +1738,10 @@ class TargetInfo : public TransferrableTargetInfo, /// Whether to support HIP image/texture API's. virtual bool hasHIPImageSupport() const { return true; } + virtual bool defaultsToMsStruct() const { +return getCXXABI().isMicrosoft() || getTriple().isWindowsGNUEnvironment(); + } + protected: /// Copy type and layout related info. void copyAuxTarget(const TargetInfo *Aux); diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/O
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From 5fb6768149bf2b4e7d74c4874e17dbf4e0e656b7 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Fri, 3 Nov 2023 21:18:06 -0400 Subject: [PATCH 1/3] [clang] Stub out gcc_struct attribute This commit implements gcc_struct attribute with the behavior similar to one in GCC. Current behavior is as follows: When C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This should provide enough compatibility with GCC. If C++ ABI is "Microsoft", [[gcc_struct]] will currently always be a no-op, since support for it is not yet implemented in MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure is ready for the future implementation. In particular, check for default value of -mms-bitfield is moved from a driver to TargetInfo, since it now non-trivially depends on other supplied flags. Also, unfortunately, this makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfield`. The patch doesn't introduce any not backwards-compatible changes, except for situations when cc1 is called directly on a target with -mms-bitfields being a default option. --- clang/include/clang/Basic/Attr.td | 7 + clang/include/clang/Basic/LangOptions.def | 1 - clang/include/clang/Basic/LangOptions.h | 2 ++ clang/include/clang/Basic/TargetInfo.h| 4 +++ clang/include/clang/Driver/Options.td | 4 +-- clang/lib/AST/Decl.cpp| 7 - clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 5 +--- clang/lib/Driver/ToolChains/Clang.cpp | 10 --- clang/lib/Frontend/CompilerInvocation.cpp | 12 + clang/lib/Sema/SemaDecl.cpp | 4 +-- clang/lib/Sema/SemaDeclCXX.cpp| 27 --- clang/test/Driver/ms-bitfields.c | 11 +--- clang/test/Layout/itanium-union-bitfield.cpp | 2 +- ...a-attribute-supported-attributes-list.test | 1 + 14 files changed, 69 insertions(+), 28 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 31434565becaec6..2685f6e0bc84f25 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3647,6 +3647,13 @@ def MSStruct : InheritableAttr { let SimpleHandler = 1; } +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; +} + def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index c541ccefdd5fbe1..1ac1e5c9eeffcf6 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -149,7 +149,6 @@ LANGOPT(AssumeNothrowExceptionDtor , 1, 0, "Assume exception object's destructor LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") -LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout") LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and stores") LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index ae99357eeea7f41..13277b253307093 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -502,6 +502,8 @@ class LangOptions : public LangOptionsBase { // received as a result of a standard operator new (-fcheck-new) bool CheckNew = false; + std::optional MSBitfields; + LangOptions(); /// Set language defaults for the given input language and diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 41f3c2e403cbef6..fc9555cf29cec7b 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1738,6 +1738,10 @@ class TargetInfo : public TransferrableTargetInfo, /// Whether to support HIP image/texture API's. virtual bool hasHIPImageSupport() const { return true; } + virtual bool defaultsToMsStruct() const { +return getCXXABI().isMicrosoft() || getTriple().isWindowsGNUEnvironment(); + } + protected: /// Copy type and layout related info. void copyAuxTarget(const TargetInfo *Aux); diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/O
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: @rjmccall The problem will arise only if GCC implements support for MSVC C++ ABI and decides that there is a better way to implement `gcc_struct`. Since, AFAIC, MSVC-compatibility for GCC is not even planned, it's unlikely anybody there will have strong opinions on this. Yet I posted a question on gcc mailing list (https://gcc.gnu.org/pipermail/gcc/2023-December/242963.html) and, unsurprisingly, got no replies in a week. At the same time, I agree that inventing behavior for attributes in gnu:: namespace feels wrong. So, what do think about putting gcc_struct into `clang::` and disallowing `__attribute__((gcc_struct))`? Looks like this would require minimal changes: ```diff @@ -3672,7 +3672,7 @@ def MSStruct : InheritableAttr { } def GCCStruct : InheritableAttr { - let Spellings = [GCC<"gcc_struct">]; + let Spellings = [CXX11<"clang", "gcc_struct">, C23<"clang", "gcc_struct">]; let Subjects = SubjectList<[Record]>; let Documentation = [MSStructDocs]; // Covers this attribute too. let SimpleHandler = 1; ``` https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: Hmm, but `ms_struct` has been accepted on non-x86 for at least 5 years now. The PR merely adds a per-structure opt out toggle for it and, honestly, I don't see how GCC might implement it differently. https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
@@ -5031,7 +5031,12 @@ void RecordDecl::completeDefinition() { /// This which can be turned on with an attribute, pragma, or the /// -mms-bitfields command-line option. bool RecordDecl::isMsStruct(const ASTContext &C) const { - return hasAttr() || C.getLangOpts().MSBitfields == 1; + if (hasAttr()) +return true; + if (hasAttr()) +return false; + return C.getLangOpts().MSBitfields.value_or( DanShaders wrote: But there is no `TargetInfo` object when I set it in `CompilerInvocation::ParseLangArgs`. https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From 5fb6768149bf2b4e7d74c4874e17dbf4e0e656b7 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Fri, 3 Nov 2023 21:18:06 -0400 Subject: [PATCH 1/4] [clang] Stub out gcc_struct attribute This commit implements gcc_struct attribute with the behavior similar to one in GCC. Current behavior is as follows: When C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This should provide enough compatibility with GCC. If C++ ABI is "Microsoft", [[gcc_struct]] will currently always be a no-op, since support for it is not yet implemented in MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure is ready for the future implementation. In particular, check for default value of -mms-bitfield is moved from a driver to TargetInfo, since it now non-trivially depends on other supplied flags. Also, unfortunately, this makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfield`. The patch doesn't introduce any not backwards-compatible changes, except for situations when cc1 is called directly on a target with -mms-bitfields being a default option. --- clang/include/clang/Basic/Attr.td | 7 + clang/include/clang/Basic/LangOptions.def | 1 - clang/include/clang/Basic/LangOptions.h | 2 ++ clang/include/clang/Basic/TargetInfo.h| 4 +++ clang/include/clang/Driver/Options.td | 4 +-- clang/lib/AST/Decl.cpp| 7 - clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 5 +--- clang/lib/Driver/ToolChains/Clang.cpp | 10 --- clang/lib/Frontend/CompilerInvocation.cpp | 12 + clang/lib/Sema/SemaDecl.cpp | 4 +-- clang/lib/Sema/SemaDeclCXX.cpp| 27 --- clang/test/Driver/ms-bitfields.c | 11 +--- clang/test/Layout/itanium-union-bitfield.cpp | 2 +- ...a-attribute-supported-attributes-list.test | 1 + 14 files changed, 69 insertions(+), 28 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 31434565becaec6..2685f6e0bc84f25 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3647,6 +3647,13 @@ def MSStruct : InheritableAttr { let SimpleHandler = 1; } +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; +} + def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index c541ccefdd5fbe1..1ac1e5c9eeffcf6 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -149,7 +149,6 @@ LANGOPT(AssumeNothrowExceptionDtor , 1, 0, "Assume exception object's destructor LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") -LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout") LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and stores") LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index ae99357eeea7f41..13277b253307093 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -502,6 +502,8 @@ class LangOptions : public LangOptionsBase { // received as a result of a standard operator new (-fcheck-new) bool CheckNew = false; + std::optional MSBitfields; + LangOptions(); /// Set language defaults for the given input language and diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 41f3c2e403cbef6..fc9555cf29cec7b 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1738,6 +1738,10 @@ class TargetInfo : public TransferrableTargetInfo, /// Whether to support HIP image/texture API's. virtual bool hasHIPImageSupport() const { return true; } + virtual bool defaultsToMsStruct() const { +return getCXXABI().isMicrosoft() || getTriple().isWindowsGNUEnvironment(); + } + protected: /// Copy type and layout related info. void copyAuxTarget(const TargetInfo *Aux); diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/O
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
@@ -5031,7 +5031,12 @@ void RecordDecl::completeDefinition() { /// This which can be turned on with an attribute, pragma, or the /// -mms-bitfields command-line option. bool RecordDecl::isMsStruct(const ASTContext &C) const { - return hasAttr() || C.getLangOpts().MSBitfields == 1; + if (hasAttr()) +return true; + if (hasAttr()) +return false; + return C.getLangOpts().MSBitfields.value_or( DanShaders wrote: And, for example, for C++ ABI we do the same: https://github.com/llvm/llvm-project/blob/d19616fc66008ad128ecd21536c6e52992bea4e6/clang/lib/AST/ASTContext.cpp#L813-L816 https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
@@ -5031,7 +5031,12 @@ void RecordDecl::completeDefinition() { /// This which can be turned on with an attribute, pragma, or the /// -mms-bitfields command-line option. bool RecordDecl::isMsStruct(const ASTContext &C) const { - return hasAttr() || C.getLangOpts().MSBitfields == 1; + if (hasAttr()) +return true; + if (hasAttr()) +return false; + return C.getLangOpts().MSBitfields.value_or( DanShaders wrote: I still don't quite understand what you want. Yes, I can compute default value while parsing arguments, but I still will need `TargetInfo::defaultsToMsStruct`, since I use it in SemaDeclCxx. https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: @rjmccall Would you mind merging this then? (I don't have write access) https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From 5fb6768149bf2b4e7d74c4874e17dbf4e0e656b7 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Fri, 3 Nov 2023 21:18:06 -0400 Subject: [PATCH 1/5] [clang] Stub out gcc_struct attribute This commit implements gcc_struct attribute with the behavior similar to one in GCC. Current behavior is as follows: When C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This should provide enough compatibility with GCC. If C++ ABI is "Microsoft", [[gcc_struct]] will currently always be a no-op, since support for it is not yet implemented in MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure is ready for the future implementation. In particular, check for default value of -mms-bitfield is moved from a driver to TargetInfo, since it now non-trivially depends on other supplied flags. Also, unfortunately, this makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfield`. The patch doesn't introduce any not backwards-compatible changes, except for situations when cc1 is called directly on a target with -mms-bitfields being a default option. --- clang/include/clang/Basic/Attr.td | 7 + clang/include/clang/Basic/LangOptions.def | 1 - clang/include/clang/Basic/LangOptions.h | 2 ++ clang/include/clang/Basic/TargetInfo.h| 4 +++ clang/include/clang/Driver/Options.td | 4 +-- clang/lib/AST/Decl.cpp| 7 - clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 5 +--- clang/lib/Driver/ToolChains/Clang.cpp | 10 --- clang/lib/Frontend/CompilerInvocation.cpp | 12 + clang/lib/Sema/SemaDecl.cpp | 4 +-- clang/lib/Sema/SemaDeclCXX.cpp| 27 --- clang/test/Driver/ms-bitfields.c | 11 +--- clang/test/Layout/itanium-union-bitfield.cpp | 2 +- ...a-attribute-supported-attributes-list.test | 1 + 14 files changed, 69 insertions(+), 28 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 31434565becaec6..2685f6e0bc84f25 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3647,6 +3647,13 @@ def MSStruct : InheritableAttr { let SimpleHandler = 1; } +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; +} + def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index c541ccefdd5fbe1..1ac1e5c9eeffcf6 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -149,7 +149,6 @@ LANGOPT(AssumeNothrowExceptionDtor , 1, 0, "Assume exception object's destructor LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") -LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout") LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and stores") LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index ae99357eeea7f41..13277b253307093 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -502,6 +502,8 @@ class LangOptions : public LangOptionsBase { // received as a result of a standard operator new (-fcheck-new) bool CheckNew = false; + std::optional MSBitfields; + LangOptions(); /// Set language defaults for the given input language and diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 41f3c2e403cbef6..fc9555cf29cec7b 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1738,6 +1738,10 @@ class TargetInfo : public TransferrableTargetInfo, /// Whether to support HIP image/texture API's. virtual bool hasHIPImageSupport() const { return true; } + virtual bool defaultsToMsStruct() const { +return getCXXABI().isMicrosoft() || getTriple().isWindowsGNUEnvironment(); + } + protected: /// Copy type and layout related info. void copyAuxTarget(const TargetInfo *Aux); diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/O
[clang] [clang] Implement gcc_struct attribute (PR #71148)
https://github.com/DanShaders created https://github.com/llvm/llvm-project/pull/71148 This implements gcc_struct attribute with the behavior similar to one in GCC. In particular, when C++ ABI is not "Microsoft" (i. e. when ItaniumRecordBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This hopefully should provide compatibility with MinGW binaries. On the other hand, if C++ ABI is "Microsoft" and a record is annotated with [[gcc_struct]], we do not have any compatibility concerns, so I decided not to complicate MicrosoftRecordLayoutBuilder and just to fully switch record layout to GenericItanium. Note that -mno-ms-bitfields is no longer always a no-op. On `x86_64-pc-windows-msvc`, specifying only it should yield the same results as annotating all the records with [[gcc_struct]]. This makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfield` in a driver since MSBitfields now has a default value, which non-trivially depends on other supplied flags. Changes related to ms_struct should not hopefully cause any observable differences, thus the patch itself is fully backwards-compatible. Fixes #24757 >From 1912ae4453570bed3a0ba27d888d53d6c7324b3c Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Thu, 2 Nov 2023 23:49:54 -0400 Subject: [PATCH] [clang] Implement gcc_struct attribute This implements gcc_struct attribute with the behavior similar to one in GCC. In particular, when C++ ABI is not "Microsoft" (i. e. when ItaniumRecordBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This hopefully should provide compatibility with MinGW binaries. On the other hand, if C++ ABI is "Microsoft" and a record is annotated with [[gcc_struct]], we do not have any compatibility concerns, so I decided not to complicate MicrosoftRecordLayoutBuilder and just to fully switch record layout to GenericItanium. Note that -mno-ms-bitfields is no longer always a no-op. On `x86_64-pc-windows-msvc`, specifying only it should yield the same results as annotating all the records with [[gcc_struct]]. This makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfield` in a driver since MSBitfields now has a default value, which non-trivially depends on other supplied flags. Changes related to ms_struct should not hopefully cause any observable differences, thus the patch itself is fully backwards-compatible. --- clang/include/clang/Basic/Attr.td | 7 clang/include/clang/Basic/LangOptions.def | 1 - clang/include/clang/Basic/LangOptions.h | 2 + clang/include/clang/Basic/TargetInfo.h| 4 ++ clang/include/clang/Driver/Options.td | 4 +- clang/lib/AST/Decl.cpp| 9 +++- clang/lib/AST/RecordLayoutBuilder.cpp | 13 +++--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 8 ++-- clang/lib/Driver/ToolChains/Clang.cpp | 10 +++-- clang/lib/Frontend/CompilerInvocation.cpp | 12 ++ clang/lib/Sema/SemaDecl.cpp | 4 +- clang/lib/Sema/SemaDeclCXX.cpp| 9 +++- .../CodeGenCXX/ms-bitfield-class-layout.cpp | 41 +++ .../test/CodeGenCXX/ms_struct-gcc_struct.cpp | 29 + clang/test/Driver/ms-bitfields.c | 11 +++-- 15 files changed, 138 insertions(+), 26 deletions(-) create mode 100644 clang/test/CodeGenCXX/ms-bitfield-class-layout.cpp create mode 100644 clang/test/CodeGenCXX/ms_struct-gcc_struct.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 60b54c155e5..34ec6c22481837e 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3635,6 +3635,13 @@ def MSStruct : InheritableAttr { let SimpleHandler = 1; } +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; +} + def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index c0ea4ecb9806a5b..afbb3c724a8d193 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -148,7 +148,6 @@ LANGOPT(ExternCNoUnwind , 1, 0, "Assume extern C functions don't unwind") LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") -LANGOPT(MSBitfields , 1, 0, "M
[clang] [clang] Implement gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From ea8a7ea979ac54c91440dab75c9aa65f2f81e30f Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Thu, 2 Nov 2023 23:49:54 -0400 Subject: [PATCH] [clang] Implement gcc_struct attribute This implements gcc_struct attribute with the behavior similar to one in GCC. In particular, when C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This hopefully should provide compatibility with MinGW binaries. On the other hand, if C++ ABI is "Microsoft" and a record is annotated with [[gcc_struct]], we do not have any compatibility concerns, so I decided not to complicate MicrosoftRecordLayoutBuilder and just to fully switch record layout to GenericItanium. Note that -mno-ms-bitfields is no longer always a no-op. On `x86_64-pc-windows-msvc`, specifying only it should yield the same results as annotating all the records with [[gcc_struct]]. This makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfield` in a driver since MSBitfields now has a default value, which non-trivially depends on other supplied flags. Changes related to ms_struct hopefully should not cause any observable differences, thus the patch itself is fully backwards-compatible. --- clang/include/clang/Basic/Attr.td | 7 clang/include/clang/Basic/LangOptions.def | 1 - clang/include/clang/Basic/LangOptions.h | 2 + clang/include/clang/Basic/TargetInfo.h| 4 ++ clang/include/clang/Driver/Options.td | 4 +- clang/lib/AST/Decl.cpp| 9 +++- clang/lib/AST/RecordLayoutBuilder.cpp | 13 +++--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 8 ++-- clang/lib/Driver/ToolChains/Clang.cpp | 10 +++-- clang/lib/Frontend/CompilerInvocation.cpp | 12 ++ clang/lib/Sema/SemaDecl.cpp | 4 +- clang/lib/Sema/SemaDeclCXX.cpp| 9 +++- .../CodeGenCXX/ms-bitfield-class-layout.cpp | 41 +++ .../test/CodeGenCXX/ms_struct-gcc_struct.cpp | 29 + clang/test/Driver/ms-bitfields.c | 11 +++-- 15 files changed, 138 insertions(+), 26 deletions(-) create mode 100644 clang/test/CodeGenCXX/ms-bitfield-class-layout.cpp create mode 100644 clang/test/CodeGenCXX/ms_struct-gcc_struct.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 60b54c155e5..34ec6c22481837e 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3635,6 +3635,13 @@ def MSStruct : InheritableAttr { let SimpleHandler = 1; } +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; +} + def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index c0ea4ecb9806a5b..afbb3c724a8d193 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -148,7 +148,6 @@ LANGOPT(ExternCNoUnwind , 1, 0, "Assume extern C functions don't unwind") LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") -LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout") LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and stores") LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 20a8ada60e0fe51..07eae8dad61813c 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -502,6 +502,8 @@ class LangOptions : public LangOptionsBase { // received as a result of a standard operator new (-fcheck-new) bool CheckNew = false; + std::optional MSBitfields; + LangOptions(); /// Set language defaults for the given input language and diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index b3c5cbfb319f01f..6865b6e23bc9628 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1724,6 +1724,10 @@ class TargetInfo : public TransferrableTargetInfo, /// Whether to support HIP image/texture API's. virtual bool hasHIPImageSupport() const { return true; } + virtual bool defaultsToMsStruct
[clang] [clang] Implement gcc_struct attribute (PR #71148)
DanShaders wrote: Hmmm, formatting issues are in the code which I did not change. https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement gcc_struct attribute (PR #71148)
DanShaders wrote: And, I guess, CC @erichkeane https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From da5f4a4081c4917317549075f5d0916ebb26d0e9 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Thu, 2 Nov 2023 23:49:54 -0400 Subject: [PATCH] [clang] Implement gcc_struct attribute This implements gcc_struct attribute with the behavior similar to one in GCC. In particular, when C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This hopefully should provide compatibility with MinGW binaries. On the other hand, if C++ ABI is "Microsoft" and a record is annotated with [[gcc_struct]], we do not have any compatibility concerns, so I decided not to complicate MicrosoftRecordLayoutBuilder and just to fully switch record layout to GenericItanium. Note that -mno-ms-bitfields is no longer always a no-op. On `x86_64-pc-windows-msvc`, specifying only it should yield the same results as annotating all the records with [[gcc_struct]]. This makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfield` in a driver since MSBitfields now has a default value, which non-trivially depends on other supplied flags. Changes related to ms_struct hopefully should not cause any observable differences, thus the patch itself is fully backwards-compatible. --- clang/include/clang/Basic/Attr.td | 7 clang/include/clang/Basic/LangOptions.def | 1 - clang/include/clang/Basic/LangOptions.h | 2 + clang/include/clang/Basic/TargetInfo.h| 4 ++ clang/include/clang/Driver/Options.td | 4 +- clang/lib/AST/Decl.cpp| 9 +++- clang/lib/AST/RecordLayoutBuilder.cpp | 13 +++--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 8 ++-- clang/lib/Driver/ToolChains/Clang.cpp | 10 +++-- clang/lib/Frontend/CompilerInvocation.cpp | 12 ++ clang/lib/Sema/SemaDecl.cpp | 4 +- clang/lib/Sema/SemaDeclCXX.cpp| 9 +++- .../CodeGenCXX/ms-bitfield-class-layout.cpp | 41 +++ .../test/CodeGenCXX/ms_struct-gcc_struct.cpp | 29 + clang/test/Driver/ms-bitfields.c | 11 +++-- 15 files changed, 138 insertions(+), 26 deletions(-) create mode 100644 clang/test/CodeGenCXX/ms-bitfield-class-layout.cpp create mode 100644 clang/test/CodeGenCXX/ms_struct-gcc_struct.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 60b54c155e5..34ec6c22481837e 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3635,6 +3635,13 @@ def MSStruct : InheritableAttr { let SimpleHandler = 1; } +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; +} + def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index c0ea4ecb9806a5b..afbb3c724a8d193 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -148,7 +148,6 @@ LANGOPT(ExternCNoUnwind , 1, 0, "Assume extern C functions don't unwind") LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") -LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout") LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and stores") LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 20a8ada60e0fe51..07eae8dad61813c 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -502,6 +502,8 @@ class LangOptions : public LangOptionsBase { // received as a result of a standard operator new (-fcheck-new) bool CheckNew = false; + std::optional MSBitfields; + LangOptions(); /// Set language defaults for the given input language and diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index b3c5cbfb319f01f..6865b6e23bc9628 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1724,6 +1724,10 @@ class TargetInfo : public TransferrableTargetInfo, /// Whether to support HIP image/texture API's. virtual bool hasHIPImageSupport() const { return true; } + virtual bool defaultsToMsStruct
[clang] [clang] Implement gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From 7e268c2b4f5b48648acad08f6f188d27388b95f7 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Thu, 2 Nov 2023 23:49:54 -0400 Subject: [PATCH] [clang] Implement gcc_struct attribute This implements gcc_struct attribute with the behavior similar to one in GCC. In particular, when C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This hopefully should provide compatibility with MinGW binaries. On the other hand, if C++ ABI is "Microsoft" and a record is annotated with [[gcc_struct]], we do not have any compatibility concerns, so I decided not to complicate MicrosoftRecordLayoutBuilder and just to fully switch record layout to GenericItanium. Note that -mno-ms-bitfields is no longer always a no-op. On `x86_64-pc-windows-msvc`, specifying only it should yield the same results as annotating all the records with [[gcc_struct]]. This makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfield` in a driver since MSBitfields now has a default value, which non-trivially depends on other supplied flags. Changes related to ms_struct hopefully should not cause any observable differences, thus the patch itself is fully backwards-compatible. --- clang/include/clang/Basic/Attr.td | 7 clang/include/clang/Basic/LangOptions.def | 1 - clang/include/clang/Basic/LangOptions.h | 2 + clang/include/clang/Basic/TargetInfo.h| 4 ++ clang/include/clang/Driver/Options.td | 4 +- clang/lib/AST/Decl.cpp| 7 +++- clang/lib/AST/RecordLayoutBuilder.cpp | 13 +++--- clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 8 ++-- clang/lib/Driver/ToolChains/Clang.cpp | 10 +++-- clang/lib/Frontend/CompilerInvocation.cpp | 12 ++ clang/lib/Sema/SemaDecl.cpp | 4 +- clang/lib/Sema/SemaDeclCXX.cpp| 9 +++- .../CodeGenCXX/ms-bitfield-class-layout.cpp | 41 +++ .../test/CodeGenCXX/ms_struct-gcc_struct.cpp | 29 + clang/test/Driver/ms-bitfields.c | 11 +++-- 15 files changed, 137 insertions(+), 25 deletions(-) create mode 100644 clang/test/CodeGenCXX/ms-bitfield-class-layout.cpp create mode 100644 clang/test/CodeGenCXX/ms_struct-gcc_struct.cpp diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 60b54c155e5..34ec6c22481837e 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3635,6 +3635,13 @@ def MSStruct : InheritableAttr { let SimpleHandler = 1; } +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; +} + def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index c0ea4ecb9806a5b..afbb3c724a8d193 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -148,7 +148,6 @@ LANGOPT(ExternCNoUnwind , 1, 0, "Assume extern C functions don't unwind") LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") -LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout") LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and stores") LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 20a8ada60e0fe51..07eae8dad61813c 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -502,6 +502,8 @@ class LangOptions : public LangOptionsBase { // received as a result of a standard operator new (-fcheck-new) bool CheckNew = false; + std::optional MSBitfields; + LangOptions(); /// Set language defaults for the given input language and diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index b3c5cbfb319f01f..6865b6e23bc9628 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1724,6 +1724,10 @@ class TargetInfo : public TransferrableTargetInfo, /// Whether to support HIP image/texture API's. virtual bool hasHIPImageSupport() const { return true; } + virtual bool defaultsToMsStruct
[clang] [clang] Implement gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From 0d6728f06d7633b6b9ffaed45182dac0e54546ba Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Fri, 3 Nov 2023 21:18:06 -0400 Subject: [PATCH] [clang] Stub out gcc_struct attribute This commit implements gcc_struct attribute with the behavior similar to one in GCC. Current behavior is as follows: When C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This should provide enough compatibility with GCC. If C++ ABI is "Microsoft", [[gcc_struct]] will currently always be a no-op, since support for it is not yet implemented in MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure is ready for the future implementation. In particular, check for default value of -mms-bitfield is moved from a driver to TargetInfo, since it now non-trivially depends on other supplied flags. Also, unfortunately, this makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfield`. The patch doesn't introduce any not backwards-compatible changes, except for situations when cc1 is called directly on a target with -mms-bitfields being a default option. --- clang/include/clang/Basic/Attr.td| 7 + clang/include/clang/Basic/LangOptions.def| 1 - clang/include/clang/Basic/LangOptions.h | 2 ++ clang/include/clang/Basic/TargetInfo.h | 4 +++ clang/include/clang/Driver/Options.td| 4 +-- clang/lib/AST/Decl.cpp | 7 - clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 5 +--- clang/lib/Driver/ToolChains/Clang.cpp| 10 +--- clang/lib/Frontend/CompilerInvocation.cpp| 12 + clang/lib/Sema/SemaDecl.cpp | 4 +-- clang/lib/Sema/SemaDeclCXX.cpp | 27 clang/test/Driver/ms-bitfields.c | 11 +--- clang/test/Layout/itanium-union-bitfield.cpp | 2 +- 13 files changed, 68 insertions(+), 28 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 60b54c155e5..34ec6c22481837e 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3635,6 +3635,13 @@ def MSStruct : InheritableAttr { let SimpleHandler = 1; } +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; +} + def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index c0ea4ecb9806a5b..afbb3c724a8d193 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -148,7 +148,6 @@ LANGOPT(ExternCNoUnwind , 1, 0, "Assume extern C functions don't unwind") LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") -LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout") LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and stores") LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 20a8ada60e0fe51..07eae8dad61813c 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -502,6 +502,8 @@ class LangOptions : public LangOptionsBase { // received as a result of a standard operator new (-fcheck-new) bool CheckNew = false; + std::optional MSBitfields; + LangOptions(); /// Set language defaults for the given input language and diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index b3c5cbfb319f01f..6865b6e23bc9628 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1724,6 +1724,10 @@ class TargetInfo : public TransferrableTargetInfo, /// Whether to support HIP image/texture API's. virtual bool hasHIPImageSupport() const { return true; } + virtual bool defaultsToMsStruct() const { +return getCXXABI().isMicrosoft() || getTriple().isWindowsGNUEnvironment(); + } + protected: /// Copy type and layout related info. void copyAuxTarget(const TargetInfo *Aux); diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 9c0dcaa8b3f6276..d29214ed3cb13db 100644 --- a/clang/includ
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From 19124226ee4d08a8025f1e6b61d750096e13ee75 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Fri, 3 Nov 2023 21:18:06 -0400 Subject: [PATCH] [clang] Stub out gcc_struct attribute This commit implements gcc_struct attribute with the behavior similar to one in GCC. Current behavior is as follows: When C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This should provide enough compatibility with GCC. If C++ ABI is "Microsoft", [[gcc_struct]] will currently always be a no-op, since support for it is not yet implemented in MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure is ready for the future implementation. In particular, check for default value of -mms-bitfield is moved from a driver to TargetInfo, since it now non-trivially depends on other supplied flags. Also, unfortunately, this makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfield`. The patch doesn't introduce any not backwards-compatible changes, except for situations when cc1 is called directly on a target with -mms-bitfields being a default option. --- clang/include/clang/Basic/Attr.td | 7 + clang/include/clang/Basic/LangOptions.def | 1 - clang/include/clang/Basic/LangOptions.h | 2 ++ clang/include/clang/Basic/TargetInfo.h| 4 +++ clang/include/clang/Driver/Options.td | 4 +-- clang/lib/AST/Decl.cpp| 7 - clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 5 +--- clang/lib/Driver/ToolChains/Clang.cpp | 10 --- clang/lib/Frontend/CompilerInvocation.cpp | 12 + clang/lib/Sema/SemaDecl.cpp | 4 +-- clang/lib/Sema/SemaDeclCXX.cpp| 27 --- clang/test/Driver/ms-bitfields.c | 11 +--- clang/test/Layout/itanium-union-bitfield.cpp | 2 +- ...a-attribute-supported-attributes-list.test | 1 + 14 files changed, 69 insertions(+), 28 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 60b54c155e5..34ec6c22481837e 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3635,6 +3635,13 @@ def MSStruct : InheritableAttr { let SimpleHandler = 1; } +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; +} + def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index c0ea4ecb9806a5b..afbb3c724a8d193 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -148,7 +148,6 @@ LANGOPT(ExternCNoUnwind , 1, 0, "Assume extern C functions don't unwind") LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") -LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout") LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and stores") LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 20a8ada60e0fe51..07eae8dad61813c 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -502,6 +502,8 @@ class LangOptions : public LangOptionsBase { // received as a result of a standard operator new (-fcheck-new) bool CheckNew = false; + std::optional MSBitfields; + LangOptions(); /// Set language defaults for the given input language and diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index b3c5cbfb319f01f..6865b6e23bc9628 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1724,6 +1724,10 @@ class TargetInfo : public TransferrableTargetInfo, /// Whether to support HIP image/texture API's. virtual bool hasHIPImageSupport() const { return true; } + virtual bool defaultsToMsStruct() const { +return getCXXABI().isMicrosoft() || getTriple().isWindowsGNUEnvironment(); + } + protected: /// Copy type and layout related info. void copyAuxTarget(const TargetInfo *Aux); diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
@@ -4393,15 +4393,15 @@ def : Joined<["-"], "mmacosx-version-min=">, Group, Alias; def mms_bitfields : Flag<["-"], "mms-bitfields">, Group, Visibility<[ClangOption, CC1Option]>, - HelpText<"Set the default structure layout to be compatible with the Microsoft compiler standard">, - MarshallingInfoFlag>; + HelpText<"Set the default structure layout to be compatible with the Microsoft compiler standard">; DanShaders wrote: Once again, yes, I can theoretically use `BoolOption` and leave everything as it is. However, this requires computing default value for `-mms-bitfields` in driver, which is possible but requires code duplication and is in general less clean that the current solution. I provided some more details in the reply to rjmccall above. In case you are strongly against breaking the convention, I can alteranatively make both `-mms-bitfields` and `-mno-ms-bitfields` driver-only options and invent a new enum option for cc1 along the lines of `-flayout-compatiblity-type={default,microsoft,itanium}`. I should note, however, that this would only slightly change the way I pass arguments from the driver to cc1. https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From 1033441efd9e790bdb027824ffa1986cd09c06f2 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Fri, 3 Nov 2023 21:18:06 -0400 Subject: [PATCH 1/6] [clang] Stub out gcc_struct attribute This commit implements gcc_struct attribute with the behavior similar to one in GCC. Current behavior is as follows: When C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This should provide enough compatibility with GCC. If C++ ABI is "Microsoft", [[gcc_struct]] will currently always produce a diagnostic, since support for it is not yet implemented in MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure is ready for the future implementation. In particular, check for default value of -mms-bitfields is moved from a driver to TargetInfo, since it now non-trivially depends on other supplied flags. Also this, unfortunately, makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfields`. The patch doesn't introduce any backwards-incompatible changes, except for situations when cc1 is called directly with `-mms-bitfields` option. --- clang/include/clang/Basic/Attr.td | 7 + clang/include/clang/Basic/LangOptions.def | 1 - clang/include/clang/Basic/LangOptions.h | 2 ++ clang/include/clang/Basic/TargetInfo.h| 4 +++ clang/include/clang/Driver/Options.td | 4 +-- clang/lib/AST/Decl.cpp| 7 - clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 5 +--- clang/lib/Driver/ToolChains/Clang.cpp | 10 --- clang/lib/Frontend/CompilerInvocation.cpp | 12 + clang/lib/Sema/SemaDecl.cpp | 4 +-- clang/lib/Sema/SemaDeclCXX.cpp| 27 --- clang/test/Driver/ms-bitfields.c | 11 +--- clang/test/Layout/itanium-union-bitfield.cpp | 2 +- ...a-attribute-supported-attributes-list.test | 1 + 14 files changed, 69 insertions(+), 28 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 1800f584c7e1088..0d7e44d783bcc39 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3671,6 +3671,13 @@ def MSStruct : InheritableAttr { let SimpleHandler = 1; } +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; +} + def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index c3d5399905a3fda..5b0869a792d8785 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -149,7 +149,6 @@ LANGOPT(AssumeNothrowExceptionDtor , 1, 0, "Assume exception object's destructor LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") -LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout") LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and stores") LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 2d167dd2bdf1287..162929b90730b0e 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -507,6 +507,8 @@ class LangOptions : public LangOptionsBase { // implementation on real-world examples. std::string OpenACCMacroOverride; + std::optional MSBitfields; + LangOptions(); /// Set language defaults for the given input language and diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 41f3c2e403cbef6..fc9555cf29cec7b 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1738,6 +1738,10 @@ class TargetInfo : public TransferrableTargetInfo, /// Whether to support HIP image/texture API's. virtual bool hasHIPImageSupport() const { return true; } + virtual bool defaultsToMsStruct() const { +return getCXXABI().isMicrosoft() || getTriple().isWindowsGNUEnvironment(); + } + protected: /// Copy type and layout related info. void copyAuxTarget(const TargetInfo *Aux); diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 9689f12fd014
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From 1033441efd9e790bdb027824ffa1986cd09c06f2 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Fri, 3 Nov 2023 21:18:06 -0400 Subject: [PATCH 1/7] [clang] Stub out gcc_struct attribute This commit implements gcc_struct attribute with the behavior similar to one in GCC. Current behavior is as follows: When C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This should provide enough compatibility with GCC. If C++ ABI is "Microsoft", [[gcc_struct]] will currently always produce a diagnostic, since support for it is not yet implemented in MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure is ready for the future implementation. In particular, check for default value of -mms-bitfields is moved from a driver to TargetInfo, since it now non-trivially depends on other supplied flags. Also this, unfortunately, makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfields`. The patch doesn't introduce any backwards-incompatible changes, except for situations when cc1 is called directly with `-mms-bitfields` option. --- clang/include/clang/Basic/Attr.td | 7 + clang/include/clang/Basic/LangOptions.def | 1 - clang/include/clang/Basic/LangOptions.h | 2 ++ clang/include/clang/Basic/TargetInfo.h| 4 +++ clang/include/clang/Driver/Options.td | 4 +-- clang/lib/AST/Decl.cpp| 7 - clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 5 +--- clang/lib/Driver/ToolChains/Clang.cpp | 10 --- clang/lib/Frontend/CompilerInvocation.cpp | 12 + clang/lib/Sema/SemaDecl.cpp | 4 +-- clang/lib/Sema/SemaDeclCXX.cpp| 27 --- clang/test/Driver/ms-bitfields.c | 11 +--- clang/test/Layout/itanium-union-bitfield.cpp | 2 +- ...a-attribute-supported-attributes-list.test | 1 + 14 files changed, 69 insertions(+), 28 deletions(-) diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 1800f584c7e1088..0d7e44d783bcc39 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3671,6 +3671,13 @@ def MSStruct : InheritableAttr { let SimpleHandler = 1; } +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [Undocumented]; + let SimpleHandler = 1; +} + def DLLExport : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"dllexport">, GCC<"dllexport">]; let Subjects = SubjectList<[Function, Var, CXXRecord, ObjCInterface]>; diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index c3d5399905a3fda..5b0869a792d8785 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -149,7 +149,6 @@ LANGOPT(AssumeNothrowExceptionDtor , 1, 0, "Assume exception object's destructor LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation") LANGOPT(RTTI , 1, 1, "run-time type information") LANGOPT(RTTIData , 1, 1, "emit run-time type information data") -LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout") LANGOPT(MSVolatile, 1, 0, "Microsoft-compatible volatile loads and stores") LANGOPT(Freestanding, 1, 0, "freestanding implementation") LANGOPT(NoBuiltin , 1, 0, "disable builtin functions") diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 2d167dd2bdf1287..162929b90730b0e 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -507,6 +507,8 @@ class LangOptions : public LangOptionsBase { // implementation on real-world examples. std::string OpenACCMacroOverride; + std::optional MSBitfields; + LangOptions(); /// Set language defaults for the given input language and diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 41f3c2e403cbef6..fc9555cf29cec7b 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1738,6 +1738,10 @@ class TargetInfo : public TransferrableTargetInfo, /// Whether to support HIP image/texture API's. virtual bool hasHIPImageSupport() const { return true; } + virtual bool defaultsToMsStruct() const { +return getCXXABI().isMicrosoft() || getTriple().isWindowsGNUEnvironment(); + } + protected: /// Copy type and layout related info. void copyAuxTarget(const TargetInfo *Aux); diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 9689f12fd014
[clang] [clang][docs] Fix emphasis syntax in attribute documentation (PR #73737)
https://github.com/DanShaders created https://github.com/llvm/llvm-project/pull/73737 This causes CI failure for PRs updating `AttrDocs.td`. CC @llvm-beanz >From d30a251b2026065de3260f473b34c080102504e9 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Tue, 28 Nov 2023 22:04:47 -0500 Subject: [PATCH] [clang][docs] Fix emphasis syntax in attribute documentation --- clang/include/clang/Basic/AttrDocs.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index b7f366c29b77b48..bf89c5a941c3f89 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7073,7 +7073,7 @@ Parameters annotated with `in` or with no annotation are passed by value from the caller to the callee. Parameters annotated with `out` are written to the argument after the callee -returns (Note: arguments values passed into `out` parameters _are not_ copied +returns (Note: arguments values passed into `out` parameters *are not* copied into the callee). Parameters annotated with `inout` are copied into the callee via a temporary, ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][docs] Fix emphasis syntax in attribute documentation (PR #73737)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/73737 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: @MaskRay, I figured the alternative solution with the completely decoupled driver/frontend flags might actually be better than my initial approach. The only issue I see with it is that it requires `s/-mms-bitfields/-fms-layout-compatibility=microsoft/g` in quite a large number of tests which invoke frontend directly. Would you mind taking a look at this again? https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: @MaskRay > It does not make sense for MSVC. Let me share a bit of background here. While porting SerenityOS's libraries to Windows and, specifically, to `x86_64-pc-windows-msvc`, we discovered a few tests that were mysteriously failing. It turned out that the change in behavior was due to different bit-field layout algorithm used in Itanium and Microsoft C++ ABIs. After consulting the documentation, I figured `-mno-ms-bitfields` should fix this and all future bitfield-related problems on Windows, and the option indeed worked for the reduced testcase I had locally. Unfortunately, it didn't seem to make any difference elsewhere (because `-m{no,}ms-bitfields` is silently ignored for `windows-msvc` but I haven't known that at the time). So, in the end, we were forced to just work around the issue in a very ugly way (see SerenityOS/serenity#21722 and SerenityOS/serenity#21781). While we probably won't enable `-mno-ms-bitfields` globally even when the support for it will be implemented in `MicrosoftRecordLayoutBuilder`, I believe silently ignoring an option is not an acceptable solution (note that with this PR Clang will emit a diagnostic about unsupported layout compatibility type). Additionally, if one wraps all external (i.e., Windows) headers with `#pragma ms_struct on`, using them while compiling with `-mno-ms-bitfields` will be valid. > This patch changes getCXXABI().isMicrosoft() to use the -mms-bitfields > behavior (RecordDecl::isMsStruct), which is a drastic change. This won't change anything observable at all. When `getCXXABI().isMicrosoft()` is true, `RecordDecl::isMsStruct` returning true means using default (old) behavior. I specifically checked all its users and ensured this is the case. > For the gcc_struct feature request > https://github.com/llvm/llvm-project/issues/24757 , I believe it's for > windows-gnu triples, not for windows-msvc. As I said, supporting `[[gcc_struct]]` on `windows-msvc` will allow to get rid of hacks we have in Serenity. There is a similar issue in QEMU (https://gitlab.com/qemu-project/qemu/-/issues/1782#note_1495842591), albeit there they were talking about `windows-mingw`. On top of that, in the mentioned issue, Erich Keane seemed to indirectly acknowledge the need for `[[gcc_struct]]` for `windows-msvc`. > These introduce a lot complexity. It's not clear to me how to implement this in a simpler way. The requirements were the following: - I need default value for `-mms-bitfield` available in frontend to use it in SemaCXXDecl.cpp - I can't add `defaultsToMsStruct` to `llvm::Triple`, since its value also depends on `-fc++abi=` (which is partially ignored for `windows-msvc` but that's another story). - I don't want to calculate the default value in two places independently. - I need either to be able to query if `-m{no-,}ms-bitfields` was provided or to compute default value for it in driver. https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: @MaskRay > I am now confused by the subject "[clang] Stub out gcc_struct attribute". The user-facing change is `[[gcc_struct]]` attribute implemented for Itanium C++ ABI. Better handling of `-mms-bitfields` is just a byproduct. I agree that commit message should be more specific about changes to them. > `-mms-bitfields` wants to be supported by all architectures, or just x86 > Darwin targets. It's not like supporting `-mms-bitfields` for all targets adds a big maintenance burden. The architecture check you are talking about can be easily added in the future if proves to be needed. -- As Andrew said, I indeed was referring to code used by cross-platform Ladybird browser. Microsoft bit-field layout didn't break an overly-specific regression test but rendered unusable double to string conversion. The culprit was the following snippet: ```c++ union Extractor { double value; struct { bool sign : 1; u32 exponent : 11; u64 mantissa : 52; }; }; ``` According to MSVC ABI, there should be padding between fields. I hope you agree that this is not an intuitive and expected behavior. I later found that, in Wasi implementation, we have more bit-fields that rely on the absence of padding which are susceptible to the same problem (they look like `struct { bool flag1 : 1; bool flag2 : 1; u32 _unused : 30 };`). To fix them, we have to split single `_unused` field into 3 (and this field cannot be a transformed to a padding since we have to ensure it is zeroed). https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: Yes, I know by now :) But this requires using the same type for all the bit-fields which might lead to unnecessary casts in the algorithm itself. And the other case is not as easy to fix. https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: > Therefore I don't think it's too relevant to implement -mno-ms-bitfields for > MSVC targets (as I guess it could open a huge can of worms). I want to only alter the layout of explicit fields in the class with the future MSVC `-mno-ms-bitfields` implementation. This is always save to do without worrying much about other parts of the compiler. I should stress that regardless of original motivation the additional complexity of `-fms-layout-compatibility` makes checks in a few other places easier to follow. Also, do we want to support `--target=x86_64-pc-windows-msvc -fc++-abi=itanium -mms-bitfields`? If so, it would be much simpler with my approach. https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: One more thing. Re binary compatibility concerns: `-mno-ms-bitfields` on MinGW is an equally-sized footgun as on MSVC. Without proper header annotation with `#pragma ms_struct on`, either of them will silently make an ABI mismatch. However, for some reason, supporting `-mno-ms-bitfields` on MinGW is not argued upon. https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: Okay, @mstorsjo @MaskRay, what is the way forward? Am I right that, as for the user-facing changes, `[[gcc_struct]]` cancelling implicit `-mms-bitfilds` on MinGW is fine and silently ignoring `-m{no-}ms-bitfields` on `windows-msvc` is not? When exactly should we disallow `-m{no-,}ms-bitfields`? Should the aforementioned `--target=x86_64-pc-windows-msvc -fc++-abi=itanium -mms-bitfields` be accepted? Is it fine to provide `[[gcc_struct]]` on MSVC because of reasons I outlined before? https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From d0484b032b13109a226c088f18cf0ccd6026bceb Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Fri, 3 Nov 2023 21:18:06 -0400 Subject: [PATCH] [clang] Stub out gcc_struct attribute This commit implements gcc_struct attribute with the behavior similar to one in GCC. Current behavior is as follows: When C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This should provide enough compatibility with GCC. If C++ ABI is "Microsoft", [[gcc_struct]] will currently always produce a diagnostic, since support for it is not yet implemented in MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure is ready for the future implementation. In particular, check for default value of -mms-bitfields is moved from a driver to TargetInfo, since it now non-trivially depends on other supplied flags. Also this, unfortunately, makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfields`. The patch doesn't introduce any backwards-incompatible changes, except for situations when cc1 is called directly with `-mms-bitfields` option. --- clang/docs/ReleaseNotes.rst | 6 clang/include/clang/Basic/Attr.td | 9 +- clang/include/clang/Basic/AttrDocs.td | 16 +++ .../include/clang/Basic/DiagnosticASTKinds.td | 3 ++ clang/include/clang/Basic/LangOptions.def | 3 +- clang/include/clang/Basic/LangOptions.h | 10 +++ clang/include/clang/Basic/TargetInfo.h| 4 +++ clang/include/clang/Driver/Options.td | 10 +-- clang/lib/AST/Decl.cpp| 9 +- clang/lib/AST/RecordLayoutBuilder.cpp | 7 + clang/lib/Driver/ToolChains/Clang.cpp | 10 +-- clang/lib/Sema/SemaDecl.cpp | 4 +-- clang/lib/Sema/SemaDeclCXX.cpp| 28 --- clang/test/CodeGen/mingw-long-double.c| 2 +- clang/test/CodeGen/mms-bitfields.c| 2 +- clang/test/Driver/ms-bitfields.c | 19 + clang/test/Layout/itanium-union-bitfield.cpp | 2 +- ...a-attribute-supported-attributes-list.test | 1 + clang/test/Sema/mms-bitfields.c | 2 +- clang/test/SemaCXX/ms_struct.cpp | 2 +- clang/test/SemaCXX/ms_wide_bitfield.cpp | 2 +- 21 files changed, 117 insertions(+), 34 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 64a9fe0d8bcc48e..241afec03ad8335 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -201,6 +201,12 @@ Attribute Changes in Clang and each must be a positive integer when provided. The parameter ``x`` is required, while ``y`` and ``z`` are optional with default value of 1. +- On targets with Itanium C++ ABI, Clang now supports ``[[gnu:gcc_struct]]`` + with the behavior similar to one existing in GCC. In particular, whenever + ``-mms-bitfields`` command line option is provided (or if Microsoft-compatible + structure layout is default on the target), ``[[gnu::gcc_struct]]`` requests + the compiler to follow Itanium rules for the layout of an annotated structure. + Improvements to Clang's diagnostics --- - Clang now applies syntax highlighting to the code snippets it diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 63efd85dcd4e58e..ce10409b2e2c05d 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3824,7 +3824,14 @@ def CFGuard : InheritableAttr, TargetSpecificAttr { def MSStruct : InheritableAttr { let Spellings = [GCC<"ms_struct">]; let Subjects = SubjectList<[Record]>; - let Documentation = [Undocumented]; + let Documentation = [MSStructDocs]; + let SimpleHandler = 1; +} + +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [MSStructDocs]; // Covers this attribute too. let SimpleHandler = 1; } diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index d61f96ade557d54..b28d2144bdb2195 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -8000,3 +8000,19 @@ requirement: } }]; } + +def MSStructDocs : Documentation { + let Category = DocCatDecl; + let Content = [{ +The ``ms_struct`` and ``gcc_struct`` attributes request the compiler to enter a +special record layout compatibility mode which mimics the layout of Microsoft or +Itanium C++ ABI respectively. Obviously, if the current C++ ABI matches the +requested ABI, the attribute does nothing. However, if it does not, annotated +structure or class
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: @rjmccall Re asking GCC developers about gcc_struct on non-x86: https://gcc.gnu.org/pipermail/gcc/2024-January/243154.html. Either GCC devs aren't really worried about this or I can't properly write emails (what's totally possible). @MaskRay Any chance you can look at this PR again? Will you be more happy if instead of `-fms-layout-compatibility` there will be a copy of `TargetInfo::defaultsToMsStruct` in the driver? https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From b26dd88d456cff7f412cdff6126d0e48454d9eb9 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Fri, 3 Nov 2023 21:18:06 -0400 Subject: [PATCH] [clang] Stub out gcc_struct attribute This commit implements gcc_struct attribute with the behavior similar to one in GCC. Current behavior is as follows: When C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This should provide enough compatibility with GCC. If C++ ABI is "Microsoft", [[gcc_struct]] will currently always produce a diagnostic, since support for it is not yet implemented in MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure is ready for the future implementation. In particular, check for default value of -mms-bitfields is moved from a driver to TargetInfo, since it now non-trivially depends on other supplied flags. Also this, unfortunately, makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfields`. The patch doesn't introduce any backwards-incompatible changes, except for situations when cc1 is called directly with `-mms-bitfields` option. --- clang/docs/ReleaseNotes.rst | 6 clang/include/clang/Basic/Attr.td | 9 +- clang/include/clang/Basic/AttrDocs.td | 16 +++ .../include/clang/Basic/DiagnosticASTKinds.td | 3 ++ clang/include/clang/Basic/LangOptions.def | 3 +- clang/include/clang/Basic/LangOptions.h | 10 +++ clang/include/clang/Basic/TargetInfo.h| 4 +++ clang/include/clang/Driver/Options.td | 10 +-- clang/lib/AST/Decl.cpp| 9 +- clang/lib/AST/RecordLayoutBuilder.cpp | 7 + clang/lib/CodeGen/CGRecordLayoutBuilder.cpp | 5 +--- clang/lib/Driver/ToolChains/Clang.cpp | 10 +-- clang/lib/Sema/SemaDecl.cpp | 4 +-- clang/lib/Sema/SemaDeclCXX.cpp| 28 --- clang/test/CodeGen/mingw-long-double.c| 2 +- clang/test/CodeGen/mms-bitfields.c| 2 +- clang/test/Driver/ms-bitfields.c | 19 + clang/test/Layout/itanium-union-bitfield.cpp | 2 +- ...a-attribute-supported-attributes-list.test | 1 + clang/test/Sema/mms-bitfields.c | 2 +- clang/test/SemaCXX/ms_struct.cpp | 2 +- clang/test/SemaCXX/ms_wide_bitfield.cpp | 2 +- 22 files changed, 118 insertions(+), 38 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3cbce1be159437..a089a8586659dd 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -397,6 +397,12 @@ Attribute Changes in Clang returns a type annotated with ``[[clang::coro_lifetimebound]]`` and ``[[clang::coro_return_type]]``. This analysis can be disabled for a function by annotating the function with ``[[clang::coro_disable_lifetimebound]]``. +- On targets with Itanium C++ ABI, Clang now supports ``[[gnu:gcc_struct]]`` + with the behavior similar to one existing in GCC. In particular, whenever + ``-mms-bitfields`` command line option is provided (or if Microsoft-compatible + structure layout is default on the target), ``[[gnu::gcc_struct]]`` requests + the compiler to follow Itanium rules for the layout of an annotated structure. + Improvements to Clang's diagnostics --- - Clang constexpr evaluator now prints template arguments when displaying diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index a03b0e44e15f7d..50157fb2f08fd9 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3711,7 +3711,14 @@ def CFGuard : InheritableAttr, TargetSpecificAttr { def MSStruct : InheritableAttr { let Spellings = [GCC<"ms_struct">]; let Subjects = SubjectList<[Record]>; - let Documentation = [Undocumented]; + let Documentation = [MSStructDocs]; + let SimpleHandler = 1; +} + +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gcc_struct">]; + let Subjects = SubjectList<[Record]>; + let Documentation = [MSStructDocs]; // Covers this attribute too. let SimpleHandler = 1; } diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 2e8d7752c9751e..cafc867bec21f4 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7827,3 +7827,19 @@ requirement: } }]; } + +def MSStructDocs : Documentation { + let Category = DocCatDecl; + let Content = [{ +The ``ms_struct`` and ``gcc_struct`` attributes request the compiler to enter a +special record layout compatibility mode which mimics the layout of Microsoft or +Itanium C++ ABI respectively. Obviou
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: @MaskRay Bump https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][X86] Fix -Wundef warning in cpuid.h (PR #89842)
https://github.com/DanShaders created https://github.com/llvm/llvm-project/pull/89842 Caught by compiling a project (SerenityOS) that uses compiler-rt and not silencing warnings from system headers. >From 8c924ea810352c27bffaf1ac30bbe4ad4ffbadc2 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Tue, 23 Apr 2024 18:41:16 -0400 Subject: [PATCH] [clang][X86] Fix -Wundef warning in cpuid.h Caught by compiling a project (SerenityOS) that uses compiler-rt and not silencing warnings from system headers. --- clang/lib/Headers/cpuid.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h index 0bb9912b465ffe..bb7692efb78ffe 100644 --- a/clang/lib/Headers/cpuid.h +++ b/clang/lib/Headers/cpuid.h @@ -10,7 +10,7 @@ #ifndef __CPUID_H #define __CPUID_H -#if !(__x86_64__ || __i386__) +#if !defined(__x86_64__) && !defined(__i386__) #error this header is for x86 only #endif @@ -256,7 +256,7 @@ #define bit_AVX10_256 0x0002 #define bit_AVX10_512 0x0004 -#if __i386__ +#ifdef __i386__ #define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \ __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \ : "0"(__leaf)) @@ -285,7 +285,7 @@ static __inline unsigned int __get_cpuid_max (unsigned int __leaf, unsigned int *__sig) { unsigned int __eax, __ebx, __ecx, __edx; -#if __i386__ +#ifdef __i386__ int __cpuid_supported; __asm(" pushfl\n" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Do not allow unorderable features in [[gnu::target{,_clones}]] (PR #98426)
https://github.com/DanShaders created https://github.com/llvm/llvm-project/pull/98426 This partially addresses #98244. >From a8ddcb19d5fb2bb6a846c7a33f2c90c580d212fe Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Wed, 10 Jul 2024 23:39:42 -0400 Subject: [PATCH] [clang] Do not allow unorderable features in [[gnu::target{,_clones}]] This partially addresses #98244. --- clang/lib/Sema/SemaDecl.cpp | 4 +++- clang/lib/Sema/SemaDeclAttr.cpp | 3 ++- clang/test/Sema/attr-target-clones.c | 3 +++ clang/test/Sema/attr-target-mv.c | 14 ++ clang/test/Sema/attr-target.c| 2 ++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d1c7b9d5ae507..4d0c2cfaee965 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -10958,7 +10958,9 @@ static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD) { } if (!TargetInfo.validateCpuSupports(BareFeat) || - !TargetInfo.isValidFeatureName(BareFeat)) { + !TargetInfo.isValidFeatureName(BareFeat) || + (BareFeat != "default" && + TargetInfo.multiVersionSortPriority(BareFeat) == 0)) { S.Diag(FD->getLocation(), diag::err_bad_multiversion_option) << Feature << BareFeat; return true; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index f2cd46d1e7c93..7e857369c1042 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3138,7 +3138,8 @@ bool Sema::checkTargetClonesAttrString( } else if (Cur == "default") { DefaultIsDupe = HasDefault; HasDefault = true; - } else if (!Context.getTargetInfo().isValidFeatureName(Cur)) + } else if (!Context.getTargetInfo().isValidFeatureName(Cur) || + Context.getTargetInfo().multiVersionSortPriority(Cur) == 0) return Diag(CurLoc, diag::warn_unsupported_target_attribute) << Unsupported << None << Cur << TargetClones; if (llvm::is_contained(StringsBuffer, Cur) || DefaultIsDupe) diff --git a/clang/test/Sema/attr-target-clones.c b/clang/test/Sema/attr-target-clones.c index e287fce7699b7..4597ea54d02bf 100644 --- a/clang/test/Sema/attr-target-clones.c +++ b/clang/test/Sema/attr-target-clones.c @@ -122,3 +122,6 @@ void good_overload5(int) __attribute__((target_clones("mmx", "sse4.2", "default" void good_isa_level(int) __attribute__((target_clones("default", "arch=x86-64", "arch=x86-64-v2", "arch=x86-64-v3", "arch=x86-64-v4"))); // expected-warning@+1 {{unsupported CPU 'x86-64-v5' in the 'target_clones' attribute string; 'target_clones' attribute ignored}} void bad_isa_level(int) __attribute__((target_clones("default", "arch=x86-64-v5"))); + +// expected-warning@+1 {{unsupported 'sha' in the 'target_clones' attribute string; 'target_clones' attribute ignored}} +void bad_feature(void) __attribute__((target_clones("default", "sse4.2", "sha"))); diff --git a/clang/test/Sema/attr-target-mv.c b/clang/test/Sema/attr-target-mv.c index 8218771275e1b..ddb1d82b02f09 100644 --- a/clang/test/Sema/attr-target-mv.c +++ b/clang/test/Sema/attr-target-mv.c @@ -170,3 +170,17 @@ int __attribute__((__overloadable__)) __attribute__((target("arch=sandybridge")) int __attribute__((__overloadable__)) __attribute__((target("sse4.2"))) good_overload7(void); int __attribute__((target("arch=sandybridge"))) good_overload7(int); + +// expected-error@+2 {{function multiversioning doesn't support feature 'sha'}} +// expected-note@+2 {{function multiversioning caused by this declaration}} +int __attribute__((target("sha"))) no_priority1(void); +int __attribute__((target("default"))) no_priority1(void); + +int __attribute__((target("default"))) no_priority2(void); +// expected-error@+1 {{function multiversioning doesn't support feature 'sha'}} +int __attribute__((target("sha"))) no_priority2(void); + +int __attribute__((target("default"))) no_priority3(void); +int __attribute__((target("avx2"))) no_priority3(void); +// expected-error@+1 {{function multiversioning doesn't support feature 'sha'}} +int __attribute__((target("sha"))) no_priority3(void); diff --git a/clang/test/Sema/attr-target.c b/clang/test/Sema/attr-target.c index 5328f056507a7..65ece3c27d299 100644 --- a/clang/test/Sema/attr-target.c +++ b/clang/test/Sema/attr-target.c @@ -33,6 +33,8 @@ void __attribute__((target("x86-64"))) baseline(void) {} //expected-warning@+1 {{unsupported 'x86-64-v2' in the 'target' attribute string}} void __attribute__((target("x86-64-v2"))) v2(void) {} +int __attribute__((target("sha"))) good_target_but_not_for_fmv() { return 5; } + #elifdef __aarch64__ int __attribute__((target("sve,arch=armv8-a"))) foo(void) { return 4; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Do not allow unorderable features in [[gnu::target{,_clones}]] (PR #98426)
DanShaders wrote: CC @FreddyLeaf, @phoebewang https://github.com/llvm/llvm-project/pull/98426 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Do not allow unorderable features in [[gnu::target{,_clones}]] (PR #98426)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/98426 >From 6ac4e250788570f4155108ef3baa1fa3532a67fa Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Wed, 10 Jul 2024 23:39:42 -0400 Subject: [PATCH] [clang] Do not allow unorderable features in [[gnu::target{,_clones}]] This partially addresses #98244. --- clang/lib/Sema/SemaDecl.cpp | 4 +++- clang/lib/Sema/SemaDeclAttr.cpp | 3 ++- clang/test/Sema/attr-target-clones.c | 3 +++ clang/test/Sema/attr-target-mv.c | 14 ++ clang/test/Sema/attr-target.c| 2 ++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 66eeaa8e6f777..984e0456f27ec 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -10958,7 +10958,9 @@ static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD) { } if (!TargetInfo.validateCpuSupports(BareFeat) || - !TargetInfo.isValidFeatureName(BareFeat)) { + !TargetInfo.isValidFeatureName(BareFeat) || + (BareFeat != "default" && + TargetInfo.multiVersionSortPriority(BareFeat) == 0)) { S.Diag(FD->getLocation(), diag::err_bad_multiversion_option) << Feature << BareFeat; return true; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index f2cd46d1e7c93..7e857369c1042 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3138,7 +3138,8 @@ bool Sema::checkTargetClonesAttrString( } else if (Cur == "default") { DefaultIsDupe = HasDefault; HasDefault = true; - } else if (!Context.getTargetInfo().isValidFeatureName(Cur)) + } else if (!Context.getTargetInfo().isValidFeatureName(Cur) || + Context.getTargetInfo().multiVersionSortPriority(Cur) == 0) return Diag(CurLoc, diag::warn_unsupported_target_attribute) << Unsupported << None << Cur << TargetClones; if (llvm::is_contained(StringsBuffer, Cur) || DefaultIsDupe) diff --git a/clang/test/Sema/attr-target-clones.c b/clang/test/Sema/attr-target-clones.c index e287fce7699b7..4597ea54d02bf 100644 --- a/clang/test/Sema/attr-target-clones.c +++ b/clang/test/Sema/attr-target-clones.c @@ -122,3 +122,6 @@ void good_overload5(int) __attribute__((target_clones("mmx", "sse4.2", "default" void good_isa_level(int) __attribute__((target_clones("default", "arch=x86-64", "arch=x86-64-v2", "arch=x86-64-v3", "arch=x86-64-v4"))); // expected-warning@+1 {{unsupported CPU 'x86-64-v5' in the 'target_clones' attribute string; 'target_clones' attribute ignored}} void bad_isa_level(int) __attribute__((target_clones("default", "arch=x86-64-v5"))); + +// expected-warning@+1 {{unsupported 'sha' in the 'target_clones' attribute string; 'target_clones' attribute ignored}} +void bad_feature(void) __attribute__((target_clones("default", "sse4.2", "sha"))); diff --git a/clang/test/Sema/attr-target-mv.c b/clang/test/Sema/attr-target-mv.c index 8218771275e1b..ddb1d82b02f09 100644 --- a/clang/test/Sema/attr-target-mv.c +++ b/clang/test/Sema/attr-target-mv.c @@ -170,3 +170,17 @@ int __attribute__((__overloadable__)) __attribute__((target("arch=sandybridge")) int __attribute__((__overloadable__)) __attribute__((target("sse4.2"))) good_overload7(void); int __attribute__((target("arch=sandybridge"))) good_overload7(int); + +// expected-error@+2 {{function multiversioning doesn't support feature 'sha'}} +// expected-note@+2 {{function multiversioning caused by this declaration}} +int __attribute__((target("sha"))) no_priority1(void); +int __attribute__((target("default"))) no_priority1(void); + +int __attribute__((target("default"))) no_priority2(void); +// expected-error@+1 {{function multiversioning doesn't support feature 'sha'}} +int __attribute__((target("sha"))) no_priority2(void); + +int __attribute__((target("default"))) no_priority3(void); +int __attribute__((target("avx2"))) no_priority3(void); +// expected-error@+1 {{function multiversioning doesn't support feature 'sha'}} +int __attribute__((target("sha"))) no_priority3(void); diff --git a/clang/test/Sema/attr-target.c b/clang/test/Sema/attr-target.c index 5328f056507a7..65ece3c27d299 100644 --- a/clang/test/Sema/attr-target.c +++ b/clang/test/Sema/attr-target.c @@ -33,6 +33,8 @@ void __attribute__((target("x86-64"))) baseline(void) {} //expected-warning@+1 {{unsupported 'x86-64-v2' in the 'target' attribute string}} void __attribute__((target("x86-64-v2"))) v2(void) {} +int __attribute__((target("sha"))) good_target_but_not_for_fmv() { return 5; } + #elifdef __aarch64__ int __attribute__((target("sve,arch=armv8-a"))) foo(void) { return 4; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Do not allow unorderable features in [[gnu::target{,_clones}]] (PR #98426)
DanShaders wrote: Rebased on top of main to hopefully pass github CI (no changes otherwise) https://github.com/llvm/llvm-project/pull/98426 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/71148 >From 39f27a9093edd1b034f193c721b76e85e790693a Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Fri, 3 Nov 2023 21:18:06 -0400 Subject: [PATCH] [clang] Stub out gcc_struct attribute This commit implements gcc_struct attribute with the behavior similar to one in GCC. Current behavior is as follows: When C++ ABI is not "Microsoft" (i. e. when ItaniumRecordLayoutBuilder is used), [[gcc_struct]] will locally cancel the effect of -mms-bitfields on a record. If -mms-bitfields is not supplied and is not a default behavior on a target, [[gcc_struct]] will be a no-op. This should provide enough compatibility with GCC. If C++ ABI is "Microsoft", [[gcc_struct]] will currently always produce a diagnostic, since support for it is not yet implemented in MicrosoftRecordLayoutBuilder. Note, however, that all the infrastructure is ready for the future implementation. In particular, check for default value of -mms-bitfields is moved from a driver to ASTContext, since it now non-trivially depends on other supplied flags. This also, unfortunately, makes it impossible to use usual argument parsing for `-m{no-,}ms-bitfields`. The patch doesn't introduce any backwards-incompatible changes, except for situations when cc1 is called directly with `-mms-bitfields` option. --- clang/docs/ReleaseNotes.rst | 6 +++ clang/include/clang/AST/ASTContext.h | 8 clang/include/clang/Basic/Attr.td | 9 - clang/include/clang/Basic/AttrDocs.td | 15 .../include/clang/Basic/DiagnosticASTKinds.td | 3 ++ clang/include/clang/Basic/LangOptions.def | 3 +- clang/include/clang/Basic/LangOptions.h | 10 + clang/include/clang/Driver/Options.td | 10 +++-- clang/lib/AST/Decl.cpp| 9 - clang/lib/AST/RecordLayoutBuilder.cpp | 37 --- clang/lib/Driver/ToolChains/Clang.cpp | 10 +++-- clang/lib/Sema/SemaDecl.cpp | 4 +- clang/lib/Sema/SemaDeclCXX.cpp| 27 +- clang/test/CodeGen/mingw-long-double.c| 2 +- clang/test/CodeGen/mms-bitfields.c| 2 +- clang/test/Driver/ms-bitfields.c | 19 +++--- clang/test/Layout/itanium-union-bitfield.cpp | 2 +- ...a-attribute-supported-attributes-list.test | 1 + clang/test/Sema/mms-bitfields.c | 2 +- clang/test/SemaCXX/ms_struct.cpp | 2 +- clang/test/SemaCXX/ms_wide_bitfield.cpp | 2 +- .../TableGen/ClangDiagnosticsEmitter.cpp | 1 + 22 files changed, 137 insertions(+), 47 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c6a2237113ace..10d3699e632d9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -590,6 +590,12 @@ Attribute Changes in Clang The attributes declare constraints about a function's behavior pertaining to blocking and heap memory allocation. +- On targets with Itanium C++ ABI, Clang now supports ``[[gnu:gcc_struct]]`` + with the behavior similar to one existing in GCC. In particular, whenever + ``-mms-bitfields`` command line option is provided (or if Microsoft-compatible + structure layout is default on the target), ``[[gnu::gcc_struct]]`` requests + the compiler to follow Itanium rules for the layout of an annotated structure. + Improvements to Clang's diagnostics --- - Clang now applies syntax highlighting to the code snippets it diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 57022e75073fe..50fb8b6c29d7a 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -2510,6 +2510,14 @@ class ASTContext : public RefCountedBase { /// runtime, such as those using the Itanium C++ ABI. CharUnits getExnObjectAlignment() const; + /// Return whether getASTRecordLayout will use MicrosoftRecordLayoutBuilder + /// or ItaniumRecordLayoutBuilder. + bool isMicrosoftLayout() const; + + /// Return whether unannotated records are treated as if they have + /// [[gnu::ms_struct]]. + bool defaultsToMsStruct() const; + /// Get or compute information about the layout of the specified /// record (struct/union/class) \p D, which indicates its size and field /// position information. diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index d2d9dd24536cb..8c2a40905a770 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -3974,7 +3974,14 @@ def CFGuard : InheritableAttr, TargetSpecificAttr { def MSStruct : InheritableAttr { let Spellings = [GCC<"ms_struct">]; let Subjects = SubjectList<[Record]>; - let Documentation = [Undocumented]; + let Documentation = [MSStructDocs]; + let SimpleHandler = 1; +} + +def GCCStruct : InheritableAttr { + let Spellings = [GCC<"gc
[clang] [clang] Stub out gcc_struct attribute (PR #71148)
DanShaders wrote: Ping @MaskRay Changes in the force-push: - rebased on top of main; - moved `defaultsToMsStruct` to `ASTContext` since it also depends on auxiliary target. https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement gcc_struct attribute on Itanium targets (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement gcc_struct attribute on Itanium targets (PR #71148)
https://github.com/DanShaders edited https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement gcc_struct attribute on Itanium targets (PR #71148)
DanShaders wrote: Fair enough https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add an off-by-default warning to complain about MSVC bitfield padding (PR #117428)
DanShaders wrote: Just FYI, there's a similar diagnostic `-Wpadded-bitfield` that warns about any padding inserted into bitfields in Itanium mode. They are somehow emitted in the completely different parts of the layout code, so it doesn't show up in the diff at all. https://github.com/llvm/llvm-project/pull/117428 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Implement gcc_struct attribute on Itanium targets (PR #71148)
DanShaders wrote: I won't have any free time to revive this until after Christmas. https://github.com/llvm/llvm-project/pull/71148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Do not allow unorderable features in [[gnu::target{,_clones}]] (PR #98426)
https://github.com/DanShaders updated https://github.com/llvm/llvm-project/pull/98426 >From 723205411efe18dbe8bb154839525b59963b1638 Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Wed, 10 Jul 2024 23:39:42 -0400 Subject: [PATCH 1/2] [clang] Do not allow unorderable features in [[gnu::target{,_clones}]] This partially addresses #98244. --- clang/lib/Sema/SemaDecl.cpp | 4 +++- clang/lib/Sema/SemaDeclAttr.cpp | 3 ++- clang/test/Sema/attr-target-clones.c | 3 +++ clang/test/Sema/attr-target-mv.c | 14 ++ clang/test/Sema/attr-target.c| 2 ++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 5b7275c316f74a..e03e66f23e9a1e 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -11108,7 +11108,9 @@ static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD) { } if (!TargetInfo.validateCpuSupports(BareFeat) || - !TargetInfo.isValidFeatureName(BareFeat)) { + !TargetInfo.isValidFeatureName(BareFeat) || + (BareFeat != "default" && + TargetInfo.multiVersionSortPriority(BareFeat) == 0)) { S.Diag(FD->getLocation(), diag::err_bad_multiversion_option) << Feature << BareFeat; return true; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index bb4d33560b93b8..256188e65d8aaa 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3289,7 +3289,8 @@ bool Sema::checkTargetClonesAttrString( } else if (Cur == "default") { DefaultIsDupe = HasDefault; HasDefault = true; - } else if (!Context.getTargetInfo().isValidFeatureName(Cur)) + } else if (!Context.getTargetInfo().isValidFeatureName(Cur) || + Context.getTargetInfo().multiVersionSortPriority(Cur) == 0) return Diag(CurLoc, diag::warn_unsupported_target_attribute) << Unsupported << None << Cur << TargetClones; if (llvm::is_contained(StringsBuffer, Cur) || DefaultIsDupe) diff --git a/clang/test/Sema/attr-target-clones.c b/clang/test/Sema/attr-target-clones.c index e287fce7699b77..4597ea54d02bfe 100644 --- a/clang/test/Sema/attr-target-clones.c +++ b/clang/test/Sema/attr-target-clones.c @@ -122,3 +122,6 @@ void good_overload5(int) __attribute__((target_clones("mmx", "sse4.2", "default" void good_isa_level(int) __attribute__((target_clones("default", "arch=x86-64", "arch=x86-64-v2", "arch=x86-64-v3", "arch=x86-64-v4"))); // expected-warning@+1 {{unsupported CPU 'x86-64-v5' in the 'target_clones' attribute string; 'target_clones' attribute ignored}} void bad_isa_level(int) __attribute__((target_clones("default", "arch=x86-64-v5"))); + +// expected-warning@+1 {{unsupported 'sha' in the 'target_clones' attribute string; 'target_clones' attribute ignored}} +void bad_feature(void) __attribute__((target_clones("default", "sse4.2", "sha"))); diff --git a/clang/test/Sema/attr-target-mv.c b/clang/test/Sema/attr-target-mv.c index 8218771275e1bd..ddb1d82b02f098 100644 --- a/clang/test/Sema/attr-target-mv.c +++ b/clang/test/Sema/attr-target-mv.c @@ -170,3 +170,17 @@ int __attribute__((__overloadable__)) __attribute__((target("arch=sandybridge")) int __attribute__((__overloadable__)) __attribute__((target("sse4.2"))) good_overload7(void); int __attribute__((target("arch=sandybridge"))) good_overload7(int); + +// expected-error@+2 {{function multiversioning doesn't support feature 'sha'}} +// expected-note@+2 {{function multiversioning caused by this declaration}} +int __attribute__((target("sha"))) no_priority1(void); +int __attribute__((target("default"))) no_priority1(void); + +int __attribute__((target("default"))) no_priority2(void); +// expected-error@+1 {{function multiversioning doesn't support feature 'sha'}} +int __attribute__((target("sha"))) no_priority2(void); + +int __attribute__((target("default"))) no_priority3(void); +int __attribute__((target("avx2"))) no_priority3(void); +// expected-error@+1 {{function multiversioning doesn't support feature 'sha'}} +int __attribute__((target("sha"))) no_priority3(void); diff --git a/clang/test/Sema/attr-target.c b/clang/test/Sema/attr-target.c index 5328f056507a71..65ece3c27d2990 100644 --- a/clang/test/Sema/attr-target.c +++ b/clang/test/Sema/attr-target.c @@ -33,6 +33,8 @@ void __attribute__((target("x86-64"))) baseline(void) {} //expected-warning@+1 {{unsupported 'x86-64-v2' in the 'target' attribute string}} void __attribute__((target("x86-64-v2"))) v2(void) {} +int __attribute__((target("sha"))) good_target_but_not_for_fmv() { return 5; } + #elifdef __aarch64__ int __attribute__((target("sve,arch=armv8-a"))) foo(void) { return 4; } >From 7378d6241f4e829a3b69af2ceb9a70c9c0bcc56a Mon Sep 17 00:00:00 2001 From: Dan Klishch Date: Mon, 13 Jan 2025 16:57:19 -0500 Subject: [PATCH 2/2] fixup after #116257 --- clang/lib/Sema/SemaDecl.c
[clang] [clang] Do not allow unorderable features in [[gnu::target{,_clones}]] (PR #98426)
DanShaders wrote: I do, thanks! https://github.com/llvm/llvm-project/pull/98426 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits