diff options
| author | Cliff Click <cliffc@acm.org> | 2026-10-28 13:39:05 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-10-28 13:39:05 -0700 |
| commit | 86ce5bc5d5018dcb62054d214b23f7a59b9c0d7d (patch) | |
| tree | 7b564b142c32924db354edfd8553d34cb66fff3e /chapter20/src/test/java/com/seaofnodes | |
| parent | e481e3d215882faa82b19f29cfde5746d4e51863 (diff) | |
| download | Simple-86ce5bc5d5018dcb62054d214b23f7a59b9c0d7d.tar.gz Simple-86ce5bc5d5018dcb62054d214b23f7a59b9c0d7d.zip | |
Fix bugs x86 storing only 32bits of a large constant
Missed field narrowing in a few cases
Diffstat (limited to 'chapter20/src/test/java/com/seaofnodes')
| -rw-r--r-- | chapter20/src/test/java/com/seaofnodes/simple/X86StoreTest.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/chapter20/src/test/java/com/seaofnodes/simple/X86StoreTest.java b/chapter20/src/test/java/com/seaofnodes/simple/X86StoreTest.java new file mode 100644 index 00000000..c853082f --- /dev/null +++ b/chapter20/src/test/java/com/seaofnodes/simple/X86StoreTest.java @@ -0,0 +1,35 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.simple.codegen.CodeGen; +import com.seaofnodes.simple.node.cpus.x86_64_v2.StoreX86; +import com.seaofnodes.simple.type.TypeInteger; +import org.junit.Test; +import static org.junit.Assert.*; + +public class X86StoreTest { + @Test public void testConstantStores() { + check("u8",255,false); + check("u16",65535,false); + check("u32",Integer.MAX_VALUE,false); + check("u32",2147483648L,true); + check("u32",4294967295L,true); + check("int",Integer.MIN_VALUE,false); + check("int",Integer.MAX_VALUE,false); + for( long value : new long[]{2147483648L,4294967295L,-2147483649L, + 0x123456789abcdefL,Long.MIN_VALUE,Long.MAX_VALUE} ) + check("int",value,true); + } + + private static void check(String type, long value, boolean register) { + // Returning the object keeps the Store; returning its field could fold. + String literal = value==Long.MIN_VALUE ? "(-9223372036854775807-1)" : Long.toString(value); + String src = "struct S { "+type+" x="+literal+"; }; return new S;"; + CodeGen code = new CodeGen(src).driver(CodeGen.Phase.InstSelect,"x86_64_v2","SystemV"); + StoreX86 store = code._stop.walk(n -> n instanceof StoreX86 st && st._name.equals("x") ? st : null); + assertNotNull(src,store); + if( register ) { + assertNotNull(src,store.in(4)); + assertEquals(src,value,((TypeInteger)store.in(4)._type).value()); + } else assertNull(src,store.in(4)); + } +} |
