llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.48k stars 11.77k forks source link

Clang crashes generating IR for variable of type auto #41373

Open llvmbot opened 5 years ago

llvmbot commented 5 years ago
Bugzilla Link 42028
Version unspecified
OS MacOS X
Attachments Crash backtrace, Testcase, Testcase(C++)
Reporter LLVM Bugzilla Contributor
CC @hfinkel,@rnk

Extended Description

Compile the Code and metal compiler crash

#include <metal_stdlib>
using namespace metal;

struct VertexOutput
{
    float4 gl_Position [[position]];
};

struct VertexContext
{
    constant float4x4& projection;
    constant float3& position;
    union
    {
        VertexOutput out;
        struct
        {
            float4 gl_Position;
        };
    };

    VertexOutput main()
    {
        out.gl_Position = float4(position, 1.0);
        return out;
    }
};

vertex VertexOutput vertexShader(constant float4x4& projection [[buffer(0)]],
                                 constant float3& position [[buffer(1)]])
{
    auto b = VertexContext
    {
        .position = position,
        .projection = projection,
    }.main();
    VertexOutput d = b;
    return d;
}
llvmbot commented 5 years ago

I confirmed the test case crashes upstream clang. Upstream LLVM doesn't support Metal, normally you would report such bugs to Apple, but since it affects clang, we can take a look.

clang(C++) crash while compiling the C++ code

struct foo
{
    float& a;
    float& b;

    float bar()
    {
        return b;
    }
};

int main(int argc, const char * argv[]) {
    float x = 0, y = 0;
    auto s = foo
    {
        .b = x,
        .a = y,
    }.bar();
    float t = s;
    return 0;
}
llvmbot commented 5 years ago

clang(C++) crash while compiling the C++ code

struct foo
{
    float& a;
    float& b;

    float bar()
    {
        return b;
    }
};

int main(int argc, const char * argv[]) {
    float x = 0, y = 0;
    auto s = foo
    {
        .b = x,
        .a = y,
    }.bar();
    float t = s;
    return 0;
}
rnk commented 5 years ago

I confirmed the test case crashes upstream clang. Upstream LLVM doesn't support Metal, normally you would report such bugs to Apple, but since it affects clang, we can take a look.

llvmbot commented 5 years ago
struct foo
{
    float& a;
    float& b;

    float bar()
    {
        return b;
    }
};

int main(int argc, const char * argv[]) {
    float x = 0, y = 0;
    auto s = foo
    {
        .b = x,
        .a = y,
    }.bar();
    float t = s;
    return 0;
}