Fix multiple bugs related to DIBuilder::createFunction() call.

The DIType passed to this method should correspond to the
FunctionType of the function, not its return type.

The first parameter should be the DIScope for the compile unit,
not the DIFile.

We previously had the unmangled function name and the mangled
function name interchanged.

The argument corresponding to "first line number of the function" was
missing, which in turn led to subsequent arguments being off, and thus
providing bogus values vs. what was supposed to be passed.

Rename FunctionEmitContext::diFunction to diSubprogram, to better
reflect its type.
This commit is contained in:
Matt Pharr
2012-04-25 08:41:28 -10:00
parent 260d7298c3
commit 0baa2b484d
2 changed files with 36 additions and 16 deletions

50
ctx.cpp
View File

@@ -297,23 +297,43 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym,
}
if (m->diBuilder) {
currentPos = funSym->pos;
/* If debugging is enabled, tell the debug information emission
code about this new function */
diFile = funcStartPos.GetDIFile();
llvm::DIType retType = function->GetReturnType()->GetDIType(diFile);
int flags = llvm::DIDescriptor::FlagPrototyped; // ??
diFunction = m->diBuilder->createFunction(diFile, /* scope */
llvmFunction->getName(), // mangled
funSym->name,
diFile,
funcStartPos.first_line,
retType,
funSym->storageClass == SC_STATIC,
true, /* is definition */
flags,
g->opt.level > 0,
llvmFunction);
Assert(diFile.Verify());
llvm::DIScope scope = llvm::DIScope(m->diBuilder->getCU());
Assert(scope.Verify());
const FunctionType *functionType = function->GetType();
llvm::DIType diSubprogramType;
if (functionType == NULL)
Assert(m->errorCount > 0);
else {
diSubprogramType = functionType->GetDIType(scope);
Assert(diSubprogramType.Verify());
}
std::string mangledName = llvmFunction->getName();
if (mangledName == funSym->name)
mangledName = "";
bool isStatic = (funSym->storageClass == SC_STATIC);
bool isOptimized = (g->opt.level > 0);
int firstLine = funcStartPos.first_line;
int flags = (llvm::DIDescriptor::FlagPrototyped);
diSubprogram =
m->diBuilder->createFunction(diFile /* scope */, funSym->name,
mangledName, diFile,
firstLine, diSubprogramType,
isStatic, true, /* is defn */
firstLine, flags,
isOptimized, llvmFunction);
Assert(diSubprogram.Verify());
/* And start a scope representing the initial function scope */
StartScope();
@@ -1439,7 +1459,7 @@ FunctionEmitContext::StartScope() {
if (debugScopes.size() > 0)
parentScope = debugScopes.back();
else
parentScope = diFunction;
parentScope = diSubprogram;
llvm::DILexicalBlock lexicalBlock =
m->diBuilder->createLexicalBlock(parentScope, diFile,
@@ -1495,7 +1515,7 @@ FunctionEmitContext::EmitFunctionParameterDebugInfo(Symbol *sym, int argNum) {
if (m->diBuilder == NULL)
return;
llvm::DIScope scope = diFunction;
llvm::DIScope scope = diSubprogram;
llvm::DIType diType = sym->type->GetDIType(scope);
Assert(diType.Verify());
int flags = 0;

2
ctx.h
View File

@@ -641,7 +641,7 @@ private:
/** DISubprogram corresponding to this function (used for debugging
info). */
llvm::DISubprogram diFunction;
llvm::DISubprogram diSubprogram;
/** These correspond to the current set of nested scopes in the
function. */