Commits

Maciej Fijalkowski committed 3113850

fix the case of llstr(char)

Comments (0)

Files changed (2)

rpython/rtyper/annlowlevel.py

 
         def specialize_call(self, hop):
             hop.exception_cannot_occur()
-            assert hop.args_r[0].lowleveltype == hop.r_result.lowleveltype
             v_ll_str, = hop.inputargs(*hop.args_r)
-            return hop.genop('same_as', [v_ll_str],
-                             resulttype = hop.r_result.lowleveltype)
-
+            if hop.args_r[0].lowleveltype == hop.r_result.lowleveltype:
+                return hop.genop('same_as', [v_ll_str],
+                                 resulttype = hop.r_result.lowleveltype)
+            else:
+                return hop.gendirectcall(hop.args_r[0].ll.ll_chr2str, v_ll_str)
+        
     return hlstr, llstr
 
 hlstr, llstr = make_string_entries(str)

rpython/rtyper/test/test_annlowlevel.py

         res = self.interpret(f, [self.string_to_ll("abc")])
         assert res == 3
 
+    def test_llstr_const_char(self):
+        def f(arg):
+            s = llstr(hlstr(arg)[0])
+            return len(s.chars)
+
+        res = self.interpret(f, [self.string_to_ll("abc")])
+        assert res == 1
+
     def test_hlunicode(self):
         s = mallocunicode(3)
         s.chars[0] = u"a"