<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 8, 2015 at 1:41 PM, Adrian Prantl via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: adrian<br>
Date: Tue Sep  8 15:41:52 2015<br>
New Revision: 247068<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=247068&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=247068&view=rev</a><br>
Log:<br>
Module Debugging: Emit debug type information into clang ObjC modules.<br>
<br>
When -fmodule-format is set to "obj", emit debug info for all types<br>
declared in a module or referenced by a declaration into the module's<br>
object file container.<br></blockquote><div><br>As I mentioned in the other code review "or referenced by a declaration" seems like a strange clause to me & sounds like it would produce a lot of redundant debug info... could you explain the motivation for this?<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
This patch adds support for Objective-C types and methods.<br>
<br>
Added:<br>
    cfe/trunk/test/Modules/Inputs/DebugObjC.h<br>
    cfe/trunk/test/Modules/ModuleDebugInfo.m<br>
Removed:<br>
    cfe/trunk/test/Modules/Inputs/DebugModule.h<br>
Modified:<br>
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
    cfe/trunk/lib/CodeGen/CGDebugInfo.h<br>
    cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp<br>
    cfe/trunk/test/Modules/Inputs/module.map<br>
    cfe/trunk/test/Modules/debug-info-moduleimport.m<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=247068&r1=247067&r2=247068&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=247068&r1=247067&r2=247068&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Sep  8 15:41:52 2015<br>
@@ -2515,11 +2515,17 @@ llvm::DISubroutineType *CGDebugInfo::get<br>
<br>
     Elts.push_back(getOrCreateType(ResultTy, F));<br>
     // "self" pointer is always first argument.<br>
-    QualType SelfDeclTy = OMethod->getSelfDecl()->getType();<br>
-    Elts.push_back(CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));<br>
+    QualType SelfDeclTy;<br>
+    if (auto *SelfDecl = OMethod->getSelfDecl())<br>
+      SelfDeclTy = SelfDecl->getType();<br>
+    else if (auto *FPT = dyn_cast<FunctionProtoType>(FnType))<br>
+      if (FPT->getNumParams() > 1)<br>
+        SelfDeclTy = FPT->getParamType(0);<br>
+    if (!SelfDeclTy.isNull())<br>
+      Elts.push_back(CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));<br>
     // "_cmd" pointer is always second argument.<br>
     Elts.push_back(DBuilder.createArtificialType(<br>
-        getOrCreateType(OMethod->getCmdDecl()->getType(), F)));<br>
+        getOrCreateType(CGM.getContext().getObjCSelType(), F)));<br>
     // Get rest of the arguments.<br>
     for (const auto *PI : OMethod->params())<br>
       Elts.push_back(getOrCreateType(PI->getType(), F));<br>
@@ -2623,6 +2629,49 @@ void CGDebugInfo::EmitFunctionStart(Glob<br>
     RegionMap[D].reset(SP);<br>
 }<br>
<br>
+void CGDebugInfo::EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc,<br>
+                                   QualType FnType) {<br>
+  StringRef Name;<br>
+  StringRef LinkageName;<br>
+<br>
+  const Decl *D = GD.getDecl();<br>
+  if (!D)<br>
+    return;<br>
+<br>
+  unsigned Flags = 0;<br>
+  llvm::DIFile *Unit = getOrCreateFile(Loc);<br>
+  llvm::DIScope *FDContext = Unit;<br>
+  llvm::DINodeArray TParamsArray;<br>
+  if (isa<FunctionDecl>(D)) {<br>
+    // If there is a DISubprogram for this function available then use it.<br>
+    collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,<br>
+                             TParamsArray, Flags);<br>
+  } else if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) {<br>
+    Name = getObjCMethodName(OMD);<br>
+    Flags |= llvm::DINode::FlagPrototyped;<br>
+  } else {<br>
+    llvm_unreachable("not a function or ObjC method");<br>
+  }<br>
+  if (!Name.empty() && Name[0] == '\01')<br>
+    Name = Name.substr(1);<br>
+<br>
+  if (D->isImplicit()) {<br>
+    Flags |= llvm::DINode::FlagArtificial;<br>
+    // Artificial functions without a location should not silently reuse CurLoc.<br>
+    if (Loc.isInvalid())<br>
+      CurLoc = SourceLocation();<br>
+  }<br>
+  unsigned LineNo = getLineNumber(Loc);<br>
+  unsigned ScopeLine = 0;<br>
+<br>
+  DBuilder.createFunction(FDContext, Name, LinkageName, Unit, LineNo,<br>
+                          getOrCreateFunctionType(D, FnType, Unit),<br>
+                          false /*internalLinkage*/, true /*definition*/,<br>
+                          ScopeLine, Flags, CGM.getLangOpts().Optimize, nullptr,<br>
+                          TParamsArray.get(),<br>
+                          getFunctionDeclaration(D));<br>
+}<br>
+<br>
 void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc) {<br>
   // Update our current location<br>
   setLocation(Loc);<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=247068&r1=247067&r2=247068&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=247068&r1=247067&r2=247068&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Tue Sep  8 15:41:52 2015<br>
@@ -281,6 +281,9 @@ public:<br>
                          SourceLocation ScopeLoc, QualType FnType,<br>
                          llvm::Function *Fn, CGBuilderTy &Builder);<br>
