Go to file
Gaius Mulley 3adceba04e [PATCH] PR modula2/115536 Expression is evaluated incorrectly when encountering relops and indirection
This fix ensures that we only call BuildRelOpFromBoolean if we are
inside a constant expression (where no indirection can be used).
The fix creates a temporary variable when a boolean is created from
a relop in other cases.
The previous pattern implementation would not work if the operands required
dereferencing during non const expressions.  Comparison of relop results
in a constant expression are resolved by constant propagation, basic
block analysis and dead code removal.  After the quadruples have been
optimized only one assignment to the boolean variable will remain for
const expressions.  All quadruple pattern checking for boolean
expressions is removed by the patch.  Thus the implementation becomes
more generic.

gcc/m2/ChangeLog:

	PR modula2/115536
	* gm2-compiler/M2BasicBlock.def (GetBasicBlockScope): New procedure.
	(GetBasicBlockStart): Ditto.
	(GetBasicBlockEnd): Ditto.
	(IsBasicBlockFirst): New procedure function.
	* gm2-compiler/M2BasicBlock.mod (ConvertQuads2BasicBlock): Allow
	conditional boolean quads to be removed.
	(GetBasicBlockScope): Implement new procedure.
	(GetBasicBlockStart): Ditto.
	(GetBasicBlockEnd): Ditto.
	(IsBasicBlockFirst): Implement new procedure function.
	* gm2-compiler/M2GCCDeclare.def (FoldConstants): New parameter
	declaration.
	* gm2-compiler/M2GCCDeclare.mod (FoldConstants): New parameter
	declaration.
	(DeclareTypesConstantsProceduresInRange): Recreate basic blocks
	after resolving constant expressions.
	(CodeBecomes): Guard IsVariableSSA with IsVar.
	* gm2-compiler/M2GenGCC.def (ResolveConstantExpressions): New
	parameter declaration.
	* gm2-compiler/M2GenGCC.mod (FoldIfLess): Remove relop pattern
	detection.
	(FoldIfGre): Ditto.
	(FoldIfLessEqu): Ditto.
	(FoldIfGreEqu): Ditto.
	(FoldIfIn): Ditto.
	(FoldIfNotIn): Ditto.
	(FoldIfEqu): Ditto.
	(FoldIfNotEqu): Ditto.
	(FoldBecomes): Add BasicBlock parameter and allow conditional
	boolean becomes to be folded in the first basic block.
	(ResolveConstantExpressions): Reimplement.
	* gm2-compiler/M2Quads.def (IsConstQuad): New procedure function.
	(IsConditionalBooleanQuad): Ditto.
	* gm2-compiler/M2Quads.mod (IsConstQuad): Implement new procedure function.
	(IsConditionalBooleanQuad): Ditto.
	(MoveWithMode): Use GenQuadOTypetok.
	(IsInitialisingConst): Rewrite using OpUsesOp1.
	(OpUsesOp1): New procedure function.
	(doBuildAssignment): Mark des as a VarConditional.
	(ConvertBooleanToVariable): Call PutVarConditional.
	(DumpQuadSummary): New procedure.
	(BuildRelOpFromBoolean): Updated debugging and improved comments.
	(BuildRelOp): Only call BuildRelOpFromBoolean if we are in a const
	expression and both operands are boolean relops.
	(GenQuadOTypeUniquetok): New procedure.
	(BackPatch): Correct comment.
	* gm2-compiler/SymbolTable.def (PutVarConditional): New procedure.
	(IsVarConditional): New procedure function.
	* gm2-compiler/SymbolTable.mod (PutVarConditional): Implement new
	procedure.
	(IsVarConditional): Implement new procedure function.
	(SymConstVar): New field IsConditional.
	(SymVar): New field IsConditional.
	(MakeVar): Initialize IsConditional field.
	(MakeConstVar): Initialize IsConditional field.
	* gm2-compiler/M2Swig.mod (DoBasicBlock): Change parameters to
	use BasicBlock.
	* gm2-compiler/M2Code.mod (SecondDeclareAndOptimize): Use iterator
	to FoldConstants over basic block list.
	* gm2-compiler/M2SymInit.mod (AppendEntry): Replace parameters
	with BasicBlock.
	* gm2-compiler/P3Build.bnf (Relation): Call RecordOp for #, <> and =.

gcc/testsuite/ChangeLog:

	PR modula2/115536
	* gm2/iso/const/pass/constbool4.mod: New test.
	* gm2/iso/const/pass/constbool5.mod: New test.
	* gm2/iso/run/pass/condtest2.mod: New test.
	* gm2/iso/run/pass/condtest3.mod: New test.
	* gm2/iso/run/pass/condtest4.mod: New test.
	* gm2/iso/run/pass/condtest5.mod: New test.
	* gm2/iso/run/pass/constbool4.mod: New test.

(cherry picked from commit 9f168b412f)

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
2024-11-22 18:38:51 +00:00
.github Minor formatting fix for newly-added file from previous commit 2023-11-01 19:28:56 -04:00
c++tools Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
config Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
contrib Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
fixincludes Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
gcc [PATCH] PR modula2/115536 Expression is evaluated incorrectly when encountering relops and indirection 2024-11-22 18:38:51 +00:00
gnattools Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
gotools Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
include Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
INSTALL
libada Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libatomic Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libbacktrace Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libcc1 Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libcody Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libcpp Daily bump. 2024-11-21 00:26:12 +00:00
libdecnumber Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libffi Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libgcc Daily bump. 2024-09-24 00:22:27 +00:00
libgfortran Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libgm2 Daily bump. 2024-11-21 00:26:12 +00:00
libgo libgo: bump libgo version for GCC 14 release 2024-02-05 11:28:30 -08:00
libgomp Daily bump. 2024-08-06 00:22:27 +00:00
libgrust Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libiberty Daily bump. 2024-09-13 00:21:45 +00:00
libitm Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libobjc Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libphobos Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libquadmath Daily bump. 2024-08-07 00:21:46 +00:00
libsanitizer Daily bump. 2024-09-06 00:22:34 +00:00
libssp Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
libstdc++-v3 Daily bump. 2024-11-13 00:23:07 +00:00
libvtv Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
lto-plugin Daily bump. 2024-09-05 00:22:17 +00:00
maintainer-scripts Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
zlib Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
.dir-locals.el
.gitattributes
.gitignore *: add modern gettext 2023-11-14 00:47:11 +01:00
ABOUT-NLS
ar-lib
ChangeLog Update ChangeLog and version files for release 2024-08-01 08:18:20 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in LoongArch: Reimplement multilib build option handling. 2023-09-15 10:42:12 +08:00
config.guess
config.rpath
config.sub
configure build: Use of cargo not yet supported here in Canadian cross configurations 2024-04-16 09:43:47 +02:00
configure.ac build: Use of cargo not yet supported here in Canadian cross configurations 2024-04-16 09:43:47 +02:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4 Build: fix error in fixinclude configure 2023-11-22 11:54:33 +01:00
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS MAINTAINERS: Update my email address 2024-04-04 16:39:52 +02:00
Makefile.def gccrs: Fix missing build dependency 2024-01-16 16:23:02 +01:00
Makefile.in Fix up postboot dependencies [PR106472] 2024-04-02 13:40:27 +02:00
Makefile.tpl Fix up postboot dependencies [PR106472] 2024-04-02 13:40:27 +02:00
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
SECURITY.txt SECURITY.txt: Drop "exploitable" in reference to hardening issues 2024-01-09 10:49:01 -05:00
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.