using namespace clang::CodeGen;
CGDebugInfo::CGDebugInfo(CodeGenModule *m)
- : M(m), DebugFactory(M->getModule()) {
+ : M(m), isMainCompileUnitCreated(false), DebugFactory(M->getModule()) {
}
CGDebugInfo::~CGDebugInfo() {
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;
--- /dev/null
+// 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;
+}