Skip to content

Commit 41811aa

Browse files
committed
[DebugInfo] Swap 'Unit' and 'Type' positions in DISubprogram.
In current order, `Type` is processed before `Unit` by the Verifier. This can cause a race condition. Take the following example code: ``` int test(int a[][5]) { return a[0][2]; } ``` when compiled with clang, you will notice that control reaches `Verifier::visitDISubrange` first with `CurrentSourceLang` still equal to dwarf::DW_LANG_lo_user (32768). The control reaches `Verifier::visitDICompileUnit` later and sets the value of `CurrentSourceLang` correctly. This behavior does not effect C like language much but is a problem for Fortran. There is special processing in `Verifier::visitDISubrange` when `CurrentSourceLang` is Fortran. With this problem, that special handling is missed and verifier fails for any code that has Fortran's assumed size array in a global subroutine. To fix this, I have swapped the position of `Type` and `Unit`. They were already adjacent so it does not require changing position of anything else.
1 parent c2a22f1 commit 41811aa

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,11 @@ class DISubprogram : public DILocalScope {
18651865
/// Only used by clients of CloneFunction, and only right after the cloning.
18661866
void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); }
18671867

1868+
DICompileUnit *getUnit() const {
1869+
return cast_or_null<DICompileUnit>(getRawUnit());
1870+
}
1871+
void replaceUnit(DICompileUnit *CU) { replaceOperandWith(4, CU); }
1872+
18681873
DISubroutineType *getType() const {
18691874
return cast_or_null<DISubroutineType>(getRawType());
18701875
}
@@ -1873,13 +1878,9 @@ class DISubprogram : public DILocalScope {
18731878
}
18741879
void replaceType(DISubroutineType *Ty) {
18751880
assert(isDistinct() && "Only distinct nodes can mutate");
1876-
replaceOperandWith(4, Ty);
1881+
replaceOperandWith(5, Ty);
18771882
}
18781883

1879-
DICompileUnit *getUnit() const {
1880-
return cast_or_null<DICompileUnit>(getRawUnit());
1881-
}
1882-
void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); }
18831884
DITemplateParameterArray getTemplateParams() const {
18841885
return cast_or_null<MDTuple>(getRawTemplateParams());
18851886
}
@@ -1903,8 +1904,8 @@ class DISubprogram : public DILocalScope {
19031904
Metadata *getRawScope() const { return getOperand(1); }
19041905
MDString *getRawName() const { return getOperandAs<MDString>(2); }
19051906
MDString *getRawLinkageName() const { return getOperandAs<MDString>(3); }
1906-
Metadata *getRawType() const { return getOperand(4); }
1907-
Metadata *getRawUnit() const { return getOperand(5); }
1907+
Metadata *getRawUnit() const { return getOperand(4); }
1908+
Metadata *getRawType() const { return getOperand(5); }
19081909
Metadata *getRawDeclaration() const { return getOperand(6); }
19091910
Metadata *getRawRetainedNodes() const { return getOperand(7); }
19101911
Metadata *getRawContainingType() const {

llvm/lib/IR/DebugInfoMetadata.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,10 +1138,9 @@ DISubprogram *DISubprogram::getImpl(
11381138
RetainedNodes, ThrownTypes, Annotations,
11391139
TargetFuncName));
11401140
SmallVector<Metadata *, 13> Ops = {
1141-
File, Scope, Name, LinkageName,
1142-
Type, Unit, Declaration, RetainedNodes,
1143-
ContainingType, TemplateParams, ThrownTypes, Annotations,
1144-
TargetFuncName};
1141+
File, Scope, Name, LinkageName, Unit,
1142+
Type, Declaration, RetainedNodes, ContainingType, TemplateParams,
1143+
ThrownTypes, Annotations, TargetFuncName};
11451144
if (!TargetFuncName) {
11461145
Ops.pop_back();
11471146
if (!Annotations) {

0 commit comments

Comments
 (0)