Giter Club home page Giter Club logo

Comments (5)

jiribenes avatar jiribenes commented on July 20, 2024

The issue 2. is hard to reproduce as on the LLVM REPL, as it works for normal strings:

> def foo(s: String): Unit = s.split("\n").foreach { x => println(x) }
foo: String => Unit
> foo("a\nb")
a
b
()

but when I try to pipe strings gotten from files into it, I run into a hard crash (possibly a different one than in 3.)

> def getInput(s: String) = { var out in global = ""; eventloop(box { with on[IOError].panic; with filesystem; out = do readFile(s) }); out }
getInput: String => String
> getInput("tiny.input")
[error] Process exited with non-zero exit code 134.
🔍 Here's a more detailed sanitiser trace
=================================================================
==11270==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x619000000080 in thread T0
    #0 0x1049712c0 in wrap_free+0x90 (libclang_rt.asan_osx_dynamic.dylib:arm64+0x4d2c0) (BuildId: 7615c595d022355bb91dd63f44086bc832000000200000000100000000000b00)
    #1 0x10455b2f0 in topLevel+0x40 (interactive:arm64+0x1000072f0) (BuildId: ac687bd67e75387bb75bb5090faec84932000000200000000100000000000b00)
    #2 0x1046bfeb4 in uv_run+0x25c (libuv.1.dylib:arm64+0x7eb4) (BuildId: 208160f0746f3fb2a43dfcdb736ed89c32000000200000000100000000000b00)
    #3 0x10455d9bc in k_332+0x1c (interactive:arm64+0x1000099bc) (BuildId: ac687bd67e75387bb75bb5090faec84932000000200000000100000000000b00)
    #4 0x10477d088 in start+0x204 (dyld:arm64+0x5088) (BuildId: 38ee9fe9b66d30668c5c6ddf0d6944c632000000200000000100000000060c00)
    #5 0x304dfffffffffffc  (<unknown module>)

Address 0x619000000080 is a wild pointer inside of access range of size 0x000000000001.
SUMMARY: AddressSanitizer: bad-free (libclang_rt.asan_osx_dynamic.dylib:arm64+0x4d2c0) (BuildId: 7615c595d022355bb91dd63f44086bc832000000200000000100000000000b00) in wrap_free+0x90
==11270==ABORTING

which seems like the very same bug as 2., if my eyes don't deceive me.

When formatted nicely, getInput looks like:

def getInput(s: String) = { 
  var out in global = "";
  eventloop(box { 
    with on[IOError].panic;
    with filesystem;
    
    // escape hatch, trying to return a string
    out = do readFile(s)
  })
    
  out
}

On the JS backend, it returns only an empty string (which makes sense as out has not been written into yet), so this is probably not the way to go about making a small testcase...

from effekt.

jiribenes avatar jiribenes commented on July 20, 2024

I added a sanitiser trace to 3. by applying the following patch:

diff --git c/effekt/jvm/src/main/scala/effekt/Runner.scala i/effekt/jvm/src/main/scala/effekt/Runner.scala
index 5eb85f65..d5f52921 100644
--- c/effekt/jvm/src/main/scala/effekt/Runner.scala
+++ i/effekt/jvm/src/main/scala/effekt/Runner.scala
@@ -209,7 +209,7 @@ object LLVMRunner extends Runner[String] {
   override def prelude: List[String] = List("effekt", "option", "list", "result", "exception", "string") // "array", "ref")
 
 
-  lazy val gccCmd = discoverExecutable(List("cc", "clang", "gcc"), List("--version"))
+  lazy val gccCmd = discoverExecutable(List("clang"), List("--version"))
   lazy val llcCmd = discoverExecutable(List("llc", "llc-15", "llc-16"), List("--version"))
   lazy val optCmd = discoverExecutable(List("opt", "opt-15", "opt-16"), List("--version"))
 
@@ -267,7 +267,7 @@ object LLVMRunner extends Runner[String] {
 
     val gccMainFile = (C.config.libPath / ".." / "llvm" / "main.c").unixPath
     val executableFile = basePath
-    val gccArgs = Seq(gcc, gccMainFile, "-o", executableFile, objPath) ++ libuvArgs
+    val gccArgs = Seq(gcc, "-fsanitize=address,undefined,leak,integer", gccMainFile, "-o", executableFile, objPath) ++ libuvArgs
     exec(gccArgs: _*)
 
     executableFile

from effekt.

jiribenes avatar jiribenes commented on July 20, 2024

Here's some more details: I tried printing the frees in @topLevel:

<called from `runPos`>
Freeing base: 0x144d2c800
Freeing base.0: 0x0
Freeing base.1: 0x619000000080
Freeing base.2: 0x0
Freeing env: 0x154d34800

<called from `run`> 
Freeing base: 0x144d2c800
Freeing base.0: 0x0
Freeing base.1: 0x619000000080
<uhoh, 💥>

from effekt.

jiribenes avatar jiribenes commented on July 20, 2024

It turns out that 2. is "just" mishandling escapes on the LLVM backends:

def main() = {
  eventloop(box {
    with on[IOError].panic;
    with filesystem;

    def analyse(str: String) = {
      println("Analysing: '" ++ str ++ "'")
      each (0, str.length) { i =>
        with on[OutOfBounds].panic;
        val c = str.charAt(i)
        println("char " ++ c.show ++ " (" ++ c.toInt.show ++ ")")
      }
    }

    val longstr = "kjrqmzv9mmtxhgvsevenhvq7\nfour2tszbgmxpbvninebxns6nineqbqzgjpmpqr"
    analyse(longstr)

    val contents = do readFile("day1-tiny.input") // same contents as `longstr`, just from a file
    analyse(contents)
  })
}

If you look into the log, you'll see:

Analysing: 'kjrqmzv9mmtxhgvsevenhvq7\nfour2tszbgmxpbvninebxns6nineqbqzgjpmpqr'
char k (107)
[...]
char \ (92)
char n (110)
[...]
Analysing: 'kjrqmzv9mmtxhgvsevenhvq7
four2tszbgmxpbvninebxns6nineqbqzgjpmpqr'
char k (107)
[...]
char 
 (10)
[...]

So actually the string read from a file is correct, the string literal isn't.

from effekt.

jiribenes avatar jiribenes commented on July 20, 2024

I've split this to two separate issues: #503 and #504

from effekt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.