<br>
+  /// Emit debug info for a function declaration.<br>
+  void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType);<br>
+<br>
   /// Constructs the debug code for exiting a function.<br>
   void EmitFunctionEnd(CGBuilderTy &Builder);<br>
<br>
<br>
Modified: cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp?rev=247068&r1=247067&r2=247068&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp?rev=247068&r1=247067&r2=247068&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp Tue Sep  8 15:41:52 2015<br>
@@ -76,6 +76,48 @@ class PCHContainerGenerator : public AST<br>
       return true;<br>
     }<br>
<br>
+    bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {<br>
+      QualType QualTy(D->getTypeForDecl(), 0);<br>
+      if (!QualTy.isNull() && CanRepresent(QualTy.getTypePtr()))<br>
+        DI.getOrCreateStandaloneType(QualTy, D->getLocation());<br>
+      return true;<br>
+    }<br>
+<br>
+    bool VisitFunctionDecl(FunctionDecl *D) {<br>
+      if (isa<CXXMethodDecl>(D))<br>
+        // This is not yet supported. Constructing the `this' argument<br>
+        // mandates a CodeGenFunction.<br>
+        return true;<br>
+<br>
+      SmallVector<QualType, 16> ArgTypes;<br>
+      for (auto i : D->params())<br>
+        ArgTypes.push_back(i->getType());<br>
+      QualType RetTy = D->getReturnType();<br>
+      QualType FnTy = Ctx.getFunctionType(RetTy, ArgTypes,<br>
+                                          FunctionProtoType::ExtProtoInfo());<br>
+      if (CanRepresent(FnTy.getTypePtr()))<br>
+        DI.EmitFunctionDecl(D, D->getLocation(), FnTy);<br>
+      return true;<br>
+    }<br>
+<br>
+    bool VisitObjCMethodDecl(ObjCMethodDecl *D) {<br>
+      if (!D->getClassInterface())<br>
+        return true;<br>
+<br>
+      bool selfIsPseudoStrong, selfIsConsumed;<br>
+      SmallVector<QualType, 16> ArgTypes;<br>
+      ArgTypes.push_back(D->getSelfType(Ctx, D->getClassInterface(),<br>
+                                        selfIsPseudoStrong, selfIsConsumed));<br>
+      ArgTypes.push_back(Ctx.getObjCSelType());<br>
+      for (auto i : D->params())<br>
+        ArgTypes.push_back(i->getType());<br>
+      QualType RetTy = D->getReturnType();<br>
+      QualType FnTy = Ctx.getFunctionType(RetTy, ArgTypes,<br>
+                                          FunctionProtoType::ExtProtoInfo());<br>
+      if (CanRepresent(FnTy.getTypePtr()))<br>
+        DI.EmitFunctionDecl(D, D->getLocation(), FnTy);<br>
+      return true;<br>
+    }<br>
   };<br>
<br>
 public:<br>
<br>
Removed: cfe/trunk/test/Modules/Inputs/DebugModule.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/DebugModule.h?rev=247067&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/DebugModule.h?rev=247067&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/Inputs/DebugModule.h (original)<br>
+++ cfe/trunk/test/Modules/Inputs/DebugModule.h (removed)<br>
@@ -1 +0,0 @@<br>
-@class F;<br>
<br>
Added: cfe/trunk/test/Modules/Inputs/DebugObjC.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/DebugObjC.h?rev=247068&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/DebugObjC.h?rev=247068&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/Inputs/DebugObjC.h (added)<br>
+++ cfe/trunk/test/Modules/Inputs/DebugObjC.h Tue Sep  8 15:41:52 2015<br>
@@ -0,0 +1,11 @@<br>
+@interface ObjCClass {<br>
+  int ivar;<br>
+}<br>
++ classMethod;<br>
+- instanceMethodWithInt:(int)i;<br>
+@property int property;<br>
+@end<br>
+<br>
+@interface ObjCClass (Category)<br>
+- categoryMethod;<br>
+@end<br>
<br>
Modified: cfe/trunk/test/Modules/Inputs/module.map<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=247068&r1=247067&r2=247068&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=247068&r1=247067&r2=247068&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/Inputs/module.map (original)<br>
+++ cfe/trunk/test/Modules/Inputs/module.map Tue Sep  8 15:41:52 2015<br>
@@ -328,14 +328,14 @@ module crash {<br>
   header "crash.h"<br>
 }<br>
