Comment 1 for bug 781615

Revision history for this message
Matt Giuca (mgiuca) wrote :

There actually is a bug causing incorrect memory to be read. When a Mars statement fails in interactive mode, the environment (including the subscript map) is not updated, causing the same variable names to be reused on subsequent statements. The code in backend_llvm.store_global (which is used to write each local variable to an LLVM global) will be called with the name of an existing global, and LLVM will automatically generate a new unique name. However, the corresponding load_global will load from the old name, thus getting the value that was previously stored in the variable of the same name, usually with a different type.

This explains some very weird behaviour, such that if you throw an error with exactly 1 character:
?> a = error("X")
Runtime error: X
and then try to show an integer:
?> 42
Rather than segfaulting, it will print out the character in the error message:
X

This can be easily fixed; just make store_global delete any existing global if it finds one.