[llvm-commits] [llvm] r169218 - in /llvm/trunk: include/llvm/ lib/CodeGen/AsmPrinter/ lib/VMCore/ test/CodeGen/ARM/ test/CodeGen/Thumb/ test/CodeGen/X86/ test/DebugInfo/ test/DebugInfo/X86/ test/JitListener/
Bill Wendling
isanbard at gmail.com
Tue Dec 4 14:33:30 PST 2012
On Dec 4, 2012, at 2:22 PM, "Robinson, Paul" <Paul.Robinson at am.sony.com> wrote:
>> Bill Wendling:
>>> DWARF wants you to omit DW_AT_upper_bound when the upper bound is unknown.
>>> I think this code does not achieve that effect when the Count == -1:
>>>
>> In the case that Count == -1, it won't get to this code because L == 1 and H == 0.
>
> Okay, I should've looked at more context than the diff showed. I was
> assuming the subrange handling was more language-neutral.
>
> As far as the patch's purpose goes, it looks okay. But the treatment
> of subranges in general leaves something to be desired.
>
> When L == 0 we don't emit the lower bound; this is permissible for
> languages that default to a lower bound of zero, but not for languages
> that have other defaults (or no default). LLVM does support non-C-family
> languages via Dragonegg; FORTRAN and Ada are especially mentioned on the
> LLVM home page, and their default lower-bound is 1 not 0.
>
> I think Ada supports subrange types directly, not just as array bounds,
> in which case omitting either bound is incorrect. I don't know whether
> Dragonegg supports describing subrange types in DWARF though.
>
We do support the lower bound being non-zero. :) Here's the code. When L is non-zero, we emit it. When Count is non-zero we also emit that.
/// constructSubrangeDIE - Construct subrange DIE from DISubrange.
void CompileUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR,
DIE *IndexTy) {
DIE *DW_Subrange = new DIE(dwarf::DW_TAG_subrange_type);
addDIEEntry(DW_Subrange, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IndexTy);
// The L value defines the lower bounds which is typically zero for C/C++. The
// Count value is the number of elements. Values are 64 bit. If Count == -1
// then the array is unbounded and we do not emit DW_AT_lower_bound and
// DW_AT_upper_bound attributes. If L == 0 and Count == 0, then the array has
// zero elements in which case we do not emit an upper bound.
uint64_t L = SR.getLo();
int64_t Count = SR.getCount();
if (Count != -1) {
// FIXME: An unbounded array should reference the expression that defines
// the array.
if (L)
addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, 0, L);
if (Count != 0)
addUInt(DW_Subrange, dwarf::DW_AT_upper_bound, 0, Count - 1);
}
Buffer.addChild(DW_Subrange);
}
But note that the lower bound isn't necessary:
"If the lower bound value is missing, the value is assumed to be a language-dependent default constant. The default lower bound is 0 for C, C++, D, Java, Objective C, Objective C++, Python, and UPC. The default lower bound is 1 for Ada, COBOL, Fortran, Modula-2, Pascal and PL/I."
The only time it would be necessary is if you're using a non-default lower bound. I suppose you could argue that we should always emit a non-zero lower bound just in case we have a non-default lower bound with an unbounded array. This is an extreme side-case, but not hard to fix. :)
-bw
More information about the llvm-commits
mailing list