Procházet zdrojové kódy

Revert revision 36436 from trunk. Final fix for issue #31675.

git-svn-id: trunk@36446 -
maciej-izak před 8 roky
rodič
revize
751bde9792

+ 2 - 0
.gitattributes

@@ -15565,6 +15565,7 @@ tests/webtbs/tw3160b.pp svneol=native#text/plain
 tests/webtbs/tw3160c.pp svneol=native#text/plain
 tests/webtbs/tw3161.pp svneol=native#text/plain
 tests/webtbs/tw3165.pp svneol=native#text/plain
+tests/webtbs/tw31675.pp svneol=native#text/pascal
 tests/webtbs/tw3168.pp svneol=native#text/plain
 tests/webtbs/tw3170.pp svneol=native#text/plain
 tests/webtbs/tw3172.pp svneol=native#text/plain
@@ -16228,6 +16229,7 @@ tests/webtbs/uw2956.pp svneol=native#text/plain
 tests/webtbs/uw2984.pp svneol=native#text/plain
 tests/webtbs/uw3103.pp svneol=native#text/plain
 tests/webtbs/uw31431.pp svneol=native#text/pascal
+tests/webtbs/uw31675.pp svneol=native#text/pascal
 tests/webtbs/uw3179a.pp svneol=native#text/plain
 tests/webtbs/uw3179b.pp svneol=native#text/plain
 tests/webtbs/uw3184a.pp svneol=native#text/plain

+ 5 - 0
compiler/scanner.pas

@@ -143,6 +143,9 @@ interface
           preproc_pattern : string;
           preproc_token   : ttoken;
 
+          { true, if we are parsing preprocessor expressions }
+          in_preproc_comp_expr : boolean;
+
           constructor Create(const fn:string; is_macro: boolean = false);
           destructor Destroy;override;
         { File buffer things }
@@ -2117,10 +2120,12 @@ type
         end;
 
      begin
+       current_scanner.in_preproc_comp_expr:=true;
        current_scanner.skipspace;
        { start preproc expression scanner }
        current_scanner.preproc_token:=current_scanner.readpreproc;
        preproc_comp_expr:=preproc_sub_expr(opcompare,true);
+       current_scanner.in_preproc_comp_expr:=false;
      end;
 
     function boolean_compile_time_expr(var valuedescr: string): Boolean;

+ 9 - 1
compiler/symtable.pas

@@ -459,7 +459,9 @@ implementation
       { codegen }
       procinfo,
       { ppu }
-      entfile
+      entfile,
+      { parser }
+      scanner
       ;
 
 
@@ -2795,6 +2797,12 @@ implementation
        var
          owner: tsymtable;
        begin
+         { for symbols used in preprocessor expressions, we don't want to
+           increase references count (for smaller final binaries) }
+         if not assigned(current_scanner) then
+           internalerror(2017050601);
+         if current_scanner.in_preproc_comp_expr then
+           exit;
          { symbol uses count }
          sym.IncRefCount;
          owner:=sym.owner;

+ 25 - 0
tests/webtbs/tw31675.pp

@@ -0,0 +1,25 @@
+{ %opt=-gh }
+
+program tw31675;
+
+{$mode objfpc}{$H+}
+
+uses
+  Classes,
+  {$if declared(useheaptrace)}
+  uw31675,
+  {$endif}
+  SysUtils
+  ;
+
+var
+  i: Boolean = false;
+begin
+{$if declared(foo)}
+  i := true;
+{$endif}
+  if not i then
+    Halt(1);
+  WriteLn('ok');
+end.
+

+ 13 - 0
tests/webtbs/uw31675.pp

@@ -0,0 +1,13 @@
+unit uw31675;
+
+{$MODE DELPHI}
+
+interface
+
+var
+  foo: boolean;
+
+implementation
+
+end.
+