Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid llvm ir for blockarg generated when a cast is applied to the result of an auto #1675

Open
dgrove-oss opened this issue Jan 23, 2023 · 2 comments
Labels
kind: bug 🪲 An error in the implementation code or documentation

Comments

@dgrove-oss
Copy link
Collaborator

The test program below is extracted from NetNative.getIntOption0. When compiled with qbicc it generates invalid llvm ir (type mismatch).

import static org.qbicc.runtime.CNative.*;
import static org.qbicc.runtime.posix.SysSocket.*;

import java.io.IOException;
import java.net.SocketException;

class PointerBlockTest {

    public static void main(String[] args) {
        getIntOption0(1, 1, true);
    }

    static int opaque(socklen_t x) {
        return 0;
    }
    
    private static int getIntOption0(int level, int opt, boolean flag) {
        c_int result = auto();
        struct_linger linger = auto();
        socklen_t arglen = auto(sizeof(result)).cast();

        if (flag) {
            arglen = sizeof(linger).cast();
        }

        return opaque(arglen);
    }
}

The llc error:

 <stdin>:86:9: error: stored value and pointer type do not match
  store i32 8, i64* %bb1.20, align 8, !dbg !836 ; PointerBlockTest.java:25 bci@48

This store corresponds to the conditional assignment of arglen inside the if.

@dgrove-oss dgrove-oss added the kind: bug 🪲 An error in the implementation code or documentation label Jan 23, 2023
@dgrove-oss
Copy link
Collaborator Author

And in the clear light of a small test case, I realized that one could (should?) instead write:

        socklen_t arglen = auto(sizeof(result).cast(socklen_t.class));

This compiles just fine and generates valid llvm ir.

@dgrove-oss
Copy link
Collaborator Author

So maybe the only issue here is that it would have been nice to flag the casting of the result of auto as an error since it resulted in a size-mismatch between the nominal type of the local variable and the size of the backing storage associated with it.

@dgrove-oss dgrove-oss changed the title Invalid llvm ir generated for blockarg with socklen_t/sizeof Invalid llvm ir for blockarg generated when a cast is applied to the result of an auto Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug 🪲 An error in the implementation code or documentation
Projects
None yet
Development

No branches or pull requests

1 participant