r255890 - [ms-inline-asm] Add support for composite structs in MS inline asm

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 15 10:53:05 PST 2016


On Thu, Dec 17, 2015 at 4:51 AM, Marina Yatsina via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: myatsina
> Date: Thu Dec 17 06:51:51 2015
> New Revision: 255890
>
> URL: http://llvm.org/viewvc/llvm-project?rev=255890&view=rev
> Log:
> [ms-inline-asm] Add support for composite structs in MS inline asm
>
> Add MS inline asm support for structs that contain fields that are also
> structs.
>
> Differential Revision: http://reviews.llvm.org/D15578
>
>
> Modified:
>     cfe/trunk/lib/Sema/SemaStmtAsm.cpp
>     cfe/trunk/test/CodeGen/ms-inline-asm.c
>
> Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=255890&r1=255889&r2=255890&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Thu Dec 17 06:51:51 2015
> @@ -617,45 +617,57 @@ ExprResult Sema::LookupInlineAsmIdentifi
>  bool Sema::LookupInlineAsmField(StringRef Base, StringRef Member,
>                                  unsigned &Offset, SourceLocation AsmLoc) {
>    Offset = 0;
> +  SmallVector<StringRef, 2> Members;
> +  Member.split(Members, ".");
> +
>    LookupResult BaseResult(*this, &Context.Idents.get(Base),
> SourceLocation(),
>                            LookupOrdinaryName);
>
>    if (!LookupName(BaseResult, getCurScope()))
>      return true;
>
> -  if (!BaseResult.isSingleResult())
> -    return true;
> +  LookupResult CurrBaseResult(BaseResult);
>
> -  const RecordType *RT = nullptr;
> -  NamedDecl *FoundDecl = BaseResult.getFoundDecl();
> -  if (VarDecl *VD = dyn_cast<VarDecl>(FoundDecl))
> -    RT = VD->getType()->getAs<RecordType>();
> -  else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(FoundDecl)) {
> -    MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
> -    RT = TD->getUnderlyingType()->getAs<RecordType>();
> -  } else if (TypeDecl *TD = dyn_cast<TypeDecl>(FoundDecl))
> -    RT = TD->getTypeForDecl()->getAs<RecordType>();
> -  if (!RT)
> -    return true;
> -
> -  if (RequireCompleteType(AsmLoc, QualType(RT, 0), 0))
> -    return true;
> +  for (StringRef NextMember : Members) {
>
> -  LookupResult FieldResult(*this, &Context.Idents.get(Member),
> SourceLocation(),
> -                           LookupMemberName);
> -
> -  if (!LookupQualifiedName(FieldResult, RT->getDecl()))
> -    return true;
> -
> -  // FIXME: Handle IndirectFieldDecl?
> -  FieldDecl *FD = dyn_cast<FieldDecl>(FieldResult.getFoundDecl());
> -  if (!FD)
> -    return true;
> +    if (!CurrBaseResult.isSingleResult())
> +      return true;
>
> -  const ASTRecordLayout &RL = Context.getASTRecordLayout(RT->getDecl());
> -  unsigned i = FD->getFieldIndex();
> -  CharUnits Result = Context.toCharUnitsFromBits(RL.getFieldOffset(i));
> -  Offset = (unsigned)Result.getQuantity();
> +    const RecordType *RT = nullptr;
> +    NamedDecl *FoundDecl = CurrBaseResult.getFoundDecl();
> +    if (VarDecl *VD = dyn_cast<VarDecl>(FoundDecl))
> +      RT = VD->getType()->getAs<RecordType>();
> +    else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(FoundDecl)) {
> +      MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
> +      RT = TD->getUnderlyingType()->getAs<RecordType>();
> +    } else if (TypeDecl *TD = dyn_cast<TypeDecl>(FoundDecl))
> +      RT = TD->getTypeForDecl()->getAs<RecordType>();
> +    else if (FieldDecl *TD = dyn_cast<FieldDecl>(FoundDecl))
> +      RT = TD->getType()->getAs<RecordType>();
> +    if (!RT)
> +      return true;
> +
> +    if (RequireCompleteType(AsmLoc, QualType(RT, 0), 0))
> +      return true;
> +
> +    LookupResult FieldResult(*this, &Context.Idents.get(NextMember),
> +                             SourceLocation(), LookupMemberName);
> +
> +    if (!LookupQualifiedName(FieldResult, RT->getDecl()))
> +      return true;
> +
> +    // FIXME: Handle IndirectFieldDecl?
> +    FieldDecl *FD = dyn_cast<FieldDecl>(FieldResult.getFoundDecl());
> +    if (!FD)
> +      return true;
> +
> +    CurrBaseResult = FieldResult;
>

LookupResults shouldn't be/aren't really copyable (it's deprecated in C++11
to copy them, because they have a non-trivial dtor, which is reasonable -
the default copy ctor would produce bad behavior if the interesting members
(explicitly destroyed in the user-defined dtor) were present/non-null when
the copy took place).

Perhaps you could generalize/do something like the change I made in
http://llvm.org/viewvc/llvm-project?rev=248761&view=rev ?

At some point it'd be nice to enable -Wdeprecated for the Clang-on-clang
build directly, but there's a few wrinkles I need to sort out (when I find
the time/motivation) before that happens.


> +
> +    const ASTRecordLayout &RL = Context.getASTRecordLayout(RT->getDecl());
> +    unsigned i = FD->getFieldIndex();
> +    CharUnits Result = Context.toCharUnitsFromBits(RL.getFieldOffset(i));
> +    Offset += (unsigned)Result.getQuantity();
> +  }
>
>    return false;
>  }
>
> Modified: cfe/trunk/test/CodeGen/ms-inline-asm.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-inline-asm.c?rev=255890&r1=255889&r2=255890&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CodeGen/ms-inline-asm.c (original)
> +++ cfe/trunk/test/CodeGen/ms-inline-asm.c Thu Dec 17 06:51:51 2015
> @@ -470,6 +470,18 @@ typedef struct {
>    int b;
>  } A;
>
> +typedef struct {
> +  int b1;
> +  A   b2;
> +} B;
> +
> +typedef struct {
> +  int c1;
> +  A   c2;
> +  int c3;
> +  B   c4;
> +} C;
> +
>  void t39() {
>  // CHECK-LABEL: define void @t39
>    __asm mov eax, [eax].A.b
> @@ -478,6 +490,14 @@ void t39() {
>  // CHECK: mov eax, [eax] .4
>    __asm mov eax, fs:[0] A.b
>  // CHECK: mov eax, fs:[$$0] .4
> +  __asm mov eax, [eax].B.b2.a
> +// CHECK: mov eax, [eax].4
> +  __asm mov eax, [eax] B.b2.b
> +// CHECK: mov eax, [eax] .8
> +  __asm mov eax, fs:[0] C.c2.b
> +// CHECK: mov eax, fs:[$$0] .8
> +  __asm mov eax, [eax]C.c4.b2.b
> +// CHECK: mov eax, [eax].24
>  // CHECK: "~{eax},~{dirflag},~{fpsr},~{flags}"()
>  }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160115/84a30e42/attachment-0001.html>


More information about the cfe-commits mailing list