class: RegressionTests::STCCompilerTests
added:
#inlinedBlockVariables1
#test20_localsOfInlinedBlock_bug
test for wrong access to inlined local variables
(of outer inlined blocks).
Reported by sr, 11-feb-2014)
--- a/RegressionTests__STCCompilerTests.st Fri Feb 07 13:57:07 2014 +0100
+++ b/RegressionTests__STCCompilerTests.st Tue Feb 11 13:45:04 2014 +0100
@@ -29,6 +29,42 @@
!STCCompilerTests methodsFor:'code templates'!
+inlinedBlockVariables1
+ "stc generates wrong code for inlined variables"
+
+ | b |
+
+ b := [:arg1 |
+ |local1|
+
+ local1 := #local1.
+ 1 to:3 do:[:argb_1 |
+ |localb_1 localb_2|
+
+ localb_1 := #localb_1.
+ localb_2 := #localb_2.
+ 1 to:5 do:[:argbb_1 |
+ |localbb_1 localbb_2|
+
+ localbb_1 := #localbb_1.
+ localbb_2 := #localbb_2.
+ argbb_1 == 3 ifTrue:[
+ ^ [:argbbb_1 |
+ |localbbb_1 localbbb_2|
+
+ localbbb_1 := #localbbb_1.
+ localbbb_2 := #localbbb_2.
+
+ localb_1 "/ here, in old stc versions, localb_2 is returned
+ ].
+ ].
+ ]
+ ]
+ ].
+
+ ^ b value:#arg1
+!
+
nextLittleEndianNumber: n from:bytes
"stc generates wrong code for the following s := assignment"
@@ -196,6 +232,44 @@
"
"Created: / 17-09-2011 / 10:32:18 / cg"
+!
+
+test20_localsOfInlinedBlock_bug
+ "checks for an stc compiler bug (detected Sep 2011).
+ stc generates bad code for the bitOr expression in nextLittleEndianNumber"
+
+ |blk mthd|
+
+ Class withoutUpdatingChangesDo:[
+ self class recompile:#'inlinedBlockVariables1'.
+ blk := self inlinedBlockVariables1.
+ self assert:((blk value:#argbbb_1) == #localb_1).
+
+ mthd := self class compiledMethodAt:#'inlinedBlockVariables1'.
+ (STCCompilerInterface new)
+ compileToMachineCode:mthd source
+ forClass:self class
+ selector:#'inlinedBlockVariables1'
+ inCategory:mthd category
+ notifying:nil
+ install:true
+ skipIfSame:false
+ silent:true.
+
+ self
+ assert:mthd ~= (self class compiledMethodAt:#'inlinedBlockVariables1')
+ description:'Could not compile with STC'.
+
+ blk := self inlinedBlockVariables1.
+ self assert:((blk value:#argbbb_1) == #localb_1).
+ ].
+
+ "
+ self run:#test20_localsOfInlinedBlock_bug
+ self new test20_localsOfInlinedBlock_bug
+ "
+
+ "Created: / 17-09-2011 / 10:32:18 / cg"
! !
!STCCompilerTests class methodsFor:'documentation'!