From 38ff4e782ef844a21512eb2ca0e491387ae89ec5 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 13 Oct 2026 05:25:09 +0000 Subject: fix: compare strings by content Co-Authored-By: Claude Fable 5.1 --- lib/CodeGen/CodeGen.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/CodeGen/CodeGen.cc') diff --git a/lib/CodeGen/CodeGen.cc b/lib/CodeGen/CodeGen.cc index 903d8ef..a6669a6 100644 --- a/lib/CodeGen/CodeGen.cc +++ b/lib/CodeGen/CodeGen.cc @@ -637,6 +637,21 @@ Value *CodeGen::emitExpr(ExprAST *Expr) { if (!L || !R) return nullptr; return StrHandler->emitConcat(L, R); } + // STRING and explicit pointers share LLVM's ptr representation; + // string comparisons must dispatch on the pseudocode type. + switch (Bin->getOp()) { + case tok_eq: case tok_ne: case '<': case '>': case tok_le: case tok_ge: + if ((LT && LT->isString()) || (RT && RT->isString())) { + if (!(LT && LT->isString() && RT && RT->isString())) { + reportError("STRING comparison requires two STRING operands (line %d)", Bin->getLine()); + return nullptr; + } + return StrHandler->emitCompare(Bin->getOp(), L, R); + } + break; + default: + break; + } return ArithHandler->emitBinaryOp(Bin->getOp(), L, R, Bin->getLine()); } -- cgit v1.3.1-4-g156e