interp: fix "todo: store" panic

This is really just a simple workaround. When such an instruction is
encountered, it will just fall back to marking the entire function as
having side effects. Ideally it should trace all affected instructions
and check if they would have any side effects, but this at least fixes a
number of compile errors.

This commit gets the following packages to compile:

  * context
  * database/sql/driver
  * image/jpeg
  * image/png
Этот коммит содержится в:
Ayke van Laethem 2019-11-04 12:47:22 +01:00 коммит произвёл Ron Evans
родитель feb2b4715b
коммит e977276044
3 изменённых файлов: 14 добавлений и 4 удалений

Просмотреть файл

@ -193,10 +193,13 @@ func (e *Eval) hasLocalSideEffects(dirtyLocals map[llvm.Value]struct{}, inst llv
// Already handled in (*Eval).hasSideEffects. // Already handled in (*Eval).hasSideEffects.
continue continue
} }
// But a store might also store to an alloca, in which case all uses // This store might affect all kinds of values. While it is
// of the alloca (possibly indirect through a GEP, bitcast, etc.) // certainly possible to traverse through all of them, the easiest
// must be marked dirty. // option right now is to just assume the worst and say that this
panic("todo: store") // function has side effects.
// TODO: traverse through all stores and mark all relevant allocas /
// globals dirty.
return true
default: default:
// All instructions that take 0 or more operands (1 or more if it // All instructions that take 0 or more operands (1 or more if it
// was a use) and produce a result. // was a use) and produce a result.

Просмотреть файл

@ -22,6 +22,7 @@ var scanTestTable = []struct {
{"readDirtyGlobal", sideEffectLimited, []string{"dirtyGlobalInt"}}, {"readDirtyGlobal", sideEffectLimited, []string{"dirtyGlobalInt"}},
{"callFunctionPointer", sideEffectAll, []string{"functionPointer"}}, {"callFunctionPointer", sideEffectAll, []string{"functionPointer"}},
{"getDirtyPointer", sideEffectLimited, nil}, {"getDirtyPointer", sideEffectLimited, nil},
{"storeToPointer", sideEffectLimited, nil},
} }
func TestScan(t *testing.T) { func TestScan(t *testing.T) {

6
interp/testdata/scan.ll предоставленный
Просмотреть файл

@ -47,6 +47,12 @@ define i64 @readDirtyGlobal() {
declare i64* @getDirtyPointer() declare i64* @getDirtyPointer()
define void @storeToPointer() {
%ptr = call i64* @getDirtyPointer()
store i64 3, i64* %ptr
ret void
}
@functionPointer = global i64()* null @functionPointer = global i64()* null
define i64 @callFunctionPointer() { define i64 @callFunctionPointer() {
%fp = load i64()*, i64()** @functionPointer %fp = load i64()*, i64()** @functionPointer