Two more tests covering stc bugs:
authorJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 23 May 2014 17:18:08 +0200
changeset 1138 cd03872a5b98
parent 1137 cdd89ab3e125
child 1139 1dfea13c4d57
Two more tests covering stc bugs: #test_05a #test_05b
RegressionTests__CompilerTests2.st
--- a/RegressionTests__CompilerTests2.st	Tue May 13 12:33:19 2014 +0200
+++ b/RegressionTests__CompilerTests2.st	Fri May 23 17:18:08 2014 +0200
@@ -695,6 +695,101 @@
 
     "Created: / 27-08-2013 / 02:37:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 27-08-2013 / 10:32:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_05a
+    "JV@2014-05-23:
+
+    As of 2014-05-23, stc generate wrong code for compilation units
+    which references symbol AND contains argument declarations for
+    variable named _<value of that symbol> (given that symbol consist
+    of [A-Za-z]). 
+
+    The problem is that stc creates per-compilation unit static variable
+    for the symbol and defines a short accessor in form _<symbol value>.
+    If the function has argumemt with the very same name, the CPP expands
+    argment name in method signature to the access to the static variable
+    referencing the symbol object and thus cause syntax error.
+
+    NOTE, that problem occurs even if the symbol object is used as a selector
+    in message send ANYWHERE in the same compilation unit.
+
+    Bytecode compiler, however, handles this correctly, so this problem
+    will manifest itself by uncompilable code once checked out and
+    compled by STC.
+    "
+    #(bc stc) do:[:mode | 
+    self compile: 'at: _key 
+                    ^ #key' mode: mode.
+        self assert: (self perform: (mode , '_at:') asSymbol with: 2) == #key.
+    ]
+
+    "Created: / 23-05-2014 / 14:33:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (comment): / 23-05-2014 / 16:11:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+test_05b
+    "JV@2014-05-23:
+
+    As of 2014-05-23, stc generate wrong code for compilation units
+    which references symbol AND contains local variable declarations for
+    variable named _<value of that symbol> (given that symbol consist
+    of [A-Za-z]. 
+
+    The problem is that local variables in stc code are not a C local variables
+    but rather accessed indirectly using __context[offset]. As a courtesy to a problammer,
+    original variable name is a #define expaning to this context-accessing expression.
+    If there's a symbol with conflicitng name, the #define which is used to access it
+    is overriden by #define for local variable, causing bad return value of the method.
+
+    Bytecode compiler, however, handles this correctly, so this problem
+    will manifest itself when recompiled by STC and run. Even worse, in debugger
+    printit you'll get correct answer and well as if you recompile. 
+
+    "
+    #(bc stc) do:[:mode | 
+    self compile: 'at: arg
+                    | _key |
+
+                    _key := arg.
+                    ^ #key' mode: mode.
+        self assert: (self perform: (mode , '_at:') asSymbol with: 2) == #key.
+    ]
+
+    "Created: / 23-05-2014 / 14:33:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (comment): / 23-05-2014 / 16:16:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!CompilerTests2 methodsFor:'tests - FFI'!
+
+test_external_function_call_01
+    "Test for stx bug for <cdecl> specs like
+
+        <cdecl: Cairo::FontFace 'cairo_get_font_face' ( Cairo::GraphicsContext ) >
+
+     i.e., when custom subclass of ExternalAddress is in namespace."
+    
+    | malloc  free |
+
+    malloc := 'malloc: size
+
+    <cdecl: RegressionTests::CompilerTests2ExternalBytes "malloc" ( int ) module: ''librun.so''>
+    self primitive failed'.
+    free := 'free: ptr
+
+    <cdecl: void "free" ( RegressionTests::CompilerTests2ExternalBytes ) module: ''librun.so''>
+    self primitive failed'.
+    #( #bc #stc ) do:[:mode | 
+        | ptr |
+
+        self compile:malloc mode:mode.
+        self compile:free mode:mode.
+        ptr := self perform:(mode , '_malloc:') asSymbol with:1.
+        self assert:ptr class == RegressionTests::CompilerTests2ExternalBytes.
+        self perform:(mode , 'free:') asSymbol with:ptr.
+    ]
+
+    "Created: / 06-01-2014 / 11:29:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !CompilerTests2 methodsFor:'tests - FFI'!