Skip to content

Commit fc6a512

Browse files
committed
change cc1 option to -fms-layout-compatibility={default,microsoft,itanium}
1 parent 354896c commit fc6a512

File tree

14 files changed

+45
-38
lines changed

14 files changed

+45
-38
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ LANGOPT(AssumeNothrowExceptionDtor , 1, 0, "Assume exception object's destructor
149149
LANGOPT(TraditionalCPP , 1, 0, "traditional CPP emulation")
150150
LANGOPT(RTTI , 1, 1, "run-time type information")
151151
LANGOPT(RTTIData , 1, 1, "emit run-time type information data")
152+
ENUM_LANGOPT(LayoutCompatibility, LayoutCompatibilityKind, 2,
153+
LayoutCompatibilityKind::Default, "Microsoft-compatible structure layout")
152154
LANGOPT(MSVolatile , 1, 0, "Microsoft-compatible volatile loads and stores")
153155
LANGOPT(Freestanding, 1, 0, "freestanding implementation")
154156
LANGOPT(NoBuiltin , 1, 0, "disable builtin functions")

clang/include/clang/Basic/LangOptions.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,15 @@ class LangOptions : public LangOptionsBase {
391391
IncompleteOnly = 3,
392392
};
393393

394+
enum class LayoutCompatibilityKind {
395+
/// Use default layout rules of the target.
396+
Default = 0,
397+
/// Use Itanium rules for bit-field layout and fundamental types alignment.
398+
Itanium = 1,
399+
/// Use Microsoft C++ ABI rules for bit-field layout and fundamental types alignment.
400+
Microsoft = 2,
401+
};
402+
394403
public:
395404
/// The used language standard.
396405
LangStandard::Kind LangStd;
@@ -507,8 +516,6 @@ class LangOptions : public LangOptionsBase {
507516
// implementation on real-world examples.
508517
std::string OpenACCMacroOverride;
509518

510-
std::optional<bool> MSBitfields;
511-
512519
LangOptions();
513520

514521
/// Set language defaults for the given input language and

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4425,7 +4425,7 @@ def mmacos_version_min_EQ : Joined<["-"], "mmacos-version-min=">,
44254425
def : Joined<["-"], "mmacosx-version-min=">,
44264426
Group<m_Group>, Alias<mmacos_version_min_EQ>;
44274427
def mms_bitfields : Flag<["-"], "mms-bitfields">, Group<m_Group>,
4428-
Visibility<[ClangOption, CC1Option]>,
4428+
Visibility<[ClangOption]>,
44294429
HelpText<"Set the default structure layout to be compatible with the Microsoft compiler standard">;
44304430
def moutline : Flag<["-"], "moutline">, Group<f_clang_Group>,
44314431
Visibility<[ClangOption, CC1Option]>,
@@ -4434,8 +4434,14 @@ def mno_outline : Flag<["-"], "mno-outline">, Group<f_clang_Group>,
44344434
Visibility<[ClangOption, CC1Option]>,
44354435
HelpText<"Disable function outlining (AArch64 only)">;
44364436
def mno_ms_bitfields : Flag<["-"], "mno-ms-bitfields">, Group<m_Group>,
4437-
Visibility<[ClangOption, CC1Option]>,
4437+
Visibility<[ClangOption]>,
44384438
HelpText<"Do not set the default structure layout to be compatible with the Microsoft compiler standard">;
4439+
def fms_layout_compatibility_EQ : Joined<["-"], "fms-layout-compatibility=">,
4440+
Visibility<[CC1Option]>,
4441+
HelpText<"Structure layout compatibility with Microsoft C++ ABI">,
4442+
Values<"default,itanium,microsoft">,
4443+
NormalizedValues<["Default", "Itanium", "Microsoft"]>, NormalizedValuesScope<"LangOptions::LayoutCompatibilityKind">,
4444+
MarshallingInfoEnum<LangOpts<"LayoutCompatibility">, "Default">;
44394445
def mskip_rax_setup : Flag<["-"], "mskip-rax-setup">, Group<m_Group>,
44404446
Visibility<[ClangOption, CC1Option]>,
44414447
HelpText<"Skip setting up RAX register when passing variable arguments (x86 only)">,

clang/lib/AST/Decl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5035,8 +5035,10 @@ bool RecordDecl::isMsStruct(const ASTContext &C) const {
50355035
return true;
50365036
if (hasAttr<GCCStructAttr>())
50375037
return false;
5038-
return C.getLangOpts().MSBitfields.value_or(
5039-
C.getTargetInfo().defaultsToMsStruct());
5038+
auto LayoutCompatibility = C.getLangOpts().getLayoutCompatibility();
5039+
if (LayoutCompatibility == LangOptions::LayoutCompatibilityKind::Default)
5040+
return C.getTargetInfo().defaultsToMsStruct();
5041+
return LayoutCompatibility == LangOptions::LayoutCompatibilityKind::Microsoft;
50405042
}
50415043

50425044
void RecordDecl::reorderDecls(const SmallVectorImpl<Decl *> &Decls) {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5670,9 +5670,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
56705670
Args.hasArg(options::OPT_mno_ms_bitfields)) {
56715671
if (Args.hasFlag(options::OPT_mms_bitfields, options::OPT_mno_ms_bitfields,
56725672
false))
5673-
CmdArgs.push_back("-mms-bitfields");
5673+
CmdArgs.push_back("-fms-layout-compatibility=microsoft");
56745674
else
5675-
CmdArgs.push_back("-mno-ms-bitfields");
5675+
CmdArgs.push_back("-fms-layout-compatibility=itanium");
56765676
}
56775677

56785678
if (Triple.isWindowsGNUEnvironment()) {

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3635,13 +3635,6 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
36353635
GenerateArg(Consumer, OPT_fcxx_abi_EQ,
36363636
TargetCXXABI::getSpelling(*Opts.CXXABI));
36373637

3638-
if (Opts.MSBitfields.has_value()) {
3639-
if (Opts.MSBitfields.value())
3640-
GenerateArg(Consumer, OPT_mms_bitfields);
3641-
else
3642-
GenerateArg(Consumer, OPT_mno_ms_bitfields);
3643-
}
3644-
36453638
if (Opts.RelativeCXXABIVTables)
36463639
GenerateArg(Consumer, OPT_fexperimental_relative_cxx_abi_vtables);
36473640
else
@@ -4184,11 +4177,6 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
41844177
options::OPT_fno_experimental_relative_cxx_abi_vtables,
41854178
TargetCXXABI::usesRelativeVTables(T));
41864179

4187-
if (Args.hasArg(options::OPT_mms_bitfields) ||
4188-
Args.hasArg(options::OPT_mno_ms_bitfields))
4189-
Opts.MSBitfields = Args.hasFlag(options::OPT_mms_bitfields,
4190-
options::OPT_mno_ms_bitfields, false);
4191-
41924180
// RTTI is on by default.
41934181
bool HasRTTI = !Args.hasArg(options::OPT_fno_rtti);
41944182
Opts.OmitVTableRTTI =

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7273,7 +7273,7 @@ void Sema::CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record) {
72737273
// language option (as opposed to via a pragma or attribute), as
72747274
// the option -mms-bitfields otherwise essentially makes it impossible
72757275
// to build C++ code, unless this diagnostic is turned off.
7276-
if (!Context.getLangOpts().MSBitfields.has_value() &&
7276+
if (Context.getLangOpts().getLayoutCompatibility() == LangOptions::LayoutCompatibilityKind::Default &&
72777277
Record->isMsStruct(Context) !=
72787278
Context.getTargetInfo().defaultsToMsStruct() &&
72797279
(Record->isPolymorphic() || Record->getNumBases())) {

clang/test/CodeGen/mingw-long-double.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_cc1 -triple i686-windows-gnu -emit-llvm -o - %s \
22
// RUN: | FileCheck %s --check-prefix=GNU32
3-
// RUN: %clang_cc1 -triple i686-windows-gnu -emit-llvm -o - %s -mms-bitfields \
3+
// RUN: %clang_cc1 -triple i686-windows-gnu -emit-llvm -o - %s -fms-layout-compatibility=microsoft \
44
// RUN: | FileCheck %s --check-prefix=GNU32
55
// RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -o - %s \
66
// RUN: | FileCheck %s --check-prefix=GNU64

clang/test/CodeGen/mms-bitfields.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple i386-apple-darwin10 -mms-bitfields -emit-llvm %s -o - | FileCheck %s
1+
// RUN: %clang_cc1 -triple i386-apple-darwin10 -fms-layout-compatibility=microsoft -emit-llvm %s -o - | FileCheck %s
22

33
struct s1 {
44
int f32;

clang/test/Driver/ms-bitfields.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
// RUN: %clang -### -target x86_64-linux-gnu %s 2>&1 | FileCheck %s -check-prefix=DEFAULT-MSBITFIELDS
2-
// RUN: %clang -### -target x86_64-windows-gnu %s 2>&1 | FileCheck %s -check-prefix=DEFAULT-MSBITFIELDS
3-
// RUN: %clang -### -target x86_64-windows-msvc %s 2>&1 | FileCheck %s -check-prefix=DEFAULT-MSBITFIELDS
4-
// RUN: %clang -### -mms-bitfields %s 2>&1 | FileCheck %s -check-prefix=MSBITFIELDS
5-
// RUN: %clang -### -mno-ms-bitfields %s 2>&1 | FileCheck %s -check-prefix=NO-MSBITFIELDS
6-
// RUN: %clang -### -mno-ms-bitfields -mms-bitfields %s 2>&1 | FileCheck %s -check-prefix=MSBITFIELDS
7-
// RUN: %clang -### -mms-bitfields -mno-ms-bitfields %s 2>&1 | FileCheck %s -check-prefix=NO-MSBITFIELDS
1+
// RUN: %clang -### -target x86_64-linux-gnu %s 2>&1 | FileCheck %s -check-prefix=DEFAULT-LAYOUT
2+
// RUN: %clang -### -target x86_64-windows-gnu %s 2>&1 | FileCheck %s -check-prefix=DEFAULT-LAYOUT
3+
// RUN: %clang -### -target x86_64-windows-msvc %s 2>&1 | FileCheck %s -check-prefix=DEFAULT-LAYOUT
4+
// RUN: %clang -### -mms-bitfields %s 2>&1 | FileCheck %s -check-prefix=MICROSOFT-LAYOUT
5+
// RUN: %clang -### -mno-ms-bitfields %s 2>&1 | FileCheck %s -check-prefix=ITANIUM-LAYOUT
6+
// RUN: %clang -### -mno-ms-bitfields -mms-bitfields %s 2>&1 | FileCheck %s -check-prefix=MICROSOFT-LAYOUT
7+
// RUN: %clang -### -mms-bitfields -mno-ms-bitfields %s 2>&1 | FileCheck %s -check-prefix=ITANIUM-LAYOUT
88

9-
// MSBITFIELDS: -mms-bitfields
10-
// NO-MSBITFIELDS: -mno-ms-bitfields
11-
// DEFAULT-MSBITFIELDS-NOT: -mms-bitfields
12-
// DEFAULT-MSBITFIELDS-NOT: -mno-ms-bitfields
9+
// DEFAULT-LAYOUT-NOT: -fms-layout-compatibility=itanium
10+
// DEFAULT-LAYOUT-NOT: -fms-layout-compatibility=microsoft
11+
// MICROSOFT-LAYOUT: -fms-layout-compatibility=microsoft
12+
// MICROSOFT-LAYOUT-NOT: -fms-layout-compatibility=itanium
13+
// ITANIUM-LAYOUT: -fms-layout-compatibility=itanium
14+
// ITANIUM-LAYOUT-NOT: -fms-layout-compatibility=microsoft
1315

0 commit comments

Comments
 (0)