From 4117b1fcb4a4dc2e505f414383240db6e63ceb9b Mon Sep 17 00:00:00 2001 From: Piotr Fusik Date: Sat, 22 Jan 2022 14:17:57 +0100 Subject: [const] Const-fold enum comparisons. --- CiResolver.cs | 8 ++++++-- Makefile | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CiResolver.cs b/CiResolver.cs index 8a2cd0e..df9da3c 100644 --- a/CiResolver.cs +++ b/CiResolver.cs @@ -579,8 +579,12 @@ public class CiResolver : CiVisitor if (leftRange.Max < rightRange.Min || leftRange.Min > rightRange.Max) return expr.ToLiteral(expr.Op == CiToken.NotEqual);; } - else if (left.Type == right.Type && left is CiLiteral leftLiteral && right is CiLiteral rightLiteral) - return expr.ToLiteral((expr.Op == CiToken.NotEqual) ^ object.Equals(leftLiteral.Value, rightLiteral.Value)); + else if (left.Type == right.Type) { + if (left is CiLiteral leftLiteral && right is CiLiteral rightLiteral) + return expr.ToLiteral((expr.Op == CiToken.NotEqual) ^ object.Equals(leftLiteral.Value, rightLiteral.Value)); + if (left.IsConstEnum && right.IsConstEnum) + return expr.ToLiteral((expr.Op == CiToken.NotEqual) ^ (left.IntValue == right.IntValue)); + } if (!left.Type.IsAssignableFrom(right.Type) && !right.Type.IsAssignableFrom(left.Type)) throw StatementException(expr, "Cannot compare {0} with {1}", left.Type, right.Type); TakePtr(left); diff --git a/Makefile b/Makefile index dc6f728..95668ce 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ prefix := /usr/local srcdir := $(dir $(lastword $(MAKEFILE_LIST))) -CFLAGS = -Wall -Wno-tautological-compare -Werror +CFLAGS = -Wall -Werror SWIFTC = swiftc ifeq ($(OS),Windows_NT) CSC = "C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/Roslyn/csc.exe" -nologo -- cgit v1.2.3