From d7ba09f5432fed805603c776afb6770daf65bb53 Mon Sep 17 00:00:00 2001 From: florian Date: Fri, 7 Aug 2020 21:43:00 +0000 Subject: [PATCH] * insert type casts when creating new unaryminus nodes during simplification, resolves #37508 git-svn-id: trunk@46309 - --- .gitattributes | 1 + compiler/nadd.pas | 10 +++++----- tests/webtbs/tw37508.pp | 6 ++++++ 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 tests/webtbs/tw37508.pp diff --git a/.gitattributes b/.gitattributes index 6bf8a1c5fb..86ae8c01c3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -18410,6 +18410,7 @@ tests/webtbs/tw37449.pp svneol=native#text/pascal tests/webtbs/tw37468.pp svneol=native#text/pascal tests/webtbs/tw37477.pp svneol=native#text/pascal tests/webtbs/tw37493.pp svneol=native#text/pascal +tests/webtbs/tw37508.pp svneol=native#text/pascal tests/webtbs/tw3751.pp svneol=native#text/plain tests/webtbs/tw3758.pp svneol=native#text/plain tests/webtbs/tw3764.pp svneol=native#text/plain diff --git a/compiler/nadd.pas b/compiler/nadd.pas index 494121afb9..87a17ee985 100644 --- a/compiler/nadd.pas +++ b/compiler/nadd.pas @@ -737,7 +737,7 @@ implementation begin case nodetype of muln: - result := cunaryminusnode.create(left.getcopy); + result := ctypeconvnode.create_internal(cunaryminusnode.create(left.getcopy),left.resultdef); else ; end; @@ -818,9 +818,9 @@ implementation begin case nodetype of addn,orn,xorn: - result := right.getcopy; + result := right.getcopy; subn: - result := cunaryminusnode.create(right.getcopy); + result := ctypeconvnode.create_internal(cunaryminusnode.create(right.getcopy),right.resultdef); andn,muln: begin if (cs_opt_level4 in current_settings.optimizerswitches) or @@ -844,7 +844,7 @@ implementation begin case nodetype of muln: - result := cunaryminusnode.create(right.getcopy); + result := ctypeconvnode.create_internal(cunaryminusnode.create(right.getcopy),right.resultdef); else ; end; @@ -976,7 +976,7 @@ implementation end; subn: begin - result:=cunaryminusnode.create(right.getcopy); + result:=ctypeconvnode.create_internal(cunaryminusnode.create(right.getcopy),right.resultdef); exit; end; else diff --git a/tests/webtbs/tw37508.pp b/tests/webtbs/tw37508.pp new file mode 100644 index 0000000000..27c5c9c353 --- /dev/null +++ b/tests/webtbs/tw37508.pp @@ -0,0 +1,6 @@ +{ %OPT=-O3 } +var a, b : integer; +begin + b := 0; + b := b - a - a { `b := b - a` won't trigger the error } +end.