]> granicus.if.org Git - clang/commitdiff
Handle corner case where clang-cc is invoked directly to compile preprocessed source...
authorDevang Patel <dpatel@apple.com>
Thu, 23 Apr 2009 18:09:16 +0000 (18:09 +0000)
committerDevang Patel <dpatel@apple.com>
Thu, 23 Apr 2009 18:09:16 +0000 (18:09 +0000)
This patch takes conservative approach by not emitting more then one compile unit with isMain bit set.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69902 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGDebugInfo.h
test/CodeGen/2009-04-23-dbg.c [new file with mode: 0644]

index f2ca2e7c589c96666fbe6e89a36302b9abdcdf38..a652ede1c1f2c348bcbce193ca9be86c365cf43d 100644 (file)
@@ -34,7 +34,7 @@ using namespace clang;
 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 @@ llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) {
     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;
index 4a59ecaaa57d50e4fb300c772dcf5d7086a0163f..1581637f4a32db61245d6e8fc983c67e371da13b 100644 (file)
@@ -34,6 +34,7 @@ namespace CodeGen {
 /// the backend.
 class CGDebugInfo {
   CodeGenModule *M;
+  bool isMainCompileUnitCreated;
   llvm::DIFactory DebugFactory;
   
   SourceLocation CurLoc, PrevLoc;
diff --git a/test/CodeGen/2009-04-23-dbg.c b/test/CodeGen/2009-04-23-dbg.c
new file mode 100644 (file)
index 0000000..4be6dab
--- /dev/null
@@ -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;
+}