From b8b5cbc169c9f6c523ada0d37dd126f7af65f3f8 Mon Sep 17 00:00:00 2001 From: Chad Rosier Date: Thu, 17 Jan 2013 19:21:24 +0000 Subject: [PATCH] [ms-inline asm] Extend the Sema interface to get the size and length of a VarDecl. Part of rdar://12576868 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172742 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/Sema.h | 3 ++- lib/Sema/SemaStmtAsm.cpp | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index af4d16b84f..0da549a9f3 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -2703,7 +2703,8 @@ public: SourceLocation RParenLoc); NamedDecl *LookupInlineAsmIdentifier(StringRef Name, SourceLocation Loc, - unsigned &Size, bool &IsVarDecl); + unsigned &Length, unsigned &Size, + unsigned &Type, bool &IsVarDecl); bool LookupInlineAsmField(StringRef Base, StringRef Member, unsigned &Offset, SourceLocation AsmLoc); StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, diff --git a/lib/Sema/SemaStmtAsm.cpp b/lib/Sema/SemaStmtAsm.cpp index 008a99a174..4646ef7b38 100644 --- a/lib/Sema/SemaStmtAsm.cpp +++ b/lib/Sema/SemaStmtAsm.cpp @@ -437,10 +437,13 @@ public: : SemaRef(Ref), AsmLoc(Loc), AsmToks(Toks), TokOffsets(Offsets) { } ~MCAsmParserSemaCallbackImpl() {} - void *LookupInlineAsmIdentifier(StringRef Name, void *SrcLoc, unsigned &Size, - bool &IsVarDecl){ + void *LookupInlineAsmIdentifier(StringRef Name, void *SrcLoc, + unsigned &Length, unsigned &Size, + unsigned &Type, bool &IsVarDecl){ SourceLocation Loc = SourceLocation::getFromPtrEncoding(SrcLoc); - NamedDecl *OpDecl = SemaRef.LookupInlineAsmIdentifier(Name, Loc, Size, + + NamedDecl *OpDecl = SemaRef.LookupInlineAsmIdentifier(Name, Loc, Length, + Size, Type, IsVarDecl); return static_cast(OpDecl); } @@ -484,8 +487,11 @@ public: } NamedDecl *Sema::LookupInlineAsmIdentifier(StringRef Name, SourceLocation Loc, - unsigned &Size, bool &IsVarDecl) { + unsigned &Length, unsigned &Size, + unsigned &Type, bool &IsVarDecl) { + Length = 1; Size = 0; + Type = 0; IsVarDecl = false; LookupResult Result(*this, &Context.Idents.get(Name), Loc, Sema::LookupOrdinaryName); @@ -504,7 +510,15 @@ NamedDecl *Sema::LookupInlineAsmIdentifier(StringRef Name, SourceLocation Loc, NamedDecl *ND = Result.getFoundDecl(); if (isa(ND) || isa(ND)) { if (VarDecl *Var = dyn_cast(ND)) { - Size = Context.getTypeInfo(Var->getType()).first; + Type = Context.getTypeInfo(Var->getType()).first; + QualType Ty = Var->getType(); + if (Ty->isArrayType()) { + const ArrayType *ATy = Context.getAsArrayType(Ty); + Length = Type / Context.getTypeInfo(ATy->getElementType()).first; + Type /= Length; // Type is in terms of a single element. + } + Type /= 8; // Type is in terms of bits, but we want bytes. + Size = Length * Type; IsVarDecl = true; } return ND; -- 2.40.0