[cfe-commits] r172742 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaStmtAsm.cpp

Chad Rosier mcrosier at apple.com
Thu Jan 17 11:21:25 PST 2013


Author: mcrosier
Date: Thu Jan 17 13:21:24 2013
New Revision: 172742

URL: http://llvm.org/viewvc/llvm-project?rev=172742&view=rev
Log:
[ms-inline asm] Extend the Sema interface to get the size and length of a
VarDecl.
Part of rdar://12576868

Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaStmtAsm.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=172742&r1=172741&r2=172742&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Jan 17 13:21:24 2013
@@ -2703,7 +2703,8 @@
                              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,

Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=172742&r1=172741&r2=172742&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Thu Jan 17 13:21:24 2013
@@ -437,10 +437,13 @@
     : 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<void *>(OpDecl);
   }
@@ -484,8 +487,11 @@
 }
 
 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 *ND = Result.getFoundDecl();
   if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) {
     if (VarDecl *Var = dyn_cast<VarDecl>(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;





More information about the cfe-commits mailing list