[llvm] r246333 - AsmPrinter: Allow null subroutine type
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 14:38:25 PDT 2015
Author: dexonsmith
Date: Fri Aug 28 16:38:24 2015
New Revision: 246333
URL: http://llvm.org/viewvc/llvm-project?rev=246333&view=rev
Log:
AsmPrinter: Allow null subroutine type
Currently the DWARF backend requires that subprograms have a type, and
the type is ignored if it has an empty type array. The long term
direction here -- see PR23079 -- is instead to skip the type entirely if
there's no valid type.
It turns out we have cases in tree of missing types on subprograms, but
since they're not referenced by compile units, the backend never crashes
on them. One option would be to add a Verifier check that subprograms
have types, and fix the bitrot. However, this is a fair bit of churn
(20-30 testcases) that would be reversed anyway by PR23079.
I found this inconsistency because of a WIP patch and upgrade script for
PR23367 that started crashing on test/DebugInfo/2010-10-01-crash.ll.
This commit updates the testcase to reference the subprogram from the
compile unit, and fixes the resulting crash (in line with the direction
of PR23079). This also updates `DIBuilder` to stop assuming a non-null
pointer for the subroutine types.
Modified:
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/trunk/lib/IR/DIBuilder.cpp
llvm/trunk/test/DebugInfo/2010-10-01-crash.ll
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=246333&r1=246332&r2=246333&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Fri Aug 28 16:38:24 2015
@@ -99,6 +99,7 @@ class DITypeRefArray {
const MDTuple *N = nullptr;
public:
+ DITypeRefArray() = default;
DITypeRefArray(const MDTuple *N) : N(N) {}
explicit operator bool() const { return get(); }
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=246333&r1=246332&r2=246333&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Fri Aug 28 16:38:24 2015
@@ -1195,11 +1195,10 @@ void DwarfUnit::applySubprogramAttribute
Language == dwarf::DW_LANG_ObjC))
addFlag(SPDie, dwarf::DW_AT_prototyped);
- const DISubroutineType *SPTy = SP->getType();
- assert(SPTy->getTag() == dwarf::DW_TAG_subroutine_type &&
- "the type of a subprogram should be a subroutine");
+ DITypeRefArray Args;
+ if (const DISubroutineType *SPTy = SP->getType())
+ Args = SPTy->getTypeArray();
- auto Args = SPTy->getTypeArray();
// Add a return type. If this is a type like a C/C++ void type we don't add a
// return type.
if (Args.size())
Modified: llvm/trunk/lib/IR/DIBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DIBuilder.cpp?rev=246333&r1=246332&r2=246333&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DIBuilder.cpp (original)
+++ llvm/trunk/lib/IR/DIBuilder.cpp Fri Aug 28 16:38:24 2015
@@ -689,8 +689,6 @@ DISubprogram *DIBuilder::createFunction(
unsigned ScopeLine, unsigned Flags,
bool isOptimized, Function *Fn,
MDNode *TParams, MDNode *Decl) {
- assert(Ty->getTag() == dwarf::DW_TAG_subroutine_type &&
- "function types should be subroutines");
auto *Node = getSubprogram(/* IsDistinct = */ isDefinition, VMContext,
DIScopeRef::get(getNonCompileUnitScope(Context)),
Name, LinkageName, File, LineNo, Ty, isLocalToUnit,
@@ -725,8 +723,6 @@ DIBuilder::createMethod(DIScope *Context
bool isLocalToUnit, bool isDefinition, unsigned VK,
unsigned VIndex, DIType *VTableHolder, unsigned Flags,
bool isOptimized, Function *Fn, MDNode *TParam) {
- assert(Ty->getTag() == dwarf::DW_TAG_subroutine_type &&
- "function types should be subroutines");
assert(getNonCompileUnitScope(Context) &&
"Methods should have both a Context and a context that isn't "
"the compile unit.");
Modified: llvm/trunk/test/DebugInfo/2010-10-01-crash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/2010-10-01-crash.ll?rev=246333&r1=246332&r2=246333&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/2010-10-01-crash.ll (original)
+++ llvm/trunk/test/DebugInfo/2010-10-01-crash.ll Fri Aug 28 16:38:24 2015
@@ -15,7 +15,7 @@ declare void @llvm.memcpy.p0i8.p0i8.i32(
!llvm.module.flags = !{!27}
!0 = distinct !DISubprogram(name: "CGRectStandardize", linkageName: "CGRectStandardize", line: 54, isLocal: false, isDefinition: true, virtualIndex: 6, isOptimized: false, file: !1, scope: null, function: void (i32*, i32*)* @CGRectStandardize)
!1 = !DIFile(filename: "GSFusedSilica.m", directory: "/Volumes/Data/Users/sabre/Desktop")
-!2 = distinct !DICompileUnit(language: DW_LANG_ObjC, producer: "clang version 2.9 (trunk 115292)", isOptimized: true, runtimeVersion: 1, emissionKind: 0, file: !25, enums: !26, retainedTypes: !26)
+!2 = distinct !DICompileUnit(language: DW_LANG_ObjC, producer: "clang version 2.9 (trunk 115292)", isOptimized: true, runtimeVersion: 1, emissionKind: 0, file: !25, enums: !26, retainedTypes: !26, subprograms: !{!0})
!5 = !DIDerivedType(tag: DW_TAG_typedef, name: "CGRect", line: 49, file: !25, baseType: null)
!23 = !DILocalVariable(name: "rect", line: 53, arg: 2, scope: !0, file: !1, type: !5)
!24 = !DILocation(line: 53, column: 33, scope: !0)
More information about the llvm-commits
mailing list