Browse Source

llvmdbg: fix overflows for aggregates > 2^61 bytes

LLVM does not support aggregates larger than that at all, because internally
it stores all sizes in bits in an uint64. Their rationale for not having
special support for that is that there is no hardware with full 64 bit VM
address space anyway. So truncate our size emissions in debug info also to
that.
Jonas Maebe 3 years ago
parent
commit
a19deace45
1 changed files with 14 additions and 2 deletions
  1. 14 2
      compiler/llvm/dbgllvm.pas

+ 14 - 2
compiler/llvm/dbgllvm.pas

@@ -945,7 +945,13 @@ implementation
         if is_vector(def) then
           dinode.addenum('flags','DIFlagVector');
         if not is_dynamic_array(def) then
-          dinode.addqword('size',def.size*8)
+          if def.size<(qword(1) shl 61) then
+            dinode.addqword('size',def.size*8)
+          else
+            { LLVM internally "only" supports sizes up to 1 shl 61, because they
+              store all sizes in bits in a qword; the rationale is that there
+              is no hardware supporting a full 64 bit address space either }
+            dinode.addqword('size',qword(1) shl 61)
         else
           begin
             exprnode:=tai_llvmspecialisedmetadatanode.create(tspecialisedmetadatanodekind.DIExpression);
@@ -974,7 +980,13 @@ implementation
         dinode.addint64('tag',ord(DW_TAG_structure_type));
         if (name<>'') then
           dinode.addstring('name',name);
-        dinode.addqword('size',def.size*8);
+        if def.size<(qword(1) shl 61) then
+          dinode.addqword('size',def.size*8)
+        else
+          { LLVM internally "only" supports sizes up to 1 shl 61, because they
+            store all sizes in bits in a qword; the rationale is that there
+            is no hardware supporting a full 64 bit address space either }
+          dinode.addqword('size',qword(1) shl 61);
 
         list.concat(dinode);