Topics: Move to C++17 and Function attributes

It was a slow week for the VM.

Move to C++17

The C++ standard used for Viua VM was updated to C++17. The switch involved nothing more than changing -std=c++14 to -std=c++17 for GCC, and -std=c++1z for Clang.

The switch was mostly cosmetic, and Viua VM does not currently use C++17 features extensively.

Function attributes

Function attributes augment the syntax used for function headers:

'.function:' ( '[[' attribute... ']]' )? function-name

Intended use for attributes is to provide additional information to the assembler, or instruct the assembler to perform (or not to perform) a specific action with regard to a function.

For example, a hypothetical inline attribute would instruct the assembler to inline calls to a function.

The no_sa attribute

The only currently implemented attribute is no_sa, meaning "no static analysis". Its purpose is to disable static analysis on a per-function basis, as opposed to the per-compilation module basis that is now provided via --no-sa assembler flag.

The attribute is provided as a workaround for bugs (i.e. false positives) in the static analyser supplied by Viua VM. The static analyser is currently unable to use all available information, and is also unable to check some cases but errs on the side of caution and assumes that if it does not know whether an instruction would crash at runtime or not it decides that it would crash and throws an error.

Sometimes the reported errors may be almost hilariously long because the SA reports the whole trace detailing how it came to the conclusion that the instruction would cause an error.

The previous workaround for false positives was to split a file into two compilation units: one with the function for which the false positive was reported, and one with the rest of the code. Then, the unit with the single function would be compiled with the --no-sa flag to suppress the errors.

However, this approach was cumbersome and highly inconvenient. The no_sa attribute will be a much more usable way to suppress false positives.

Instruction attributes?

This would be similar to the function attributes. The example use case would be to make the `.unused:` directive, that is currently be used to tell the SA that a value produced by an instruction may be unused, into an attribute. The code would look like this:

; this is the current way
text %1 local "Hello World!"
.unused: %1

; this would be the "attribute way"
text [[maybe_unused]] %1 local "Hello World!"