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:
50
ctx.cpp
50
ctx.cpp
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user