aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGen.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-13 05:25:09 +0000
committer_ov4 <ov4@ov4.org>2026-10-13 05:25:09 +0000
commit38ff4e782ef844a21512eb2ca0e491387ae89ec5 (patch)
treed9097aa5c8c5989b7dd4f9ee1c34dbcf28750fcb /lib/CodeGen/CodeGen.cc
parenta6fc1625ea8f825a7161354eb9167a281542fa29 (diff)
fix: compare strings by content
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/CodeGen.cc')
-rw-r--r--lib/CodeGen/CodeGen.cc15
1 files changed, 15 insertions, 0 deletions
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());
}