<br>
-module DebugModule {<br>
-  header "DebugModule.h"<br>
-}<br>
-<br>
 module DebugCXX {<br>
   header "DebugCXX.h"<br>
 }<br>
<br>
+module DebugObjC {<br>
+  header "DebugObjC.h"<br>
+}<br>
+<br>
 module ImportNameInDir {<br>
   header "ImportNameInDir.h"<br>
   export *<br>
<br>
Added: cfe/trunk/test/Modules/ModuleDebugInfo.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ModuleDebugInfo.m?rev=247068&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/ModuleDebugInfo.m?rev=247068&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/ModuleDebugInfo.m (added)<br>
+++ cfe/trunk/test/Modules/ModuleDebugInfo.m Tue Sep  8 15:41:52 2015<br>
@@ -0,0 +1,27 @@<br>
+// Test that debug info is emitted for an Objective-C module and<br>
+// a precompiled header.<br>
+<br>
+// REQUIRES: asserts, shell<br>
+<br>
+// Modules:<br>
+// RUN: rm -rf %t<br>
+// RUN: %clang_cc1 -x objective-c -fmodules -fmodule-format=obj -fimplicit-module-maps -DMODULES -fmodules-cache-path=%t %s -I %S/Inputs -I %t -emit-llvm -o %t.ll -mllvm -debug-only=pchcontainer &>%t-mod.ll<br>
+// RUN: cat %t-mod.ll | FileCheck %s<br>
+<br>
+// PCH:<br>
+// RUN: %clang_cc1 -x objective-c -emit-pch -fmodule-format=obj -I %S/Inputs -o %t.pch %S/Inputs/DebugObjC.h -mllvm -debug-only=pchcontainer &>%t-pch.ll<br>
+// RUN: cat %t-pch.ll | FileCheck %s<br>
+<br>
+#ifdef MODULES<br>
+@import DebugObjC;<br>
+#endif<br>
+<br>
+// CHECK: distinct !DICompileUnit(language: DW_LANG_ObjC<br>
+// CHECK-SAME:                    isOptimized: false,<br>
+// CHECK-SAME:                    splitDebugFilename:<br>
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClass"<br>
+// CHECK: !DIObjCProperty(name: "property",<br>
+// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "ivar"<br>
+// CHECK: !DISubprogram(name: "+[ObjCClass classMethod]"<br>
+// CHECK: !DISubprogram(name: "-[ObjCClass instanceMethodWithInt:]"<br>
+// CHECK: !DISubprogram(name: "-[ categoryMethod]"<br>
<br>
Modified: cfe/trunk/test/Modules/debug-info-moduleimport.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/debug-info-moduleimport.m?rev=247068&r1=247067&r2=247068&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/debug-info-moduleimport.m?rev=247068&r1=247067&r2=247068&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Modules/debug-info-moduleimport.m (original)<br>
+++ cfe/trunk/test/Modules/debug-info-moduleimport.m Tue Sep  8 15:41:52 2015<br>
@@ -2,6 +2,6 @@<br>
 // RUN: %clang_cc1 -g -fmodules -DGREETING="Hello World" -UNDEBUG -fimplicit-module-maps -fmodules-cache-path=%t %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - | FileCheck %s<br>
<br>
 // CHECK: ![[CU:.*]] = distinct !DICompileUnit<br>
-@import DebugModule;<br>
+@import DebugObjC;<br>
 // CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: ![[CU]], entity: ![[MODULE:.*]], line: 5)<br>
-// CHECK: ![[MODULE]] = !DIModule(scope: null, name: "DebugModule", configMacros: "\22-DGREETING=Hello World\22 \22-UNDEBUG\22", includePath: "{{.*}}test{{.*}}Modules{{.*}}Inputs", isysroot: "/tmp/..")<br>
+// CHECK: ![[MODULE]] = !DIModule(scope: null, name: "DebugObjC", configMacros: "\22-DGREETING=Hello World\22 \22-UNDEBUG\22", includePath: "{{.*}}test{{.*}}Modules{{.*}}Inputs", isysroot: "/tmp/..")<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>