News for hackers. Stuff that matters.
Re:Low-Level Software Security for Compiler Developers by kazinator on Monday February 20, 2023 @09:38PM (#34875787)
* * *
Re:Low-Level Software Security for Compiler Developers by cjbprime on Monday February 20, 2023 @10:48PM (#34876250)
Bounds checking isn't the only type of memory unsafety detected by sanitizers: they can also detect things like use-after-free, undefined behavior, and so on.
Re:Low-Level Software Security for Compiler Developers by Someone on Tuesday February 21, 2023 @05:46AM (#34879431)
> Languages that have properly bounded arrays just emit the code and optimize it. E.g. if a loop steps a variable from i from 0 to N-1

Modern languages have for value in arr, arr.forEach or equivalent. Such code makes it easier for compiler writers to make this optimization.

Swift even chose to remove for loops that step a variable (https://github.com/apple/swift-evolution/blob/main/proposals...), and I don’t think Rust has them, either.

I think that’s the right decision. In modern languages, classical for loops are a code smell.

And of course, golang goes the other way. https://go.dev/tour/flowcontrol/1:

Go has only one looping construct, the for loop.

The basic for loop has three components separated by semicolons:

- the init statement: executed before the first iteration

- the condition expression: evaluated before every iteration

- the post statement: executed at the end of every iteration

Re:Low-Level Software Security for Compiler Developers by pjmlp on Tuesday February 21, 2023 @10:10AM (#34882000)
> Modern languages have for value in arr, arr.forEach or equivalent. Such code makes it easier for compiler writers to make this optimization.

Those features were modern 40 years ago, even Visual Basic (pre-.NET) already had them.

Re:Low-Level Software Security for Compiler Developers by kazinator on Tuesday February 21, 2023 @02:15PM (#34885543)
If the compiler has good loop optimizations, the front end can turn foreach into an ordinary loop with a hidden variable:

  for (x in array) 
    print(x)

  ->

  const __local0017 = array.len;
  for (var __local0018 = 0; __local0018 < __local0017; __local++) {
    const x = array[__local0018];
    print(x);
  }
The middle and back ends will infer that __local0018 doesn't exceed __local0017 which is the length of array and get rid of the bound check.