]> Cypherpunks repositories - gostls13.git/commitdiff
gc: make string const comparison unsigned
authorJeff R. Allen <jra@nella.org>
Wed, 16 Feb 2011 22:57:15 +0000 (17:57 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 16 Feb 2011 22:57:15 +0000 (17:57 -0500)
Make compile-time string const comparison match semantics
of runtime.cmpstring.

Fixes #1515.

R=rsc
CC=golang-dev, rog
https://golang.org/cl/4172049

src/cmd/gc/const.c
test/fixedbugs/bug1515.go [new file with mode: 0644]

index 0ee693c025b2a2831512e5adffac6bc5d99ae972..a54c40f6cc209ac83ea72edf1ba3feca8895bb40 100644 (file)
@@ -1051,12 +1051,12 @@ int
 cmpslit(Node *l, Node *r)
 {
        int32 l1, l2, i, m;
-       char *s1, *s2;
+       uchar *s1, *s2;
 
        l1 = l->val.u.sval->len;
        l2 = r->val.u.sval->len;
-       s1 = l->val.u.sval->s;
-       s2 = r->val.u.sval->s;
+       s1 = (uchar*)l->val.u.sval->s;
+       s2 = (uchar*)r->val.u.sval->s;
 
        m = l1;
        if(l2 < m)
diff --git a/test/fixedbugs/bug1515.go b/test/fixedbugs/bug1515.go
new file mode 100644 (file)
index 0000000..7402525
--- /dev/null
@@ -0,0 +1,20 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+const (
+       joao = "João"
+       jose = "José"
+)
+
+func main() {
+       s1 := joao
+       s2 := jose
+       if (s1 < s2) != (joao < jose) {
+               panic("unequal")
+       }
+}