Browse Source

* mark symbols used in conditional compiling expressions using sizeof, resolves #40955

florian 9 months ago
parent
commit
22ec4a2033
2 changed files with 31 additions and 2 deletions
  1. 14 2
      compiler/scanner.pas
  2. 17 0
      tests/webtbs/tw40955.pp

+ 14 - 2
compiler/scanner.pas

@@ -1872,6 +1872,12 @@ type
             end;
         end;
 
+        procedure MarkSymbolAsUsed(sym: tsym);
+          begin
+           tabstractvarsym(sym).IncRefCount;
+           inc(current_module.unitmap[sym.owner.moduleid].refs);
+          end;
+
         function preproc_factor(eval: Boolean):texprvalue;
         var
            hs,countstr,storedpattern: string;
@@ -2050,9 +2056,15 @@ type
                               staticvarsym,
                               localvarsym,
                               paravarsym :
-                                l:=tabstractvarsym(srsym).getsize;
+                                begin
+                                  l:=tabstractvarsym(srsym).getsize;
+                                  MarkSymbolAsUsed(srsym);
+                                end;
                               typesym:
-                                l:=ttypesym(srsym).typedef.size;
+                                begin
+                                  l:=ttypesym(srsym).typedef.size;
+                                  MarkSymbolAsUsed(srsym);
+                                end;
                               else
                                 Message(scan_e_error_in_preproc_expr);
                             end;

+ 17 - 0
tests/webtbs/tw40955.pp

@@ -0,0 +1,17 @@
+{ %opt=-v -Seh }
+program unused;
+
+uses
+	ctypes;
+
+begin
+	{$IF SIZEOF(cint) >= 8)}
+		Writeln('cint is 8 bytes or larger')
+	{$ELSEIF SIZEOF(cint) >= 4)}
+		Writeln('cint is 4 bytes or larger')
+	{$ELSEIF SIZEOF(cint) >= 2)}
+		Writeln('cint is 2 bytes or larger')
+	{$ELSE}
+		Writeln('cint is a puny 1 byte')
+	{$ENDIF}
+end.