From a1311366decdac3a9d9405a4d6fdf697cef08a10 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 3 Feb 2015 08:49:32 +0000 Subject: [PATCH] MS ABI: Records with fields with required aligmnet shouldn't be common git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227954 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 22 +++++++++++++++++++--- test/CodeGen/ms-align-tentative.c | 5 +++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index dc7ec6f654..bc52028a06 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -2162,9 +2162,25 @@ static bool isVarDeclStrongDefinition(const ASTContext &Context, // Declarations with a required alignment do not have common linakge in MSVC // mode. - if (Context.getLangOpts().MSVCCompat && - (Context.isAlignmentRequired(D->getType()) || D->hasAttr())) - return true; + if (Context.getLangOpts().MSVCCompat) { + if (D->hasAttr()) + return true; + QualType VarType = D->getType(); + if (Context.isAlignmentRequired(VarType)) + return true; + + if (const auto *RT = VarType->getAs()) { + const RecordDecl *RD = RT->getDecl(); + for (const FieldDecl *FD : RD->fields()) { + if (FD->isBitField()) + continue; + if (FD->hasAttr()) + return true; + if (Context.isAlignmentRequired(FD->getType())) + return true; + } + } + } return false; } diff --git a/test/CodeGen/ms-align-tentative.c b/test/CodeGen/ms-align-tentative.c index 13d7440e88..eb68e69f58 100644 --- a/test/CodeGen/ms-align-tentative.c +++ b/test/CodeGen/ms-align-tentative.c @@ -18,3 +18,8 @@ struct __declspec(align(64)) S { char fd; } s; // CHECK-DAG: @s = global %struct.S zeroinitializer, align 64 + +struct Wrap { + struct S x; +} w; +// CHECK-DAG: @w = global %struct.Wrap zeroinitializer, align 64 -- 2.40.0