View Issue Details

IDProjectCategoryView StatusLast Update
0037014FPCCompilerpublic2020-05-14 07:47
ReporterRyan Joseph Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version3.3.1 
Summary0037014: Constants in generics (with sets in units) cause compiler error
Description"Compilation raised exception" with set constants in generics IF the generic is part of a unit (programs are fine). Maybe a bug in the PPU loading?
Steps To Reproduce{$mode objfpc}

unit test;
interface

type
  TOption = (A);
  TOptions = set of TOption;

type
  generic TType<T; const U: TOptions> = class
  end;

// error: Compilation raised exception
implementation

end.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Ryan Joseph

2020-05-10 06:20

reporter   ~0122694

The problem is we're trying to write a generic constant (unspecialized) to the PPU but I never actually set the value of the constant (which is good because we don't this information) so for ptr types we get crashes.

Proposed solution is to just not write generic consts to the PPU but I don't like that I had to perform a random nil check without it being known that is only for generic constant syms (if this is not set for regular constants it's an error which should be captured). I can leave it like this if you want or maybe add another tsymoption which is for undefined generic constants and check against this. Right now we use sp_generic_const for generic and specialized
patch.diff (1,520 bytes)   
diff --git a/compiler/symsym.pas b/compiler/symsym.pas
index 66674b21fa..1cc493a515 100644
--- a/compiler/symsym.pas
+++ b/compiler/symsym.pas
@@ -2619,23 +2619,29 @@ implementation
            constresourcestring :
              begin
                ppufile.putderef(constdefderef);
-               ppufile.putlongint(value.len);
-               ppufile.putdata(pchar(value.valueptr)^,value.len);
+               if value.valueptr<>nil then
+                 begin
+                   ppufile.putlongint(value.len);
+                   ppufile.putdata(pchar(value.valueptr)^,value.len);
+                 end;
              end;
            constreal :
              begin
                ppufile.putderef(constdefderef);
-               ppufile.putreal(pbestreal(value.valueptr)^);
+               if value.valueptr<>nil then
+                 ppufile.putreal(pbestreal(value.valueptr)^);
              end;
            constset :
              begin
                ppufile.putderef(constdefderef);
-               ppufile.putset(tppuset32(value.valueptr^));
+               if value.valueptr<>nil then
+                 ppufile.putset(tppuset32(value.valueptr^));
              end;
            constguid :
              begin
                ppufile.putderef(constdefderef);
-               ppufile.putdata(value.valueptr^,sizeof(tguid));
+               if value.valueptr<>nil then
+                 ppufile.putdata(value.valueptr^,sizeof(tguid));
              end;
          else
            internalerror(13);
patch.diff (1,520 bytes)   

Ryan Joseph

2020-05-14 03:39

reporter   ~0122778

I haven't heard back on this. Is this an acceptable solution?

Sven Barth

2020-05-14 07:39

manager   ~0122780

In principle yes, but you have to keep in mind that the loading code needs to handle this as well. So you have to write /something/ so that the loading code can know that it's Nil and handle accordingly.

Ryan Joseph

2020-05-14 07:47

reporter   ~0122781

I don't see they're getting loaded at all, I couldn't cause crashing with this patch. I can't remember but I think the constants were repopulated when the type was specialized so they didn't go through the loading process. They're basically dummy constants that are placeholders for a value, which only happens on specialization, and in that case the values are set and load/unload properly.

Issue History

Date Modified Username Field Change
2020-05-04 08:46 Ryan Joseph New Issue
2020-05-10 06:20 Ryan Joseph Note Added: 0122694
2020-05-10 06:20 Ryan Joseph File Added: patch.diff
2020-05-14 03:39 Ryan Joseph Note Added: 0122778
2020-05-14 07:39 Sven Barth Note Added: 0122780
2020-05-14 07:47 Ryan Joseph Note Added: 0122781