PLC-lang / rusty

Structured Text Parser and LLVM Frontend
GNU Lesser General Public License v3.0
203 stars 52 forks source link

Error in Standard functions regarding pointer assignments #1081

Open ghaith opened 7 months ago

ghaith commented 7 months ago
          > > @mhasel I think this is what you fixed in #1072 if i'm not mistaken? @rohanrayan The problem here is we are generating debug information for functions that don't exist. In a normal binary run (not IR) this does not matter because LLVM just removes it. But for IR it gets validated. The fix in #1072 should fix that I believe.

Yes, this issue should be fixed in #1072.

I checked and this commit indeed fixes this issue.

However I find other issues now. Specifically when trying to compile "string_conversion.st", I get the following error:

error: Invalid assignment: cannot assign '__POINTER_TO_CHAR' to 'REF_TO STRING'
    ┌─ /home/rusty_test/rusty/libs/stdlib/iec61131-st/string_conversion.st:118:5
    │
118 │     ptr := ∈
    │     ^^^^^^^^^^ Invalid assignment: cannot assign '__POINTER_TO_CHAR' to 'REF_TO STRING'

Also, please let me know if you want me to create new issues as this thread is getting long.

Thanks

Originally posted by @rohanrayan in https://github.com/PLC-lang/rusty/issues/1065#issuecomment-1920895509

ghaith commented 7 months ago

I created a new issue for this, the problem is because of our change with diagnostics. These issues will eventually be configurable so that we could ignore them. But this specific case is a false positive.

mhasel commented 7 months ago

I created a new issue for this, the problem is because of our change with diagnostics. These issues will eventually be configurable so that we could ignore them. But this specific case is a false positive.

This error has been around since the assignment validation refactor I believe. See also #1048.

After the recent changes to the diagnostics, I am no longer seeing this error when compiling the stdlib to IR (I tried on the #1072 branch since the master branch still fails on the llvm debug-symbol error). Can you confirm that plc -g --ir libs/stdlib/iec61131-st/*.st now builds without a single error/warning on the aforementioned branch (using the devcontainer)? This might just be on my side, since @rohanrayan seems to be getting the error still. I haven't looked too deeply into the diagnostics refactor yet, but it might be good to be able to override the severity configuration to display/log all errors/warnings with a compile argument, like --verbose.

edit: We have also temporarily disabled pointer validation in the past due to excessive errors when including the stdlib in builds (#858) and re-enabled them (#953) after changes to our pipeline so includes would no longer be validated. I am not sure if this really is an issue, since while the operation that causes this error in the stdlib is technically not allowed as per the standard (Section 6.4.4.10.3 and Table 12), so the validation is correct.

edit2: The line highlighted as error (ptr := ∈) does not actually occur in string_conversion.st::118 - that file only has 116 lines - but rather in bit_conversion.st and xtask/res/combined.st. However, bit_conversion.st does not have a function CHAR_TO_STRING function. xtask/res/combined.st does, bit with a wrong signature (and on a completely different line also). This might be due to the diagnostics refactor and is indeed a problem.

CHAR_TO_STRING declaration in string_conversion.st:

{external}
FUNCTION CHAR_TO_STRING : STRING
VAR_INPUT
    in : CHAR;
END_VAR
END_FUNCTION

CHAR_TO_STRING declaration in xtask/res/combined.st:

FUNCTION CHAR_TO_STRING : STRING
VAR_INPUT
    in : CHAR;
END_VAR
VAR
    ptr : REF_TO STRING;
END_VAR
    ptr := ∈
    CHAR_TO_STRING := ptr^;
END_FUNCTION