Browse Source

* ensure that only the newest message state is applied

Sven/Sarah Barth 7 months ago
parent
commit
5ec9386d27
3 changed files with 40 additions and 8 deletions
  1. 19 4
      compiler/scanner.pas
  2. 10 2
      compiler/switches.pas
  3. 11 2
      compiler/verbose.pas

+ 19 - 4
compiler/scanner.pas

@@ -3755,6 +3755,8 @@ type
         specialtoken : tspecialgenerictoken;
         specialtoken : tspecialgenerictoken;
         i : byte;
         i : byte;
         pmsg,prevmsg : pmessagestaterecord;
         pmsg,prevmsg : pmessagestaterecord;
+        msgset : thashset;
+        msgfound : boolean;
       begin
       begin
         if not assigned(replaytokenbuf) then
         if not assigned(replaytokenbuf) then
           internalerror(200511177);
           internalerror(200511177);
@@ -3863,20 +3865,33 @@ type
                       begin
                       begin
                         { free pending messages }
                         { free pending messages }
                         FreeLocalVerbosity(pendingstate.nextmessagerecord);
                         FreeLocalVerbosity(pendingstate.nextmessagerecord);
+                        { the message settings are stored from newest to oldest
+                          change for the whole stack, so we only want to apply
+                          the newest changes for each message type }
                         mesgnb:=tokenreadsizeint;
                         mesgnb:=tokenreadsizeint;
+                        msgset:=thashset.create(min(mesgnb,10),false,false);
                         prevmsg:=nil;
                         prevmsg:=nil;
+                        pmsg:=nil;
                         for i:=1 to mesgnb do
                         for i:=1 to mesgnb do
                           begin
                           begin
-                            new(pmsg);
+                            if not assigned(pmsg) then
+                              new(pmsg);
+                            pmsg^.value:=tokenreadlongint;
+                            pmsg^.state:=tmsgstate(tokenreadlongint);
+                            pmsg^.next:=nil;
+                            msgfound:=false;
+                            if assigned(msgset.findoradd(@pmsg^.value,sizeof(pmsg^.value),msgfound)) and msgfound then
+                              continue;
                             if i=1 then
                             if i=1 then
                               pendingstate.nextmessagerecord:=pmsg
                               pendingstate.nextmessagerecord:=pmsg
                             else
                             else
                               prevmsg^.next:=pmsg;
                               prevmsg^.next:=pmsg;
-                            pmsg^.value:=tokenreadlongint;
-                            pmsg^.state:=tmsgstate(tokenreadlongint);
-                            pmsg^.next:=nil;
                             prevmsg:=pmsg;
                             prevmsg:=pmsg;
+                            pmsg:=nil;
                           end;
                           end;
+                        if assigned(pmsg) then
+                          dispose(pmsg);
+                        msgset.free;
                       end;
                       end;
                     ST_LINE:
                     ST_LINE:
                       begin
                       begin

+ 10 - 2
compiler/switches.pas

@@ -50,7 +50,7 @@ uses
   { override optimizer switches }
   { override optimizer switches }
   llvminfo,
   llvminfo,
 {$endif llvm}
 {$endif llvm}
-  globals,verbose,comphook,dirparse,
+  globals,verbose,comphook,dirparse,cclasses,
   fmodule;
   fmodule;
 
 
 {****************************************************************************
 {****************************************************************************
@@ -384,6 +384,8 @@ procedure flushpendingswitchesstate;
   var
   var
     tmpproccal: tproccalloption;
     tmpproccal: tproccalloption;
     fstate, pstate : pmessagestaterecord;
     fstate, pstate : pmessagestaterecord;
+    msgset : thashset;
+    msgfound : boolean;
   begin
   begin
     { process pending localswitches (range checking, etc) }
     { process pending localswitches (range checking, etc) }
     if psf_local_switches_changed in pendingstate.flags then
     if psf_local_switches_changed in pendingstate.flags then
@@ -423,12 +425,17 @@ procedure flushpendingswitchesstate;
         setverbosity(pendingstate.nextverbositystr);
         setverbosity(pendingstate.nextverbositystr);
         pendingstate.nextverbositystr:='';
         pendingstate.nextverbositystr:='';
       end;
       end;
+    msgset:=thashset.create(10,false,false);
     fstate:=pendingstate.nextmessagerecord;
     fstate:=pendingstate.nextmessagerecord;
     pstate:=pendingstate.nextmessagerecord;
     pstate:=pendingstate.nextmessagerecord;
     while assigned(pstate) do
     while assigned(pstate) do
       begin
       begin
         pendingstate.nextmessagerecord:=pstate^.next;
         pendingstate.nextmessagerecord:=pstate^.next;
-        SetMessageVerbosity(pstate^.value,pstate^.state);
+        { the message records are ordered newest to oldest, so only apply the newest change }
+        msgfound:=false;
+        if not assigned(msgset.findoradd(@pstate^.value,sizeof(pstate^.value),msgfound)) or
+            not msgfound then
+          SetMessageVerbosity(pstate^.value,pstate^.state);
         if not assigned(pstate^.next) then
         if not assigned(pstate^.next) then
           begin
           begin
             pstate^.next:=current_settings.pmessage;
             pstate^.next:=current_settings.pmessage;
@@ -439,6 +446,7 @@ procedure flushpendingswitchesstate;
           pstate:=pstate^.next;
           pstate:=pstate^.next;
         pendingstate.nextmessagerecord:=nil;
         pendingstate.nextmessagerecord:=nil;
       end;
       end;
+    msgset.free;
     { process pending calling convention changes (calling x) }
     { process pending calling convention changes (calling x) }
     if pendingstate.nextcallingstr<>'' then
     if pendingstate.nextcallingstr<>'' then
       begin
       begin

+ 11 - 2
compiler/verbose.pas

@@ -114,7 +114,7 @@ interface
 implementation
 implementation
 
 
     uses
     uses
-      comphook,fmodule,constexp,globals,cfileutl,switches;
+      comphook,fmodule,constexp,globals,cfileutl,switches,cclasses;
 
 
 {****************************************************************************
 {****************************************************************************
                        Extra Handlers for default compiler
                        Extra Handlers for default compiler
@@ -173,13 +173,22 @@ implementation
       end;
       end;
 
 
     procedure RestoreLocalVerbosity(pstate : pmessagestaterecord);
     procedure RestoreLocalVerbosity(pstate : pmessagestaterecord);
+      var
+        msgset : thashset;
+        msgfound : boolean;
       begin
       begin
         msg^.ResetStates;
         msg^.ResetStates;
+        msgset:=thashset.create(10,false,false);
         while assigned(pstate) do
         while assigned(pstate) do
           begin
           begin
-            SetMessageVerbosity(pstate^.value,pstate^.state);
+            msgfound:=false;
+            { only apply the newest message state }
+            if not assigned(msgset.findoradd(@pstate^.value,sizeof(pstate^.value),msgfound)) or
+                not msgfound then
+              SetMessageVerbosity(pstate^.value,pstate^.state);
             pstate:=pstate^.next;
             pstate:=pstate^.next;
           end;
           end;
+        msgset.free;
       end;
       end;
 
 
     procedure FreeLocalVerbosity(var fstate : pmessagestaterecord);
     procedure FreeLocalVerbosity(var fstate : pmessagestaterecord);