[cfe-commits] r69902 - in /cfe/trunk: lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDebugInfo.h test/CodeGen/2009-04-23-dbg.c

Devang Patel dpatel at apple.com
Thu Apr 23 11:09:16 PDT 2009


Author: dpatel
Date: Thu Apr 23 13:09:16 2009
New Revision: 69902

URL: http://llvm.org/viewvc/llvm-project?rev=69902&view=rev
Log:
Handle corner case where clang-cc is invoked directly to compile preprocessed source file without -main-file-name. In this case, CDDebugInfo is not able identify correct main source file becase SM.isFromMainFile() returns true for locations from header files as well as locations from main source file.
This patch takes conservative approach by not emitting more then one compile unit with isMain bit set.


Added:
    cfe/trunk/test/CodeGen/2009-04-23-dbg.c
Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=69902&r1=69901&r2=69902&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Apr 23 13:09:16 2009
@@ -34,7 +34,7 @@
 using namespace clang::CodeGen;
 
 CGDebugInfo::CGDebugInfo(CodeGenModule *m)
-  : M(m), DebugFactory(M->getModule()) {
+  : M(m), isMainCompileUnitCreated(false), DebugFactory(M->getModule()) {
 }
 
 CGDebugInfo::~CGDebugInfo() {
@@ -71,16 +71,22 @@
     AbsFileName = tmp;
   }
 
-  // See if thie compile unit is represnting main source file.
+  // See if thie compile unit is representing main source file. Each source
+  // file has corresponding compile unit. There is only one main source
+  // file at a time.
   bool isMain = false;
   const LangOptions &LO = M->getLangOptions();
   const char *MainFileName = LO.getMainFileName();
-  if (MainFileName) {
-    if (!strcmp(AbsFileName.getLast().c_str(), MainFileName))
-      isMain = true;
-  } else {
-    if (Loc.isValid() && SM.isFromMainFile(Loc))
-      isMain = true;
+  if (isMainCompileUnitCreated == false) {
+    if (MainFileName) {
+      if (!strcmp(AbsFileName.getLast().c_str(), MainFileName))
+        isMain = true;
+    } else {
+      if (Loc.isValid() && SM.isFromMainFile(Loc))
+        isMain = true;
+    }
+    if (isMain)
+      isMainCompileUnitCreated = true;
   }
 
   unsigned LangTag;

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=69902&r1=69901&r2=69902&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Thu Apr 23 13:09:16 2009
@@ -34,6 +34,7 @@
 /// the backend.
 class CGDebugInfo {
   CodeGenModule *M;
+  bool isMainCompileUnitCreated;
   llvm::DIFactory DebugFactory;
   
   SourceLocation CurLoc, PrevLoc;

Added: cfe/trunk/test/CodeGen/2009-04-23-dbg.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2009-04-23-dbg.c?rev=69902&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/2009-04-23-dbg.c (added)
+++ cfe/trunk/test/CodeGen/2009-04-23-dbg.c Thu Apr 23 13:09:16 2009
@@ -0,0 +1,20 @@
+// RUN: clang-cc -g -o %t  %s -emit-llvm-bc && llc %t -f -o %t.s
+# 1 "a.c"
+# 1 "a.c" 1
+# 1 "<built-in>" 1
+# 103 "<built-in>"
+# 103 "<command line>" 1
+
+# 1 "/private/tmp/a.h" 1
+int bar;
+# 105 "<command line>" 2
+# 105 "<built-in>" 2
+# 1 "a.c" 2
+# 1 "/private/tmp/a.h" 1
+int bar;
+# 2 "a.c" 2
+
+int main() {
+ bar = 0;
+ return 0;
+}





More information about the cfe-commits mailing list